rt-sim-training-client/src/views/system/configLine/edit.vue

148 lines
5.0 KiB
Vue
Raw Normal View History

<template>
<el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="30%" :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 { addSkinCode, updateSkinCode } from '@/api/management/mapline';
export default {
name: 'DictionaryEdit',
props: {
type: {
type: String,
required: true
}
},
data() {
return {
dialogVisible: false,
formModel: {
id: '',
code: '',
name: '',
origin: { x: 0, y: 0 },
scaling: 1
}
};
},
computed: {
form() {
const isAdd = this.type === 'ADD';
const form = {
labelWidth: '100px',
items: [
{ prop: 'code', label: this.$t('system.code'), type: 'text', disabled: !isAdd },
{ prop: 'name', label: this.$t('system.name'), type: 'text' },
{ prop: 'origin', label: '坐标:', type: 'coordinate', children: [
{ prop: 'origin.x', firstLevel: 'origin', secondLevel: 'x', label: 'x', type: 'number', labelWidth: '20px'},
{ prop: 'origin.y', firstLevel: 'origin', secondLevel: 'y', label: 'y', type: 'number', labelWidth: '20px'}
] },
{ prop: 'scaling', label: '缩放比例:', type: 'number', min: 0.4, max: 8, step: 0.2 }
]
};
return form;
},
rules() {
const crules = {
name: [
{ required: true, message: this.$t('rules.pleaseInputName'), trigger: 'blur' }
],
status: [
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
],
'origin.x': [
{ required: true, message: '请输入坐标x', trigger: 'blur' }
],
'origin.y': [
{ required: true, message: '请输入坐标y', trigger: 'blur' }
],
scaling: [
{ required: true, message: '请输入缩放比例', trigger: 'blur' }
]
};
if (this.type === 'ADD') {
return Object.assign(crules, {
code: [
{ required: true, message: this.$t('rules.pleaseInputCode'), trigger: 'blur' }
]
});
} else {
return crules;
}
},
title() {
if (this.type === 'ADD') {
return this.$t('system.createDirectory');
} else {
return this.$t('system.editDictionary');
}
}
},
methods: {
show(row) {
this.dialogVisible = true;
if (row && row.id) {
this.formModel = {
id: row.id,
code: row.code,
name: row.name,
origin: row.origin,
scaling: row.scaling
};
}
},
doSave() {
const self = this;
this.$refs.dataform.validateForm(() => {
if (self.type === 'ADD') {
self.create();
} else {
self.update();
}
});
},
create() {
addSkinCode(this.formModel).then(response => {
this.$message.success(this.$t('system.createSuccess'));
this.handleClose();
this.$emit('reloadTable');
}).catch(error => {
this.$message.error(`${this.$t('error.createDictionaryFailed')}:${error.message}`);
});
},
update() {
updateSkinCode(this.formModel).then(response => {
this.$message.success(this.$t('system.updateSuccess'));
this.handleClose();
this.$emit('reloadTable');
}).catch(error => {
this.$message.error(`${this.$t('error.updateDictionaryFailed')}:${error.message}`);
});
},
handleClose(done) {
this.formModel = {
id: '',
code: '',
name: '',
origin: { x: 0, y: 0 },
scaling: 1
};
this.$refs.dataform.resetForm();
if (done) {
done();
} else {
this.dialogVisible = false;
}
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>