rt-sim-training-client/src/views/system/deviceManage/add.vue

109 lines
3.8 KiB
Vue
Raw Normal View History

2020-01-02 17:01:11 +08:00
<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="handleClose">{{ $t('global.cancel') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { createDevice, deviceIsExist} from '@/api/project';
export default {
name: 'DeviceAdd',
props: {
type: {
type: String,
required: true
}
},
data() {
return {
dialogVisible: false,
formModel: {
code: '',
type: '',
projectCode: ''
},
LessonList: [],
UserList: [],
UserLoading: false,
deviceTypeList:[{label: '道岔', value: 'SWITCH'}, {label: '信号机', value:'SIGNAL'}, {label: '屏蔽门', value: 'PSD'}],
projectList: [{label:'西铁院', value: 'XTY'}, {label: '贵州装备', value:'GZB'}],
gatewayList: []
};
},
computed: {
form() {
const form = {
labelWidth: '120px',
items: [
{ prop: 'code', label: '设备编码', type: 'text', required: true, placeholder: '请输入设备编码' },
{ prop: 'type', label: '设备类型', type: 'select', required: true, options: this.deviceTypeList, placeholder: '请选择设备类型' },
{ prop: 'projectCode', label: '所属项目', type: 'select', required: true, options: this.projectList, placeholder: '请选择设备所属项目'}
]
};
return form;
},
rules() {
const crules = {
code: [
{ required: true, message: '请输入设备编码', trigger: 'blur' }
],
type: [
{ required: true, message: '请选择设备类型', trigger: 'change' }
],
projectCode: [
{ required: true, message: '请选择所属项目', trigger: 'change' }
]
};
return crules;
},
title() {
return '创建项目设备';
}
},
mounted() {
},
methods: {
show(data) {
this.dialogVisible = true;
},
doSave() {
const self = this;
this.$refs.dataform.validateForm(() => {
const params = {
code: this.formModel.code,
type: this.formModel.type,
projectCode: this.formModel.projectCode
};
deviceIsExist(params.projectCode, params.code).then(response => {
if (!response.data) {
createDevice(params).then(response => {
self.$message.success('创建项目设备成功!');
self.handleClose();
self.$emit('reloadTable');
}).catch(error => {
self.$message.error(this.$t('error.addFailed') + error.message);
});
} else {
self.$message.error('已存在该设备编号,请修改设备编号后创建!');
}
});
});
},
handleClose(done) {
this.formModel = {
code: '',
type: '',
projectCode: ''
};
this.$refs.dataform.resetForm();
this.dialogVisible = false;
}
}
};
</script>