GuLiMmo
2024-01-23 1e36aba92dc35c1ea98e5585ff8011376d7f71b5
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<template>
    <el-dialog v-model="params.visible" :title="params.title || '编辑部门评优任务'" width="50%" @open="openDialog"
        @close="dialogClose" destroy-on-close>
        <div class="content">
            <el-form :model="form" ref="formRef" :rules="rules" label-width="130px">
                <el-form-item label="任务名称" prop="taskName">
                    <el-input v-model="form.taskName" placeholder="请输入任务名称"></el-input>
                </el-form-item>
                <el-form-item label="评优奖项" prop="evaluateAwards">
                    <el-input v-model="form.evaluateAwards" placeholder="请输入评优奖项"></el-input>
                </el-form-item>
                <el-form-item label="认定标准描述" prop="identificationStandard">
                    <el-input v-model="form.identificationStandard" type="textarea" placeholder="请输入认定标准描述"></el-input>
                </el-form-item>
                <el-form-item label="投票人员" prop="pollingPersons">
                    <el-checkbox-group v-model="form.pollingPersons">
                        <el-checkbox v-for="item in employeeDict" :key="item.id" :label="item.dictKey"
                            @change="checkBoxChange($event, item)">
                            {{ item.dictValue }}
                            <el-button type="primary" icon="el-icon-edit" text
                                @click="selectionHandler(item)">设置人员</el-button>
                        </el-checkbox>
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item label="投票时间" required>
                    <el-form-item class="time-box" prop="evaluateCutoffTimeStart">
                        <el-date-picker v-model="form.evaluateCutoffTimeStart" type="datetime" placeholder="请选择任务开始时间"
                            value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%;" />
                    </el-form-item>
                    <span class="time-span">至</span>
                    <el-form-item class="time-box" prop="evaluateCutoffTimeEnd">
                        <el-date-picker v-model="form.evaluateCutoffTimeEnd" type="datetime" placeholder="请选择任务结束时间"
                            value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%;" />
                    </el-form-item>
                </el-form-item>
            </el-form>
        </div>
        <template #footer>
            <el-button @click="() => params.visible = false">取消</el-button>
            <el-button type="primary" @click="submit">确定</el-button>
        </template>
        <!-- 人员选择 -->
        <selectionDialog :params="selectionParams" @addEvaluateParams="addEvaluateParams" />
    </el-dialog>
</template>
 
<script>
import { getDict } from '@/api/dict'
import { update, getEmployeeLevelList } from '@/api/evaluate/evaluateTask'
import _ from 'lodash';
import selectionDialog from './selectionDialog.vue';
 
