<template> <el-dialog :title="title" :visible.sync="dialogFormVisible" append-to-body> <el-form ref="dataForm" :rules="rules" :model="weightForm" label-well-code="right" label-width="120px"> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="部门职能指标" prop="deptindex"> <el-input v-model.trim="weightForm.deptindex" :disabled="isEditMode" :min="0" :max="100" type="number" placeholder="必填"> <i slot="suffix" style="font-style:normal;margin-right: 12px;">%</i> </el-input> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="专题专项指标" prop="specialindex"> <el-input v-model.trim="weightForm.specialindex" :disabled="isEditMode" :min="0" :max="100" type="number" placeholder="必填"> <i slot="suffix" style="font-style:normal;margin-right: 12px;">%</i> </el-input> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="经济发展指标" prop="economyindex"> <el-input v-model.trim="weightForm.economyindex" :disabled="isDetailMode" :min="0" :max="100" type="number" placeholder="必填"> <i slot="suffix" style="font-style:normal;margin-right: 12px;">%</i> </el-input> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="行政综合指标" prop="totalindex"> <el-input v-model.trim="weightForm.totalindex" :disabled="isDetailMode" :min="0" :max="100" type="number" placeholder="必填"> <i slot="suffix" style="font-style:normal;margin-right: 12px;">%</i> </el-input> </el-form-item> </el-col> </el-row> </el-form> <div v-show="!isDetailMode" slot="footer" class="dialog-footer"> <el-button type="primary" @click="saveData">保存</el-button> <el-button @click="cancel">取消</el-button> </div> </el-dialog> </template> <script> import { updateWeight } from '@/api/assessRules' export default { name: 'EditPermWeight', data() { const deptindexValidate = (rule, value, callback) => { if (value !== '') { if (parseInt(value) < 0 || parseInt(value) > 100) { callback(new Error('指标权重值必须在0-100之间')) } else { callback() } } else { callback(new Error('部门职能指标不能为空')) } } const specialindexValidate = (rule, value, callback) => { if (value !== '') { if (parseInt(value) < 0 || parseInt(value) > 100) { callback(new Error('指标权重值必须在0-100之间')) } else { callback() } } else { callback(new Error('专题专项指标不能为空')) } } const economyindexValidate = (rule, value, callback) => { if (value !== '') { if (parseInt(value) < 0 || parseInt(value) > 100) { callback(new Error('指标权重值必须在0-100之间')) } else { callback() } } else { callback(new Error('经济发展指标不能为空')) } } const totalindexValidate = (rule, value, callback) => { if (value !== '') { if (parseInt(value) < 0 || parseInt(value) > 100) { callback(new Error('指标权重值必须在0-100之间')) } else { callback() } } else { callback(new Error('行政综合指标不能为空')) } } return { dialogFormVisible: false, // 对话框是否显示 dialogStatus: '', // 对话框类型:create,update,detail isEdit: false, weightForm: { id: '', deptindex: '', specialindex: '', economyindex: '', totalindex: '' }, // 表单 title: '', textMap: { update: '编辑', create: '新增', detail: '详情' }, // 表头显示标题 rules: { deptindex: [{ required: true, validator: deptindexValidate, trigger: ['blur', 'change'] }], specialindex: [{ required: true, validator: specialindexValidate, trigger: ['blur', 'change'] }], economyindex: [{ required: true, validator: economyindexValidate, trigger: ['blur', 'change'] }], totalindex: [{ required: true, validator: totalindexValidate, trigger: ['blur', 'change'] }] }, // 前端校验规则 isEditMode: false, // 编辑模式 isDetailMode: false // 详情模式 } }, mounted() { this.fetchData() }, methods: { // 初始化对话框 initDialog: function(dialogStatus, dialogFormVisible, row) { this.dialogStatus = dialogStatus this.dialogFormVisible = dialogFormVisible this.title = this.textMap[dialogStatus] + '-' + row.deptName this.isEdit = false this.resetForm() if (dialogStatus === 'create') { // 如果是新增,清除验证 this.resetForm() this.isEditMode = false this.isDetailMode = false this.$nextTick(() => { this.$refs['dataForm'].clearValidate() }) } else if (dialogStatus === 'update') { // 如果是修改,将row中数据填写到输入框中 this.weightForm.id = row.id this.weightForm.deptindex = row.deptindex this.weightForm.specialindex = row.specialindex this.weightForm.economyindex = row.economyindex this.weightForm.totalindex = row.totalindex } }, // 重置表单 resetForm() { this.deviceForm = { deviceName: '', devcode: '', deviceType: '', wellCode: '', modelId: '', installDate: '' } }, // 保存数据 saveData: function() { if (this.dialogStatus === 'update') { this.updateData() } else if (this.dialogStatus === 'create') { this.createData() } }, // 新增数据 createData: function() { this.$refs['dataForm'].validate((valid) => { console.log(this.deviceForm) if (valid) { // addDevice(this.deviceForm).then(response => { // if (response.code === 200) { // this.$confirm('新增成功,是否继续新增?', '提示', { // confirmButtonText: '是', // cancelButtonText: '否', // type: 'info' // }).then(() => { // this.resetForm() // this.$nextTick(() => { // this.$refs['dataForm'].clearValidate() // }) // }).catch(() => { // this.$emit('watchChild') // this.dialogFormVisible = false // }) // } // }) } }) }, // 修改数据 updateData: function() { this.$refs['dataForm'].validate((valid) => { if (valid) { var total = parseInt(this.weightForm.totalindex) + parseInt(this.weightForm.deptindex) + parseInt(this.weightForm.specialindex) + parseInt(this.weightForm.economyindex) if (parseInt(total) > 100) { this.$message.error('修改失败,各指标权重之和不能大于100') return } else if (parseInt(total) < 100) { this.$message.error('修改失败,各指标权重之和不能小于100') return } updateWeight(this.weightForm).then(response => { if (response.code === 200) { this.$message.success('修改成功') this.$emit('watchChild') this.dialogFormVisible = false } }) } }) }, cancel: function() { this.dialogFormVisible = false this.$emit('watchChild') } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> .el-select{ width: 100%; } .el-date-editor{ width: 100%; } </style>