<template>
    <div>
        <!--    面包屑导航区    -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>测试发布</el-breadcrumb-item>
            <el-breadcrumb-item>提测单</el-breadcrumb-item>
        </el-breadcrumb>
        <!--    卡片    -->
        <el-card>
            <!--    搜索    -->
            <el-form :inline="true" :model="querySubmitParam">
                <el-form-item label="提测单名称">
                    <el-input v-model="querySubmitParam.submitName" placeholder="请输入提测单名称" clearable></el-input>
                </el-form-item>
                <el-form-item label="所属项目">
                    <el-select v-model="querySubmitParam.ownerProjectId" placeholder="请选择所属项目"
                               @change="queryAllSprintByProjectId(querySubmitParam.ownerProjectId)" clearable>
                        <el-option v-for="(item, name) in this.allProject" :label="name" :value="item.id"
                                   :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所属版本" v-if="querySubmitParam.ownerProjectId !== null">
                    <el-select v-model="querySubmitParam.ownerVersionId" placeholder="请选择所属版本" clearable>
                        <el-option v-for="(item, index) in this.allSprint" :label="item.name" :value="item.id"
                                   :key="index"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="querySubmitByPage">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="showCreateSubmitDialog">新增项目配置</el-button>
                </el-form-item>
            </el-form>
            <!--    列表    -->
            <el-table :data="submitTable" style="width: 100%"
                      border :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}">
                <el-table-column type="index"/>
                <el-table-column prop="submitName" label="提测单名称" min-width="10%" showOverflowTooltip/>
                <el-table-column prop="submitMsg" label="提测单内容" min-width="10%" showOverflowTooltip/>
                <el-table-column prop="ownerProjectName" label="所属项目" min-width="10%" showOverflowTooltip/>
                <el-table-column prop="ownerVersionName" label="所属迭代" min-width="10%" showOverflowTooltip/>
                <el-table-column prop="startTime" label="测试开始时间" min-width="10%" showOverflowTooltip/>
                <el-table-column prop="endTime" label="测试结束时间" min-width="10%" showOverflowTooltip/>
                <el-table-column prop="status" label="提测单状态" min-width="10%" :formatter="statusFormatter" showOverflowTooltip/>
                <el-table-column label="操作" align="center" min-width="15%" showOverflowTooltip>
                    <template v-slot="{ row }">
                        <el-button type="primary" size="mini" @click="showSubmitInfoDialog(row.id)">查看</el-button>
                        <el-button type="primary" size="mini" @click="showEditSubmitDialog(row.id)" v-if="row.status !== 'END'">编辑</el-button>
                        <el-button type="success" size="mini" @click="changeStatus(row.id)" v-if="row.status === 'UN_START'">开始</el-button>
                        <el-button type="success" size="mini" @click="changeStatus(row.id)" v-else-if="row.status === 'START'">结束</el-button>
                        <el-button type="info" size="mini" @click="changeStatus(row)" disabled v-else>已结束</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--    分页    -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="querySubmitParam.page"
                :page-sizes="[10, 20, 50, 100, 200]"
                :page-size="querySubmitParam.size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-card>

        <!--    查看详情的dialog    -->
        <el-dialog
            title=""
            :visible.sync="submitInfoDialogVisible"
            width="1440px"
            top="8vh"
            :before-close="submitInfoDialogClose"
            class="editDialog"
        >
            <div class="el-dialog-div">
                <!-- 基础信息 -->
                <el-descriptions
                    class="margin-top"
                    title="提测单详情"
                    :column="1"
                    size="medium"
                    labelStyle="width: 20%"
                    border>
                    <el-descriptions-item label="提测单名称">{{ submitInfoForm.submitName }}</el-descriptions-item>
                    <el-descriptions-item label="提测单内容">{{ submitInfoForm.submitMsg }}</el-descriptions-item>
                    <el-descriptions-item label="所属项目">{{ submitInfoForm.ownerProjectName }}</el-descriptions-item>
                    <el-descriptions-item label="所属迭代">{{ submitInfoForm.ownerVersionName }}</el-descriptions-item>
                    <el-descriptions-item label="状态">
                        <el-tag size="small">{{ statusMap[submitInfoForm.status] }}</el-tag>
                    </el-descriptions-item>
                    <el-descriptions-item label="测试周期">{{ submitInfoForm.startTime + ' ~ ' + submitInfoForm.endTime }}
                    </el-descriptions-item>
                    <el-descriptions-item label="实际测试开始时间">{{ submitInfoForm.actualStartTime }}</el-descriptions-item>
                    <el-descriptions-item label="实际测试结束时间">{{ submitInfoForm.actualEndTime }}</el-descriptions-item>
                    <el-descriptions-item label="创建人">{{ submitInfoForm.createUserName }}</el-descriptions-item>
                    <el-descriptions-item label="创建时间">{{ submitInfoForm.createTime }}</el-descriptions-item>
                </el-descriptions>
                <br>
                <!-- 项目信息 -->
                <p>项目信息:</p>
                <el-table :data="submitInfoForm.submitProjectInfoList" size="medium" width="100%" border>
                    <el-table-column prop="projectName" label="git项目名称"></el-table-column>
                    <el-table-column prop="serviceName" label="服务名称" :formatter="formatter"></el-table-column>
                    <el-table-column prop="branch" label="提测分支"></el-table-column>
                </el-table>
                <br>
                <!-- 配置信息 -->
                <p>配置信息:</p>
                <el-table v-if="submitInfoForm.submitConfigInfoList !== [] && submitInfoForm.submitConfigInfoList !== null"
                          :data="submitInfoForm.submitConfigInfoList" size="medium" width="100%" border>
                    <el-table-column prop="configName" label="配置名称" min-width="20%"></el-table-column>
                    <el-table-column prop="configInfo" label="配置详情" min-width="80%"></el-table-column>
                </el-table>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="submitInfoDialogVisible = false">关 闭</el-button>
            </span>
        </el-dialog>

        <!--    创建提测单的dialog    -->
        <el-dialog
            title="新建提测单"
            :visible.sync="createSubmitDialogVisible"
            width="1440px"
            top="8vh"
            :before-close="createSubmitDialogClose">
            <div class="el-dialog-div">
                <el-form
                    :model="createSubmitForm"
                    :rules="createSubmitFormRules"
                    ref="createSubmitFormRef"
                    label-width="100px"
                    inline>
                    <h3>基本信息:</h3>
                    <br>
                    <el-form-item label="提测单名称" prop="submitName">
                        <el-input v-model.trim="createSubmitForm.submitName"/>
                    </el-form-item>
                    <el-form-item label="所属项目" prop="ownerProjectId">
                        <el-select v-model="createSubmitForm.ownerProjectId" placeholder="请选择所属项目"
                                   @change="queryAllSprintByProjectId(createSubmitForm.ownerProjectId)" clearable>
                            <el-option v-for="(item, name) in this.allProject" :label="name" :value="item.id"
                                       :key="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="所属迭代" prop="ownerVersionId">
                        <el-select v-model="createSubmitForm.ownerVersionId" placeholder="请选择所属版本" clearable>
                            <el-option v-for="(item, index) in this.allSprint" :label="item.name" :value="item.id"
                                       :key="index"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="测试周期">
                        <el-date-picker v-model="createSubmitForm.dateList" type="daterange" :editable="false"
                                        format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" range-separator="至"
                                        start-placeholder="开始日期" end-placeholder="结束日期" clearable></el-date-picker>
                    </el-form-item>
                    <el-form-item label="提测单内容" prop="submitMsg" style="width: 80%">
                        <el-input type="textarea" style="width: 998px" v-model="createSubmitForm.submitMsg"/>
                    </el-form-item>

                    <h3>项目信息:</h3>
                    <br>
                    <div v-for="(item, index) in createSubmitForm.submitProjectInfoList" :key="index + 'project'">
                        <el-form-item
                            label="git项目名称"
                            style="width: 366px"
                            :prop="'submitProjectInfoList.' + index + '.projectName'"
                            :rules="{ required: true, message: 'git项目名称不能为空', trigger: 'blur' }">
                            <el-select v-model="item.projectName" filterable placeholder="请选择项目名称"
                                       @change="changeProjectName($event)" clearable>
                                <el-option v-for="(name, index) in projectList" :label="name" :value="name"
                                           :key="index"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="showServiceNameMap[item.projectName]"
                            label="服务名称"
                            style="width: 366px"
                            :prop="'submitProjectInfoList.' + index + '.serviceName'"
                            :rules="{ required: true, message: '服务名称不能为空', trigger: 'blur' }">
                            <el-select v-model="item.serviceName" placeholder="请选择服务名称" clearable>
                                <el-option v-for="(name, index) in moduleNameList" :label="name" :value="name"
                                           :key="index"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            label="提测分支"
                            style="width: 366px"
                            :prop="'submitProjectInfoList.' + index + '.branch'"
                            :rules="{ required: true, message: '提测分支不能为空', trigger: 'blur' }">
                            <el-input v-model="item.branch"></el-input>
                        </el-form-item>
                        <el-form-item style="width: 122px">
                            <el-button v-if="index+1 === createSubmitForm.submitProjectInfoList.length"
                                       @click="addProjectInfo" type="primary">增加
                            </el-button>
                            <el-button v-if="index !== 0" @click="deleteProjectInfo(item, index)" type="danger">删除
                            </el-button>
                        </el-form-item>
                    </div>

                    <h3>配置信息:</h3>
                    <br>
                    <div v-for="(item, index) in createSubmitForm.submitConfigInfoList" :key="index + 'config'">
                        <el-form-item
                            label="配置名称"
                            style="width: 366px"
                            :prop="'submitConfigInfoList.' + index + '.configName'">
                            <el-input v-model="item.configName"></el-input>
                        </el-form-item>
                        <el-form-item
                            label="配置详情"
                            style="width: 732px"
                            :prop="'submitConfigInfoList.' + index + '.configInfo'">
                            <el-input type="textarea" style="width: 534px" v-model="item.configInfo"></el-input>
                        </el-form-item>
                        <el-form-item style="width: 122px">
                            <el-button
                                v-if="index+1 === createSubmitForm.submitConfigInfoList.length"
                                @click="addConfigInfo" type="primary">增加
                            </el-button>
                            <el-button v-if="index !== 0" @click="deleteConfigInfo(item, index)" type="danger">删除
                            </el-button>
                        </el-form-item>
                    </div>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="createSubmitDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="createSubmit">确 定</el-button>
            </span>
        </el-dialog>

        <!--    编辑提测单的dialog    -->
        <el-dialog
            title="编辑提测单"
            :visible.sync="editSubmitDialogVisible"
            width="1440px"
            top="8vh"
            :before-close="editSubmitDialogClose">
            <div class="el-dialog-div">
                <el-form
                    :model="editSubmitForm"
                    :rules="editSubmitFormRules"
                    ref="editSubmitFormRef"
                    label-width="100px"
                    inline>
                    <h3>基本信息:</h3>
                    <br>
                    <el-form-item label="提测单名称" prop="submitName">
                        <el-input v-model.trim="editSubmitForm.submitName"/>
                    </el-form-item>
                    <el-form-item label="所属项目" prop="ownerProjectId">
                        <el-select v-model="editSubmitForm.ownerProjectId" placeholder="请选择所属项目"
                                   @change="queryAllSprintByProjectId(editSubmitForm.ownerProjectId)" clearable>
                            <el-option v-for="(item, name) in this.allProject" :label="name" :value="item.id"
                                       :key="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="所属迭代" prop="ownerVersionId">
                        <el-select v-model="editSubmitForm.ownerVersionId" placeholder="请选择所属版本" clearable>
                            <el-option v-for="(item, name) in this.allSprint" :label="name" :value="item.id" :key="item.id">
                                {{ name }}
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="测试周期">
                        <el-date-picker v-model="editSubmitForm.dateList" type="daterange" :editable="false"
                                        format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" range-separator="至"
                                        start-placeholder="开始日期" end-placeholder="结束日期" clearable></el-date-picker>
                    </el-form-item>
                    <el-form-item label="提测单内容" prop="submitMsg">
                        <el-input type="textarea" rows="5" style="width: 998px" v-model="editSubmitForm.submitMsg"/>
                    </el-form-item>

                    <h3>项目信息:</h3>
                    <br>
                    <div v-for="(item, index) in editSubmitForm.submitProjectInfoList" :key="index + 'project'">
                        <el-form-item
                            label="git项目名称"
                            style="width: 366px"
                            :prop="'submitProjectInfoList.' + index + '.projectName'"
                            :rules="{ required: true, message: 'git项目名称不能为空', trigger: 'blur' }">
                            <el-select v-model="item.projectName" filterable placeholder="请选择项目名称"
                                       @change="changeProjectName($event)" clearable>
                                <el-option v-for="(name, index) in projectList" :label="name" :value="name"
                                           :key="index"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="showServiceNameMap[item.projectName]"
                            label="服务名称"
                            style="width: 366px"
                            :prop="'submitProjectInfoList.' + index + '.serviceName'"
                            :rules="{ required: true, message: '应用/服务/模块名称不能为空', trigger: 'blur' }">
                            <el-select v-model="item.serviceName" placeholder="请选择服务名称" clearable>
                                <el-option v-for="(name, index) in moduleNameList" :label="name" :value="name"
                                           :key="index"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            label="提测分支"
                            style="width: 366px"
                            :prop="'submitProjectInfoList.' + index + '.branch'"
                            :rules="{ required: true, message: '提测分支不能为空', trigger: 'blur' }">
                            <el-input v-model="item.branch"></el-input>
                        </el-form-item>
                        <el-form-item style="width: 122px">
                            <el-button v-if="index+1 === editSubmitForm.submitProjectInfoList.length"
                                       @click="addEditProjectInfo" type="primary">增加
                            </el-button>
                            <el-button v-if="index !== 0" @click="deleteEditProjectInfo(item, index)" type="danger">删除
                            </el-button>
                        </el-form-item>
                    </div>

                    <h3>配置信息:</h3>
                    <br>
                    <div v-for="(item, index) in editSubmitForm.submitConfigInfoList" :key="index + 'config'">
                        <el-form-item
                            label="配置名称"
                            style="width: 366px"
                            :prop="'submitConfigInfoList.' + index + '.configName'">
                            <el-input v-model="item.configName"></el-input>
                        </el-form-item>
                        <el-form-item
                            label="配置详情"
                            style="width: 732px"
                            :prop="'submitConfigInfoList.' + index + '.configInfo'">
                            <el-input type="textarea" rows="5" style="width: 534px" v-model="item.configInfo"></el-input>
                        </el-form-item>
                        <el-form-item style="width: 122px">
                            <el-button v-if="index+1 === editSubmitForm.submitConfigInfoList.length"
                                       @click="addEditConfigInfo" type="primary">增加
                            </el-button>
                            <el-button v-if="index !== 0" @click="deleteEditConfigInfo(item, index)" type="danger">删除
                            </el-button>
                        </el-form-item>
                    </div>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                    <el-button @click="editSubmitDialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="editSubmit">确 定</el-button>
                </span>

        </el-dialog>

    </div>
