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

106 lines
3.5 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';
2020-07-07 16:30:06 +08:00
import ConstConfig from '@/scripts/ConstConfig';
2020-01-02 17:01:11 +08:00
export default {
name: 'DeviceAdd',
props: {
2020-06-19 18:02:50 +08:00
projectCode: {
type: String,
required: true
}
2020-01-02 17:01:11 +08:00
},
data() {
return {
dialogVisible: false,
formModel: {
code: '',
type: '',
projectCode: ''
},
LessonList: [],
UserList: [],
UserLoading: false,
2020-07-07 16:30:06 +08:00
deviceTypeList:ConstConfig.ConstSelect.projectDeviceTypeList,
2020-01-02 17:01:11 +08:00
gatewayList: []
};
},
computed: {
form() {
const form = {
labelWidth: '120px',
items: [
2020-01-06 11:25:07 +08:00
{ prop: 'code', label: this.$t('system.deviceCode'), type: 'text', required: true, placeholder: this.$t('rules.enterDeviceCode') },
2020-07-09 10:25:04 +08:00
{ prop: 'type', label: this.$t('system.deviceType1'), type: 'select', required: true, options: this.deviceTypeList, placeholder: this.$t('rules.selectDeviceType') }
2020-01-02 17:01:11 +08:00
]
};
return form;
},
rules() {
const crules = {
code: [
2020-01-06 11:25:07 +08:00
{ required: true, message: this.$t('rules.enterDeviceCode'), trigger: 'blur' }
2020-01-02 17:01:11 +08:00
],
type: [
2020-01-06 11:25:07 +08:00
{ required: true, message: this.$t('rules.selectDeviceType'), trigger: 'change' }
2020-01-02 17:01:11 +08:00
]
};
return crules;
},
title() {
2020-01-06 11:25:07 +08:00
return this.$t('system.createProjectDevice');
2020-01-02 17:01:11 +08:00
}
},
mounted() {
},
methods: {
show(data) {
this.dialogVisible = true;
2020-06-19 18:02:50 +08:00
this.formModel.projectCode = this.projectCode;
2020-01-02 17:01:11 +08:00
},
doSave() {
const self = this;
this.$refs.dataform.validateForm(() => {
const params = {
code: this.formModel.code,
type: this.formModel.type,
projectCode: this.formModel.projectCode
};
2020-06-19 18:02:50 +08:00
deviceIsExist(params.code).then(response => {
2020-01-02 17:01:11 +08:00
if (!response.data) {
createDevice(params).then(response => {
2020-01-06 11:25:07 +08:00
self.$message.success(this.$t('tip.createProjectDeviceSuccessfully'));
2020-01-02 17:01:11 +08:00
self.handleClose();
self.$emit('reloadTable');
}).catch(error => {
self.$message.error(this.$t('error.addFailed') + error.message);
});
} else {
2020-06-19 18:02:50 +08:00
self.$message.error('项目设备编号已存在!');
2020-01-02 17:01:11 +08:00
}
});
});
},
handleClose(done) {
this.formModel = {
code: '',
type: '',
projectCode: ''
};
this.$refs.dataform.resetForm();
this.dialogVisible = false;
}
}
};
</script>