export default {
    inject: ['type'],
    components: {
        selectionDialog
    },
    props: {
        params: {
            type: Object,
            default: () => {
                return {
                    visible: false,
                    title: '新增部门评优任务',
                    data: {}
                };
            },
        },
    },
    data() {
        return {
            form: {
                id: '',
                taskName: '',
                evaluateAwards: '',
                identificationStandard: '',
                pollingPersons: [],
                votePersonObjInfo: [],
                evaluateCutoffTimeStart: '',
                evaluateCutoffTimeEnd: ''
            },
            rules: {
                taskName: [
                    { required: true, message: '请输入任务名称', trigger: 'click' },
                ],
                evaluateAwards: [
                    { required: true, message: '请输入评优奖项', trigger: 'click' },
                ],
                identificationStandard: [
                    { required: true, message: '请输入认定标准', trigger: 'click' },
                ],
                pollingPersons: [
                    { required: true, message: '请选择评定人员', trigger: 'click' },
                ],
                evaluateCutoffTimeStart: [
                    { required: true, message: '请选择任务开始时间', trigger: 'click' },
                    {
                        validator: (rule, value, callback) => {
                            if (value) {
                                const startTime = new Date(value).getTime()
                                const endTime = new Date(this.form.candidateCutoffTimeEnd).getTime()
                                const nowTime = new Date().getTime()
                                // if (nowTime > startTime) {
                                //     callback(new Error('开始时间不能早于当前时间'))
                                // } else
                                if (startTime >= endTime) {
                                    callback(new Error('结束时间不能早于等于开始时间'))
                                } else {
                                    callback()
                                }
                            }
                        }, trigger: 'click'
                    }
                ],
                evaluateCutoffTimeEnd: [
                    { required: true, message: '请选择任务开始时间', trigger: 'click' },
                    {
                        validator: (rule, value, callback) => {
                            if (value) {
                                const startTime = new Date(this.form.candidateCutoffTimeStart).getTime()
                                const endTime = new Date(value).getTime()
                                const nowTime = new Date().getTime() - (24 * 60 * 60 * 1000)
                                if (nowTime > startTime) {
                                    callback(new Error('开始时间不能早于当日时间'))
                                } else if (startTime >= endTime) {
                                    callback(new Error('结束时间不能早于等于开始时间'))
                                } else {
                                    callback()
                                }
                            }
                        }, trigger: 'click'
                    }
                ]
            },
            employeeDict: [],
            selectionParams: {}
        }
    },
    watch: {
        'params.visible': {
            handler(val) {
                if (!val) return
                const { id, taskName, evaluateAwards, identificationStandard, pollingPersons, votePersonObjInfo, evaluateCutoffTimeStart, evaluateCutoffTimeEnd } = this.params.data
                this.form.id = id
                this.form.taskName = taskName
                this.form.evaluateAwards = evaluateAwards
                this.form.identificationStandard = identificationStandard
                this.form.pollingPersons = pollingPersons.split(',') || []
                this.form.votePersonObjInfo = JSON.parse(votePersonObjInfo) || []
                this.form.evaluateCutoffTimeStart = evaluateCutoffTimeStart
                this.form.evaluateCutoffTimeEnd = evaluateCutoffTimeEnd
                console.log('编辑回显');
            },
            deep: true
        }
    },
    methods: {
        dialogClose() {
            this.$refs.formRef.resetFields()
        },
        openDialog() {
            this.initDict()
            // const { id, taskName, evaluateAwards, identificationStandard, pollingPersons, votePersonObjInfo, evaluateCutoffTimeStart, evaluateCutoffTimeEnd } = this.params.data
            // this.form.id = id
            // this.form.taskName = taskName
            // this.form.evaluateAwards = evaluateAwards
            // this.form.identificationStandard = identificationStandard
            // this.form.pollingPersons = pollingPersons.split(',') || []
            // this.form.votePersonObjInfo = JSON.parse(votePersonObjInfo) || []
            // this.form.evaluateCutoffTimeStart = evaluateCutoffTimeStart
            // this.form.evaluateCutoffTimeEnd = evaluateCutoffTimeEnd
            // this.form = {
            //     id,
            //     taskName,
            //     evaluateAwards,
            //     identificationStandard,
            //     pollingPersons: pollingPersons.split(',') || [],
            //     votePersonObjInfo: JSON.parse(votePersonObjInfo) || [],
            //     evaluateCutoffTimeStart,
            //     evaluateCutoffTimeEnd
            // }
        },
        submit() {
            this.$refs.formRef.validate(vaild => {
                if (!vaild) return
                const data = _.cloneDeep(this.form)
                data.pollingPersons = data.pollingPersons.join(',')
                data.type = this.type()
                update(data).then(res => {
                    if (res.data.code !== 200) return
                    this.$message.success('更新当前任务成功')
                    this.params.visible = false
                    this.$emit('refreshTable', { currentPage: 1, pageSize: 10 })
                })
            })
        },
        initDict() {
            getDict('employee_type').then(res => {
                const { code, data } = res.data
                if (code !== 200) {
                    return this.$message.error('人员类型字典加载失败')
                }
                this.employeeDict = data
            })
        },
        selectionHandler(row) {
            const obj = this.form.votePersonObjInfo.find(item => item.employeeType === row.dictKey) || {}
            this.selectionParams = {
                visible: true,
                data: row,
                values: obj
            }
        },
        checkBoxChange(e, { dictKey }) {
            const index = this.form.votePersonObjInfo.findIndex(item => item.employeeType === dictKey)
            if (!e) {
                this.form.votePersonObjInfo.splice(index, 1)
                return
            }
            getEmployeeLevelList(dictKey).then((res) => {
                const { code, data } = res.data
                if (code !== 200) return this.$message.error('当前级别人员加载失败,请重试!!')
                const participateInList = data.map(item => {
                    const { id, name, deptId, deptName, postId, postName } = item
                    return { id, name, deptId, deptName, postId, postName }
                })
                const params = {
                    employeeType: dictKey,
                    participateIn: participateInList,
                    notParticipateIn: []
                }
                if (index === -1) {
                    this.form.votePersonObjInfo.push(params)
                } else {
                    this.form.votePersonObjInfo[index] = params
                }
            })
        },
        addEvaluateParams(params) {
            const { participateIn, employeeType } = params
            const index = this.form.votePersonObjInfo.findIndex(item => item.employeeType === employeeType)
            const typeIndex = this.form.pollingPersons.findIndex(item => item === employeeType)
 
            if (index === -1) {
                if (participateIn.length > 0) {
                    this.form.votePersonObjInfo.push(params)
                    this.form.pollingPersons.push(params.employeeType)
                }
            } else {
                if (participateIn.length > 0) {
                    this.form.votePersonObjInfo[index] = params
                } else {
                    this.form.votePersonObjInfo.splice(index, 1)
                    this.form.pollingPersons.splice(typeIndex, 1)
                }
            }
        }
    }
};
</script>
 
<style lang="scss" scoped>
$borderColor: var(--el-border-color);
 
.content {
    max-height: 400px;
    overflow-y: auto;
 
    .time-span {
        margin: 0 10px;
    }
 
    .time-box {
        width: calc(100% / 2 - 20px);
    }
}
</style>