<template> <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false" append-to-body> <el-form ref="dataForm" :rules="rules" :model="form" label-well-code="right" label-width="120px"> <el-form-item label="项目名称" prop="name"> <el-input v-model.trim="form.name" :disabled="dialogStatus === 'detail'" type="text" placeholder="必填"/> </el-form-item> <el-form-item label="项目简称" prop="abbreviation"> <el-input v-model.trim="form.abbreviation" :disabled="dialogStatus === 'detail'" type="text" placeholder="必填"/> </el-form-item> <el-form-item label="项目开始日期" prop="startDate"> <el-date-picker v-model="form.startDate" :disabled="dialogStatus === 'detail'" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date" placeholder="请选择开始日期" /> </el-form-item> <el-form-item label="项目结束日期" prop="endDate"> <el-date-picker v-model="form.endDate" :disabled="dialogStatus === 'detail'" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date" placeholder="请选择结束日期" /> </el-form-item> <el-form-item label="生产设备类型" prop="type"> <el-input v-model.trim="form.type" :disabled="dialogStatus === 'detail'" :placeholder="dialogStatus === 'detail' ? '' : '必填'" type="text"/> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="saveData">提交</el-button> <el-button @click="cancel">取消</el-button> </div> </el-dialog> </template> <script> export default { name: 'EditDeviceType', data() { return { dialogFormVisible: false, // 对话框是否显示 dialogStatus: '', // 对话框类型:create,update form: { name: '', // 名称 abbreviation: '', // 简称 startDate: '', // 开始日期 endDate: '', // 结束日期 type: '', // 生产设备类型 id: '' // 主键 }, // 表单 textMap: { update: '编辑', create: '新增', detail: '详情' }, // 表头显示标题 rules: { name: [{ required: true, message: '项目名称不能为空', trigger: ['blur', 'change'] }], abbreviation: [{ required: true, message: '项目简称不能为空', trigger: ['blur', 'change'] }], startDate: [{ type: 'date', required: true, message: '项目开始日期不能为空', trigger: 'change' }], endDate: [{ type: 'date', required: true, message: '项目结束日期不能为空', trigger: 'change' }], } // 前端校验规则 } }, created() { this.fetchPrincipalList() this.fetchDeptList() }, methods: { // 初始化对话框 initDialog: function(dialogStatus, dialogFormVisible, row = null) { this.dialogStatus = dialogStatus // 类型 新增create 编辑update 详情detail this.dialogFormVisible = dialogFormVisible // 对话框显隐 if (dialogStatus === 'create') { // 如果是新增,清除验证 this.resetForm() this.$nextTick(() => { this.$refs['dataForm'].clearValidate() }) } else if (dialogStatus === 'update') { // 如果是修改,将row中数据填写到输入框中 this.form = { name: row.name, // 名称 abbreviation: row.abbreviation, // 简称 startDate: row.startDate, // 开始日期 endDate: row.endDate, // 结束日期 type: row.type, // 生产设备类型 id: row.id } } }, // 重置表单 resetForm() { this.form = { name: '', // 名称 abbreviation: '', // 简称 startDate: '', // 开始日期 endDate: '', // 结束日期 type: '' // 生产设备类型 } }, // 点击提交 saveData: function() { if (this.dialogStatus === 'update') { this.updateData() } else if (this.dialogStatus === 'create') { this.createData() } }, // 新增数据 createData: function() { this.$refs['dataForm'].validate((valid) => { if (valid) { // addDeviceType(this.form.productName, this.form.productModel, this.form.machineVersion, // this.form.hardwareVersion, this.form.softwareVersion, this.form.designArchive, // this.form.batchFiling, this.form.status, this.form.principal, // this.form.kpi, this.form.quotaSummary, this.quotaSummaryFile, this.form.communicationVersion, // this.form.productType).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) { // updateDeviceType(this.form.id, this.form.productName, this.form.productModel, this.form.machineVersion, // this.form.hardwareVersion, this.form.softwareVersion, this.form.designArchive, // this.form.batchFiling, this.form.status, this.form.principal, // this.form.kpi, this.form.quotaSummary, this.quotaSummaryFile, this.form.communicationVersion, // this.form.productType).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>