132 lines
4.6 KiB
Vue
132 lines
4.6 KiB
Vue
|
<template>
|
||
|
<el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="500px" :before-close="handleClose" center :close-on-click-modal="false">
|
||
|
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
|
||
|
<span slot="footer" class="dialog-footer">
|
||
|
<el-button type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
|
||
|
<el-button @click="dialogVisible = false">{{ $t('global.cancel') }}</el-button>
|
||
|
</span>
|
||
|
</el-dialog>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import { create, getData, update } from '@/api/management/dictionary';
|
||
|
|
||
|
export default {
|
||
|
name: 'DictionaryEdit',
|
||
|
props: {
|
||
|
type: {
|
||
|
type: String,
|
||
|
required: true
|
||
|
}
|
||
|
},
|
||
|
data() {
|
||
|
return {
|
||
|
dialogVisible: false,
|
||
|
formModel: {
|
||
|
code: '',
|
||
|
name: '',
|
||
|
status: '1',
|
||
|
remarks: ''
|
||
|
}
|
||
|
};
|
||
|
},
|
||
|
computed: {
|
||
|
form() {
|
||
|
const isAdd = this.type === 'ADD';
|
||
|
const form = {
|
||
|
labelWidth: '120px',
|
||
|
items: [
|
||
|
{ prop: 'controlMode', label: this.$t('system.controlMode'), type: 'text', required: true, disabled: !isAdd },
|
||
|
{ prop: 'deviceType', label: this.$t('system.deviceType'), type: 'select', required: true, options: this.$ConstSelect.Status },
|
||
|
{ prop: 'lineCode', label: this.$t('system.lineCode'), type: 'select', required: true, options: this.$ConstSelect.Status },
|
||
|
{ prop: 'role', label: this.$t('system.simulationRole'), type: 'select', required: true, options: this.$ConstSelect.Status },
|
||
|
{ prop: 'type', label: this.$t('system.instructionType'), type: 'select', required: true, options: this.$ConstSelect.Status }
|
||
|
]
|
||
|
};
|
||
|
return form;
|
||
|
},
|
||
|
rules() {
|
||
|
return {
|
||
|
controlMode: [
|
||
|
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
|
||
|
],
|
||
|
deviceType: [
|
||
|
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
|
||
|
],
|
||
|
lineCode: [
|
||
|
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
|
||
|
],
|
||
|
role: [
|
||
|
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
|
||
|
],
|
||
|
type: [
|
||
|
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
|
||
|
]
|
||
|
};
|
||
|
},
|
||
|
title() {
|
||
|
if (this.type === 'ADD') {
|
||
|
return this.$t('system.createDirective');
|
||
|
} else {
|
||
|
return this.$t('system.editDirective');
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
show(id) {
|
||
|
this.dialogVisible = true;
|
||
|
if (id) {
|
||
|
getData(id).then(response => {
|
||
|
this.formModel = response.data;
|
||
|
this.$refs.dataform.resetForm();
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
doSave() {
|
||
|
const self = this;
|
||
|
this.$refs.dataform.validateForm(() => {
|
||
|
if (self.type === 'ADD') {
|
||
|
self.create();
|
||
|
} else {
|
||
|
self.update();
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
create() {
|
||
|
const self = this;
|
||
|
create(this.formModel).then(response => {
|
||
|
self.$message.success(this.$t('system.createSuccess'));
|
||
|
self.handleClose();
|
||
|
self.$emit('reloadTable');
|
||
|
}).catch(error => {
|
||
|
self.$message.error(`${this.$t('error.createDictionaryFailed')}:${error.message}`);
|
||
|
});
|
||
|
},
|
||
|
update() {
|
||
|
const self = this;
|
||
|
update(this.formModel).then(response => {
|
||
|
self.$message.success(this.$t('system.updateSuccess'));
|
||
|
self.handleClose();
|
||
|
self.$emit('reloadTable');
|
||
|
}).catch(error => {
|
||
|
self.$message.error(`${this.$t('error.updateDictionaryFailed')}:${error.message}`);
|
||
|
});
|
||
|
},
|
||
|
handleClose(done) {
|
||
|
this.formModel = {
|
||
|
code: '',
|
||
|
name: '',
|
||
|
status: '1',
|
||
|
remarks: ''
|
||
|
};
|
||
|
this.$refs.dataform.resetForm();
|
||
|
if (done) {
|
||
|
done();
|
||
|
} else {
|
||
|
this.dialogVisible = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
</script>
|