北尚诉办前端
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.

201 lines
7.1 KiB

<template>
<el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
<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:80%;"
:disabled="dataForm.id?true:false"
>
</el-cascader>
</el-form-item>
<el-form-item label="考核年月" prop="monthYear" label-width="120px">
<el-date-picker v-model="dataForm.monthYear" :disabled="dataForm.id?true:false"
type="month" clearable placeholder="选择月"
value-format="yyyy-MM" format="yyyy-MM">
</el-date-picker>
</el-form-item>
<el-form-item label="建站达标" prop="stationEstablishment" label-width="120px">
<el-input-number v-model="dataForm.stationEstablishment" :min="0" :max="4" label="建站达标分数" :precision="1"></el-input-number>
</el-form-item>
<el-form-item label="人员配备" prop="staffingPlacement" label-width="120px">
<el-input-number v-model="dataForm.staffingPlacement" :min="0" :max="3" label="人员配备分数" :precision="1"></el-input-number>
</el-form-item>
<el-form-item label="网格运行" prop="gridOperation" label-width="120px">
<el-input-number v-model="dataForm.gridOperation" :min="0" :max="3" label="网格运行分数" :precision="1"></el-input-number>
</el-form-item>
</el-form>
<template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button>
<el-button type="primary" :disabled="isAble" @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: '',
monthYear: '',
stationEstablishment: '',
staffingPlacement: '',
gridOperation: '',
parentDeptIds: '',
parentDeptNames: '',
allDeptIds: '',
allDeptNames: '',
revision: '',
createdBy: '',
createdTime: '',
updatedBy: '',
updatedTime: '',
delFlag: '',
joinDeptIdsArr: ''
},
options: [],
isAble: false
}
},
computed: {
dataRule () {
return {
deptName: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
deptTypeKey: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
monthYear: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
stationEstablishment: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
staffingPlacement: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
gridOperation: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
joinDeptIdsArr: [
{ required: false, message: this.$t('validate.required'), trigger: 'blur' }
]
}
}
},
created: function () {
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/getDeptAuthByUser`)
.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/kpigridentity/${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
}
this.isAble = true
this.$http[!this.dataForm.id ? 'post' : 'put']('/kpi/kpigridentity/', 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>