<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>
|