spring
2025-02-19 bb98d4606e64ee048e99a83df2ef554c9605d692
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<template>
    <div class="add">
        <el-dialog
            :isEdit="isEdit"
            :title="isEdit ? '编辑工作监督记录':'新增工作监督记录'"
            :visible.sync="dialogVisible"
            width="800"
        >
            <el-steps v-if="isEdit" :active="active" :align-center="true" finish-status="success">
                <el-step style="cursor: pointer;" title="检测" @click.native="setStep(0)"></el-step>
                <el-step style="cursor: pointer;" title="审批" @click.native="setStep(1)"></el-step>
            </el-steps>
            <SuperviseForm
                v-show="pageStatus == 0"
                ref="superviseFormRef"
                :disabled="active != 0"
                :isEdit="isEdit"
                :superviseForm.sync="mainForm.superviseForm"
                :userList="userList"
                @addData="addData"
                @close="closeDialog"
                @submit="submit"
            ></SuperviseForm>
            <ApproveForm
                v-show="pageStatus == 1"
                ref="approveFormRef"
                :approveForm.sync="mainForm.approveForm"
                :disabled="active != 1"
                :isEdit="isEdit"
                :userList="userList"
                @close="toClose"
                @submit="submit"
            ></ApproveForm>
            <el-result v-show="pageStatus == 2" icon="success" subTitle="处理完成" title="审核完成">
            </el-result>
        </el-dialog>
    </div>
</template>
<script>
import SuperviseForm from './supervise/SuperviseForm.vue'
import ApproveForm from './supervise/ApproveForm.vue'
import {
    getUserListApi,
    addOrUpdatePersonSupervisionRecord
} from "../../../../../assets/api/api"
import dayjs from 'dayjs'
 
export default {
    components: {
        SuperviseForm,
        ApproveForm
    },
    data() {
        return {
            active: 0,
            pageStatus: 0,
            isEdit: false,
            dialogVisible: false,
            userList: [],
            id: undefined,
            mainForm: {
                superviseForm: {
                    testerId: undefined,
                    supervisorId: undefined,
                    testItem: undefined,
                    sampleNumber: undefined,
                    detectionDate: undefined,
                    personnel: [],
                    instrumentEquipment: undefined,
                    workingEnvironment: undefined,
                    sampleCollection: undefined,
                    samplePreparation: undefined,
                    testMethod: undefined,
                    testingRecords: undefined,
                    testReport: undefined,
                    evaluationSupervisionSituation: undefined,
                    doNotMeetTheHandlingOpinions: undefined,
                },
                approveForm: {
                    technicalDirector: undefined
                }
            }
        }
    },
    methods: {
        async openDialog(row, type=false) {
            this.dialogVisible = true
            this.isEdit = type
            await this.getUserList()
            if(this.isEdit) {
                // 编辑
                this.loadForm(row)
                this.id = row.id
            } else {
                // 新增
                this.resetForm(row)
                this.id = undefined
            }
        },
        /**
         * @desc 加载表单
         */
         loadForm(row) {
            if(row.currentState) {
                this.active = Number(row.currentState)
                this.pageStatus = Number(row.currentState === '2' ? 0 : row.currentState)
            }
            // 第1步
            this.mainForm.superviseForm.testerId = row.testerId
            this.mainForm.superviseForm.supervisorId = row.supervisorId
            this.mainForm.superviseForm.testItem = row.testItem
            this.mainForm.superviseForm.sampleNumber = row.sampleNumber
            this.mainForm.superviseForm.detectionDate = row.detectionDate
            let personList = row.personnel.split(',')
            this.mainForm.superviseForm.personnel = personList.map(item => {
                return Number(item)
            });
            this.mainForm.superviseForm.instrumentEquipment = row.instrumentEquipment
            this.mainForm.superviseForm.workingEnvironment = row.workingEnvironment
            this.mainForm.superviseForm.sampleCollection = row.sampleCollection
            this.mainForm.superviseForm.samplePreparation = row.samplePreparation
            this.mainForm.superviseForm.testMethod = row.testMethod
            this.mainForm.superviseForm.testingRecords = row.testingRecords
            this.mainForm.superviseForm.testReport = row.testReport
            this.mainForm.superviseForm.evaluationSupervisionSituation = row.evaluationSupervisionSituation
            this.mainForm.superviseForm.doNotMeetTheHandlingOpinions = row.doNotMeetTheHandlingOpinions
            // 第2步
            this.mainForm.approveForm.technicalDirector = row.technicalDirector
        },
        /**
         * @desc 重置表单
         */
         resetForm(row) {
            console.log(row)
            this.active = 0
            this.pageStatus = 0
            // 第1个
            this.mainForm.superviseForm.currentState = undefined
            this.mainForm.superviseForm.testerId = undefined
            this.mainForm.superviseForm.supervisorId = undefined
            this.mainForm.superviseForm.testItem = undefined
            this.mainForm.superviseForm.sampleNumber = undefined
            this.mainForm.superviseForm.detectionDate = undefined
            this.mainForm.superviseForm.personnel = [row.departId]
            this.mainForm.superviseForm.instrumentEquipment = undefined
            this.mainForm.superviseForm.workingEnvironment = undefined
            this.mainForm.superviseForm.sampleCollection = undefined
            this.mainForm.superviseForm.samplePreparation = undefined
            this.mainForm.superviseForm.testMethod = undefined
            this.mainForm.superviseForm.testingRecords = undefined
            this.mainForm.superviseForm.testReport = undefined
            this.mainForm.superviseForm.evaluationSupervisionSituation = undefined
            this.mainForm.superviseForm.doNotMeetTheHandlingOpinions = undefined
            // 第2个
            this.mainForm.approveForm.technicalDirector = undefined
        },
        closeDialog() {
            this.dialogVisible = false
        },
        /**
         * @desc 获取用户信息
         */
        async getUserList() {
            const { code, data } = await this.$axios({
                method: 'get',
                url: getUserListApi,
            })
            if(code == 200) {
                this.userList = data
            }
        },
        /**
         * @desc 驳回
         */
        toClose() {
            this.submitFormApi({
                id: this.id,
                currentState: 0,
            })
        },
        /**
         * @desc 新增
         */
        addData(step) {
            let data = this.setParams(step)
            this.submitFormApi(data)
        },
        /**
         * @desc 编辑
         */
        submit(step) {
            console.log('编辑', this.isEdit)
            let data = this.setParams(step)
            data.id = this.id
            this.submitFormApi(data)
        },
        // 设置参数
        setParams(step) {
            if(step == 1) {
                let result = this.mainForm.superviseForm
                result.currentState = this.active + 1
                result.personnel = result.personnel.join(",")
                result.technicalDirectorDate = dayjs().format('YYYY-MM-DD HH:mm:ss')
                return result
            }
            if(step == 2) {
                let result = this.mainForm.approveForm
                result.currentState = this.active + 1
                return result
            }
        },
        // 向服务器发送表单
        async submitFormApi(data) {
            console.log('接口表单', data)
            const { code } = await this.$axios({
                method: 'post',
                url: addOrUpdatePersonSupervisionRecord,
                data: data,
                noQs: true
            })
            if(code == 200) {
                this.$message.success('操作成功')
                this.dialogVisible = false
                this.$emit('submit')
            }
        },
        setStep(e) {
            this.pageStatus = e
        }
    }
}
</script>
<style scoped>
.foot {
    width: 100%;
}
.add >>> .el-dialog__footer {
    padding-right: 20px;
}
.main_right {
    text-align: left;
}
</style>