北尚诉办前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

217 lines
7.7 KiB

<template>
<el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false" customClass="customWidth">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
<el-form-item label="部门名称" prop="deptId" label-width="120px">
<el-cascader
ref="name"
v-model="dataForm.joinDeptIdsArr"
:options="options"
:props="{ multiple: false, emitPath: false, checkStrictly: true }"
@visible-change="changeHandle"
style="width:90%;"
:disabled="dataForm.id?true:false"
>
</el-cascader>
</el-form-item>
<el-form-item label="考核年月" prop="year" label-width="120px">
<el-date-picker v-model="dataForm.year" :disabled="dataForm.id?true:false"
type="year" clearable placeholder="选择年"
value-format="yyyy" format="yyyy" style="width:45%;">
</el-date-picker>
</el-form-item>
<el-form-item label="满意" prop="satisfied" label-width="120px">
<el-input-number v-model="dataForm.satisfied" :min="0" :max="20" label="满意分数" :precision="1" style="width:45%;"></el-input-number>
</el-form-item>
<el-form-item label="基本满意" prop="basicSatisfaction" label-width="120px">
<el-input-number v-model="dataForm.basicSatisfaction" :min="0" :max="20" label="基本满意分数" :precision="1" style="width:45%;"></el-input-number>
</el-form-item>
<el-form-item label="不满意" prop="dissatisfied" label-width="120px">
<el-input-number v-model="dataForm.dissatisfied" :min="0" :max="20" label="不满意分数" :precision="1" style="width:45%;"></el-input-number>
</el-form-item>
</el-form>
<template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button>
<el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
</template>
</el-dialog>
</template>
<script>
import debounce from 'lodash/debounce'
export default {
data () {
return {
visible: false,
dataForm: {
id: '',
deptId: '',
deptName: '',
deptTypeKey: '',
year: '',
satisfied: '',
basicSatisfaction: '',
dissatisfied: '',
parentDeptIds: '',
parentDeptNames: '',
allDeptIds: '',
allDeptNames: '',
revision: '',
createdBy: '',
createdTime: '',
updatedBy: '',
updatedTime: '',
delFlag: '',
joinDeptIdsArr: ''
},
options: [],
isAble: false
}
},
computed: {
dataRule () {
return {
deptId: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
deptName: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
deptTypeKey: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
year: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
satisfied: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
basicSatisfaction: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
dissatisfied: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
joinDeptIdsArr: [
{ required: false, message: this.$t('validate.required'), trigger: 'blur' }
]
}
}
},
created: function () {
this.dataForm.joinDeptIdsArr = ''
this.dataForm.deptId = ''
this.getOptions()
},
methods: {
init () {
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
this.getInfo()
} else {
this.dataForm.joinDeptIdsArr = ''
this.dataForm.deptId = ''
}
})
},
getOptions () {
this.$http
.get(`/sys/user/deptOptions/getAllDeptPartyByUser`)
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.options = res.data.options
})
.catch(() => {})
},
changeHandle (value, selectedData) {
let parentDeptIds = ''
let parentDeptNames = ''
let allDeptIds = ''
let allDeptNames = ''
let deptId = ''
let deptName = ''
if (this.$refs['name'].getCheckedNodes() !== null && this.$refs['name'].getCheckedNodes().length > 0) {
var path = this.$refs['name'].getCheckedNodes()[0].path
var pathLabels = this.$refs['name'].getCheckedNodes()[0].pathLabels
for (var i = 0; i < path.length; i++) {
if (i < path.length - 1) {
parentDeptIds += path[i] + ','
} else {
deptId = path[i]
}
allDeptIds += path[i] + ','
}
for (var j = 0; j < pathLabels.length; j++) {
if (j < pathLabels.length - 1) {
parentDeptNames += pathLabels[j] + '-'
} else {
deptName = pathLabels[j]
}
allDeptNames += pathLabels[j] + '-'
}
}
this.dataForm.parentDeptIds = parentDeptIds.length > 0 ? parentDeptIds.substring(0, parentDeptIds.length - 1) : parentDeptIds
this.dataForm.parentDeptNames = parentDeptNames.length > 0 ? parentDeptNames.substring(0, parentDeptNames.length - 1) : parentDeptNames
this.dataForm.allDeptIds = allDeptIds.length > 0 ? allDeptIds.substring(0, allDeptIds.length - 1) : allDeptIds
this.dataForm.allDeptNames = allDeptNames.length > 0 ? allDeptNames.substring(0, allDeptNames.length - 1) : allDeptNames
this.dataForm.deptId = deptId
this.dataForm.deptName = deptName
},
// 获取信息
getInfo () {
this.$http.get(`/kpi/kpimassevaluation/${this.dataForm.id}`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.dataForm = {
...this.dataForm,
...res.data
}
this.dataForm.joinDeptIdsArr = this.dataForm.deptId
}).catch(() => {})
},
// 表单提交
dataFormSubmitHandle: debounce(function () {
this.$refs['dataForm'].validate((valid) => {
if (!valid) {
return false
}
// 校验分数是否总计未超过20
let satisfied = this.dataForm.satisfied
let basicSatisfaction = this.dataForm.basicSatisfaction
let dissatisfied = this.dataForm.dissatisfied
if ((satisfied + basicSatisfaction + dissatisfied) > 20) {
return this.$message.error('评价分数总和不能超过20分!')
}
this.isAble = true
this.$http[!this.dataForm.id ? 'post' : 'put']('/kpi/kpimassevaluation/', this.dataForm).then(({ data: res }) => {
if (res.code !== 0) {
this.isAble = false
return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
this.isAble = false
this.dataForm.joinDeptIdsArr = ''
this.dataForm.deptId = ''
this.visible = false
this.$emit('refreshDataList')
}
})
}).catch(() => {})
})
}, 1000, { 'leading': true, 'trailing': false })
}
}
</script>
<style lang="scss">
.customWidth {
width:35%
}
</style>