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: [
|
2020-01-06 11:25:07 +08:00
|
|
|
{ prop: 'code', label: this.$t('system.deviceCode'), type: 'text', required: true, placeholder: this.$t('rules.enterDeviceCode') },
|
|
|
|
{ prop: 'type', label: this.$t('system.deviceType1'), type: 'select', required: true, options: this.deviceTypeList, placeholder: this.$t('rules.selectDeviceType') },
|
|
|
|
{ prop: 'projectCode', label: this.$t('system.belongProject'), type: 'select', required: true, options: this.projectList, placeholder: this.$t('rules.selectBelongProject')}
|
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
|
|
|
],
|
|
|
|
projectCode: [
|
2020-01-06 11:25:07 +08:00
|
|
|
{ required: true, message: this.$t('rules.selectBelongProject'), 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;
|
|
|
|
},
|
|
|
|
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 => {
|
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-01-06 11:25:07 +08:00
|
|
|
self.$message.error(this.$t('tip.deviceCodeTip'));
|
2020-01-02 17:01:11 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleClose(done) {
|
|
|
|
this.formModel = {
|
|
|
|
code: '',
|
|
|
|
type: '',
|
|
|
|
projectCode: ''
|
|
|
|
};
|
|
|
|
this.$refs.dataform.resetForm();
|
|
|
|
this.dialogVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|