</template>

<script>
export default {
    name: "PublishPage",
    data() {
        return {
            // 分页查询报告参数
            querySubmitParam: {
                submitName: null,
                ownerProjectName: null,
                ownerVersionName: null,
                page: 1,
                size: 10
            },
            submitTable: [],
            total: 0,
            allProject: [],
            allSprint: [],
            projectList: [],
            moduleNameMap: {},
            moduleNameList: [],
            showServiceNameMap: {},

            // 提测单详情的显示控制
            submitInfoDialogVisible: false,
            // 创建提测单的显示控制
            createSubmitDialogVisible: false,
            // 创建提测单的表单对象
            createSubmitForm: {
                submitProjectInfoList: [
                    {
                        projectName: "",
                        serviceName: "",
                        branch: "",
                    }
                ],
                submitConfigInfoList: [
                    {
                        configName: "",
                        configInfo: "",
                    }
                ]
            },
            // 创建提测单的表单规则
            createSubmitFormRules: {
                submitName: [
                    {required: true, message: '请输入提测单名称', trigger: 'blur'},
                ],
                submitMsg: [
                    {required: true, message: '请输入提测单内容', trigger: 'blur'},
                ],
                ownerProjectId: [
                    {required: true, message: '请选择所属项目', trigger: 'blur'},
                ],
                ownerVersionId: [
                    {required: true, message: '请选择所属版本', trigger: 'blur'},
                ],
                submitProjectInfoList: [
                    {required: true, message: '请选择提测项目信息', trigger: 'blur'},
                ],
            },
            // 编辑提测单的显示控制
            editSubmitDialogVisible: false,
            // 编辑提测单的表单对象
            editSubmitForm: {
                submitProjectInfoList: [],
                submitConfigInfoList: []
            },
            // 编辑提测单的表单规则
            editSubmitFormRules: {
                submitName: [
                    {required: true, message: '请输入提测单名称', trigger: 'blur'},
                ],
                submitMsg: [
                    {required: true, message: '请输入提测单内容', trigger: 'blur'},
                ],
                ownerProjectId: [
                    {required: true, message: '请选择所属项目', trigger: 'blur'},
                ],
                ownerVersionId: [
                    {required: true, message: '请选择所属版本', trigger: 'blur'},
                ],
                submitProjectInfoList: [
                    {required: true, message: '请选择提测项目信息', trigger: 'blur'},
                ],
            },
            statusMap: {
                UN_START: '未开始',
                START: '已开始',
                END: '已结束'
            },
            // 查看提测单的表单对象
            submitInfoForm: {},
        }
    },
    methods: {
        formatter(row, column, cellValue) {
            return cellValue === "" ? "-" : cellValue
        },
        // 状态格式化
        statusFormatter(row, column, cellValue) {
            return this.statusMap[cellValue]
        },
        // 根据提测单id更新提测单状态
        async changeStatus(id) {
            const res = await this.$api.postForm("/sonar/submit/updateStatusById",
                {
                    id, userName: localStorage.getItem('username')
                }
            )
            if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
            await this.querySubmitByPage()
            this.$message.success("状态变更成功")
        },
        // 分页查询提测单
        async querySubmitByPage() {
            const res = await this.$api.post("/sonar/submit/customPage", this.querySubmitParam)
            if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
            this.submitTable = res.data.records
            this.total = res.data.total
        },
        // 查询全部ones项目
        async queryAllProject() {
            const res = await this.$api.get("/sonar/onesProject/queryAllProject")
            if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
            this.allProject = res.data
        },
        // 查询全部版本
        async queryAllSprintByProjectId(projectId) {
            if (projectId === undefined || projectId === null || projectId === '') {
                return
            }
            this.allSprint = []
            const res = await this.$api.postForm("/sonar/onesSprint/findSprintByProjectId", {
                projectId
            })
            if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
            this.allSprint = res.data
        },
        // 查询全部配置项目和服务模块信息
        async queryAllProjectAndServiceModule() {
            const res = await this.$api.get("/sonar/project/config/queryAllProjectAndServiceModule")
            if (res.code !== 200) return this.$message.error(res.message)
            this.projectList = res.data['project'];
            this.moduleNameMap = res.data['module'];
        },
        // 项目变更监听事件
        changeProjectName(name) {
            if (this.moduleNameMap[name] !== undefined && JSON.parse(JSON.stringify(this.moduleNameMap[name])).length > 0 && JSON.parse(JSON.stringify(this.moduleNameMap[name]))[0] !== null) {
                this.moduleNameList = this.moduleNameMap[name]
                this.showServiceNameMap[name] = true
            } else {
                this.moduleNameList = []
                this.showServiceNameMap[name] = false
            }
        },

        // 创建提测单
        async createSubmit() {
            this.createSubmitForm.startTime = this.createSubmitForm.dateList[0]
            this.createSubmitForm.endTime = this.createSubmitForm.dateList[1]
            this.$refs.createSubmitFormRef.validate(async valid => {
                if (!valid) return
                this.createSubmitForm.createUserName = localStorage.getItem('username'); // 记录创建人
                const res = await this.$api.post("/sonar/submit/save", this.createSubmitForm)
                if (res.code !== 200 || res.data === null) return this.$message.error(res.message)

                this.$message.success("保存成功!")
                await this.querySubmitByPage();
                // 初始化创建提测单的表单信息
                this.createSubmitForm = {
                    submitProjectInfoList: [
                        {
                            projectName: "",
                            serviceName: "",
                            branch: "",
                        }
                    ],
                    submitConfigInfoList: [
                        {
                            configName: "",
                            configInfo: "",
                        }
                    ]
                }
                this.createSubmitDialogVisible = false
            });
        },
        // [创建提测单时]-增加项目信息
        addProjectInfo() {
            this.createSubmitForm.submitProjectInfoList.push({
                projectName: "",
                serviceName: "",
                branch: "",
            });
        },
        // [创建提测单时]-删除项目信息
        deleteProjectInfo(item, index) {
            this.createSubmitForm.submitProjectInfoList.splice(index, 1);
        },
        // [创建提测单时]-增加配置信息
        addConfigInfo() {
            this.createSubmitForm.submitConfigInfoList.push({
                configName: "",
                configInfo: "",
            });
        },
        // [创建提测单时]-删除配置信息
        deleteConfigInfo(item, index) {
            this.createSubmitForm.submitConfigInfoList.splice(index, 1);
        },

        // 编辑提测单
        async editSubmit() {
            this.editSubmitForm.startTime = this.editSubmitForm.dateList[0]
            this.editSubmitForm.endTime = this.editSubmitForm.dateList[1]
            this.$refs.editSubmitFormRef.validate(async valid => {
                if (!valid) return
                const res = await this.$api.post("/sonar/submit/update", this.editSubmitForm)
                if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
                this.$message.success("更新成功!")
                await this.querySubmitByPage()
                this.editSubmitDialogVisible = false
            })
        },
        // [编辑提测单时]-增加项目信息
        addEditProjectInfo() {
            this.editSubmitForm.submitProjectInfoList.push({
                projectName: "",
                serviceName: "",
                branch: "",
            });
        },
        // [编辑提测单时]-删除项目信息
        async deleteEditProjectInfo(item, index) {
            // 删除已存在的项目信息, 调用链接口删除
            if (item.id !== undefined) {
                const confirmResult = await this.$confirm(
                    '此操作将永久删除该记录, 是否继续?',
                    '提示',
                    {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    }
                ).catch((err) => err)

                console.log("confirmResult: " + confirmResult)
                if (confirmResult === 'cancel') {
                    return this.$message.info('已取消删除！')
                }
                // 确认删除时, 调用接口
                if (confirmResult === 'confirm') {
                    const res = await this.$api.postForm("/sonar/submit/projectInfo/removeById", {id: item.id})
                    if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
                    this.editSubmitForm.submitProjectInfoList.splice(index, 1);
                    this.$message.success('删除成功！')
                }
            } else {
                this.editSubmitForm.submitProjectInfoList.splice(index, 1);
            }
        },
        // [编辑提测单时]-增加配置信息
        addEditConfigInfo() {
            this.editSubmitForm.submitConfigInfoList.push({
                configName: "",
                configInfo: "",
            });
        },
        // [编辑提测单时]-删除配置信息
        async deleteEditConfigInfo(item, index) {
            // 删除已存在的项目信息, 调用链接口删除
            if (item.id !== undefined) {
                const confirmResult = await this.$confirm(
                    '此操作将永久删除该记录, 是否继续?',
                    '提示',
                    {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    }
                ).catch((err) => err)

                if (confirmResult === 'cancel') {
                    return this.$message.info('已取消删除！')
                }
                // 确认删除时, 调用接口
                if (confirmResult === 'confirm') {
                    const res = await this.$api.postForm("/sonar/submit/configInfo/removeById", {id: item.id})
                    if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
                    this.editSubmitForm.submitConfigInfoList.splice(index, 1);
                    this.$message.success('删除成功！')
                }
            } else {
                this.editSubmitForm.submitConfigInfoList.splice(index, 1);
            }
        },

        // 监听页大小改变的事件
        handleSizeChange(newSize) {
            this.querySubmitParam.size = newSize;
            this.querySubmitByPage()
        },
        // 监听页码改变的事件
        handleCurrentChange(newPage) {
            this.querySubmitParam.page = newPage;
            this.querySubmitByPage()
        },

        // dialog显示事件
        async showSubmitInfoDialog(id) {
            const res = await this.$api.get("/sonar/submit/findById", {
                id
            })
            if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
            this.submitInfoForm = res.data
            // 查询迭代
            await this.queryAllSprintByProjectId(this.submitInfoForm.ownerProjectId)
            this.submitInfoDialogVisible = true
        },
        showCreateSubmitDialog() {
            this.createSubmitDialogVisible = true
        },
        async showEditSubmitDialog(id) {
            const res = await this.$api.get("/sonar/submit/findById", {
                id
            })
            if (res.code !== 200 || res.data === null) return this.$message.error(res.message)
            this.editSubmitForm = res.data
            // 查询迭代
            await this.queryAllSprintByProjectId(this.editSubmitForm.ownerProjectId)
            // 处理
            for (const index in this.editSubmitForm.submitProjectInfoList) {
                const projectName = this.editSubmitForm.submitProjectInfoList[index].projectName;
                this.showServiceNameMap[projectName] = this.moduleNameMap[projectName] !== undefined && JSON.parse(JSON.stringify(this.moduleNameMap[projectName])).length > 0 && JSON.parse(JSON.stringify(this.moduleNameMap[projectName]))[0] !== null;
            }
            if (this.editSubmitForm.submitConfigInfoList.length === 0) {
                this.editSubmitForm.submitConfigInfoList.push({
                    configName: "",
                    configInfo: "",
                })
            }

            this.editSubmitDialogVisible = true
        },

        // dialog关闭事件
        submitInfoDialogClose() {
            this.submitInfoDialogVisible = false
        },
        createSubmitDialogClose() {
            this.createSubmitForm = {
                submitProjectInfoList: [
                    {
                        projectName: "",
                        serviceName: "",
                        branch: "",
                    }
                ],
                submitConfigInfoList: [
                    {
                        configName: "",
                        configInfo: "",
                    }
                ]
            }
            this.createSubmitDialogVisible = false
        },
        editSubmitDialogClose() {
            this.editSubmitDialogVisible = false
        },
    },
    computed: {},
    created() {
        this.queryAllProject();
        this.queryAllProjectAndServiceModule();
        this.querySubmitByPage();
    },
}
</script>
<style lang="less" scoped>
.el-breadcrumb {
    height: 32px;
    line-height: 32px;
}

.el-dialog {
    .el-form-item {
        margin: 10px auto;
    }

    .el-dialog-div {
        height: 65vh;
        overflow: auto;
    }
}

.editDialog .el-table /deep/ .cell {
    white-space: pre-wrap;
}

.el-card {
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;

    .el-table {
        margin-top: 15px;
        margin-bottom: 15px;
    }

    .el-pagination {
        text-align: center;
        margin-top: 15px;
    }
}
</style>
