rt-sim-training-client/src/views/lesson/trainingRule/addEdit.vue

316 lines
13 KiB
Vue
Raw Normal View History

2019-07-26 13:32:43 +08:00
<template>
<el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" center>
2019-08-08 15:57:36 +08:00
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
<span slot="footer" class="dialog-footer">
2019-08-29 17:16:33 +08:00
<el-button v-loading="loading" type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
<el-button @click="handleClose">{{ $t('global.cancel') }}</el-button>
2019-08-08 15:57:36 +08:00
</span>
</el-dialog>
2019-07-26 13:32:43 +08:00
</template>
<script>
2019-08-08 15:57:36 +08:00
import { postTrainingRulesData, putTrainingRulesData, getPlaceholderList } from '@/api/management/operation';
2019-11-08 16:22:05 +08:00
import { getPublishMapListOnline } from '@/api/jmap/map';
2019-07-26 13:32:43 +08:00
2019-08-08 15:57:36 +08:00
export default {
2019-10-29 13:15:57 +08:00
name: 'TrainingEdit',
props: {
type: {
type: String,
required: true
}
},
data() {
return {
loading: false,
dialogVisible: false,
formModel: {
trainingName: '',
trainingType: '',
operateType: '',
2019-10-30 19:36:29 +08:00
mapId: '',
2019-10-29 13:15:57 +08:00
minDuration: '',
maxDuration: '',
trainingRemark: '',
productTypes: []
},
2019-10-30 19:36:29 +08:00
mapIdList: [],
2019-10-29 13:15:57 +08:00
trainingTypeList: [],
trainingOperateTypeMap: {},
2019-10-31 11:03:19 +08:00
placeholderList: [],
productTypesList:[]
2019-10-29 13:15:57 +08:00
};
},
computed: {
form() {
const isAdd = this.type === 'ADD';
const form = {
labelWidth: '120px',
items: [
2019-10-30 19:36:29 +08:00
{ prop: 'mapId', label: this.$t('lesson.mapName'), type: 'select', required: true, options: this.mapIdList, disabled: true },
2019-10-29 13:15:57 +08:00
{ prop: 'trainingType', label: this.$t('lesson.trainingType'), type: 'select', required: true, options: this.trainingTypeList, disabled: !isAdd, change: true, onChange: this.changeList },
{ prop: 'operateType', label: this.$t('lesson.operationType'), type: 'select', required: true, options: this.trainingOperateTypeMap[this.formModel.trainingType], disabled: !isAdd },
2019-10-31 11:03:19 +08:00
{ prop: 'productTypes', label: this.$t('lesson.productType'), type: 'select', multiple: true, required: true, options: this.productTypesList, disabled: !isAdd},
2019-10-29 13:15:57 +08:00
{ label: '', type: 'button', options: this.placeholderList, style: 'margin-bottom: 0; margin-top: -10px;', typeBtn: 'info', click: this.addTrainName },
{ prop: 'trainingName', label: this.$t('lesson.trainingName'), type: 'text', required: true, rightWidth: true, tooltip: true, info: this.$t('lesson.tipNamePlaceholderInfo') },
2019-10-30 19:36:29 +08:00
{ prop: 'minDuration', label: this.$t('lesson.minDuration'), type: 'number', required: true, min:1},
{ prop: 'maxDuration', label: this.$t('lesson.maxDuration'), type: 'number', required: true, min:1},
2019-10-29 13:15:57 +08:00
{ label: '', type: 'button', options: this.placeholderList, style: 'margin-bottom: 0; margin-top: -10px;', typeBtn: 'info', click: this.addTrainRemark },
{ prop: 'trainingRemark', label: this.$t('lesson.trainingRemark'), type: 'textarea', required: true, tooltip: true, info: this.$t('lesson.tipExplainPlaceholderInfo') }
2019-10-31 11:03:19 +08:00
2019-10-29 13:15:57 +08:00
]
};
return form;
},
rules() {
const crules = {
trainingName: [
{ required: true, message: this.$t('rules.inputTrainingName'), trigger: 'blur' }
],
trainingType: [
{ required: true, message: this.$t('rules.inputTrainingType'), trigger: 'change' }
],
operateType: [
{ required: true, message: this.$t('rules.inputOperationType'), trigger: 'change' }
],
2019-10-31 11:03:19 +08:00
productTypes:[
{ required: true, message: this.$t('rules.productTypeInput'), trigger: 'change' }
],
2019-10-30 19:36:29 +08:00
mapId: [
{ required: true, message: this.$t('rules.selectMapName'), trigger: 'change' }
2019-10-29 13:15:57 +08:00
],
minDuration: [
{ required: true, message: this.$t('rules.inputMinDuration'), trigger: 'blur' }
],
maxDuration: [
{ required: true, message: this.$t('rules.inputMaxDuration'), trigger: 'blur' }
],
trainingRemark: [
{ required: true, max: 500, message: this.$t('rules.inputTrainingRemark'), trigger: 'blur' }
]
};
return crules;
},
title() {
if (this.type === 'ADD') {
return this.$t('lesson.createOperateRule');
} else {
return this.$t('lesson.editOperateRule');
}
}
},
2019-10-31 11:03:19 +08:00
created() {
2019-10-29 13:15:57 +08:00
this.init();
},
2019-10-31 11:03:19 +08:00
// beforeupdate(data) {
// this.$refs.dataform.clearValidate();
// },
2019-10-29 13:15:57 +08:00
methods: {
init() {
2019-10-30 19:36:29 +08:00
// 获取地图列表
2019-10-31 11:03:19 +08:00
// this.$refs.dataform.resetForm();
2019-10-30 19:36:29 +08:00
this.mapIdList = [];
2019-10-31 11:03:19 +08:00
this.productTypesList = [{ value:'01', label:'现地'}, {value:'02', label:'行调'}];
2019-11-08 16:22:05 +08:00
getPublishMapListOnline().then(response => {
2019-10-30 19:36:29 +08:00
this.mapIdList = response.data.map(item => {
2019-10-29 13:15:57 +08:00
const params = {};
params.label = item.name;
2019-10-30 19:36:29 +08:00
params.value = item.id;
2019-10-29 13:15:57 +08:00
return params;
});
});
2019-07-26 13:32:43 +08:00
2019-10-29 13:15:57 +08:00
// 获取实训类型
this.trainingTypeList = [];
this.$Dictionary.trainingType().then(list => {
this.trainingTypeList = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
});
});
// 获取实训操作类型
this.trainingOperateTypeMap = {};
this.$Dictionary.stationControl().then(list => {
this.trainingOperateTypeMap['01'] = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
}); // 控制权实训
});
this.$Dictionary.signalOperation().then(list => {
this.trainingOperateTypeMap['02'] = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
}); // 信号机实训
});
this.$Dictionary.switchOperation().then(list => {
this.trainingOperateTypeMap['03'] = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
}); // 道岔实训
});
this.$Dictionary.sectionOperation().then(list => {
this.trainingOperateTypeMap['04'] = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
}); // 区段实训
});
this.$Dictionary.stationStandOperation().then(list => {
this.trainingOperateTypeMap['05'] = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
}); // 站台实训
});
this.$Dictionary.trainPlanOperation().then(list => {
this.trainingOperateTypeMap['06'] = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
}); // 行车计划实训
});
this.$Dictionary.trainOperation().then(list => {
this.trainingOperateTypeMap['07'] = list.map(item => {
const params = {};
params.label = item.name;
params.value = item.code;
return params;
}); // 列车实训
});
2019-07-26 13:32:43 +08:00
2019-10-29 13:15:57 +08:00
},
async show(data) {
this.loading = false;
this.dialogVisible = true;
if (data && data.id) {
// 获取操作占位列表
2019-10-30 19:36:29 +08:00
const res = await getPlaceholderList({ trainingType: data.trainingType });
2019-10-29 13:15:57 +08:00
this.placeholderList = res.data;
this.formModel = {
id: data.id,
trainingName: this.repliceName(data.trainingName, this.placeholderList),
trainingType: data.trainingType,
operateType: data.operateType,
productTypes: data.productTypes,
2019-10-30 19:36:29 +08:00
mapId: data.mapId,
2019-10-29 13:15:57 +08:00
minDuration: data.minDuration,
maxDuration: data.maxDuration,
trainingRemark: this.repliceName(data.trainingRemark, this.placeholderList)
};
} else {
2019-10-31 11:03:19 +08:00
this.formModel.mapId = this.$route.query.mapId;
// this.formModel = {
// mapId: this.$route.query.mapId
// };
2019-10-29 13:15:57 +08:00
}
},
repliceName(fieldValue, enumList) {
if (enumList && enumList.length > 0) {
for (let i = 0; i < enumList.length; i++) {
if (fieldValue.includes(`{${enumList[i].id}}`)) {
fieldValue = fieldValue.replace(`{${enumList[i].id}}`, `{${enumList[i].name}}`);
}
2019-10-10 09:33:56 +08:00
}
2019-10-29 13:15:57 +08:00
return fieldValue;
2019-10-10 09:33:56 +08:00
}
2019-10-29 13:15:57 +08:00
},
changeList(val) {
// 获取操作占位列表
2019-10-30 19:36:29 +08:00
getPlaceholderList({ trainingType: val}).then(res => {
2019-10-29 13:15:57 +08:00
this.placeholderList = res.data;
});
},
addTrainName(val) {
this.formModel.trainingName = `${this.formModel.trainingName}{${val.name}}`;
},
addTrainRemark(val) {
this.formModel.trainingRemark = `${this.formModel.trainingRemark}{${val.name}}`;
},
doSave() {
const self = this;
this.$refs.dataform.validateForm(() => {
if (self.type === 'ADD') {
self.create();
} else {
self.update();
}
});
},
create() {
const self = this;
2019-10-31 13:56:42 +08:00
this.loading = true;
2019-10-29 13:15:57 +08:00
this.placeholderList.forEach(item => {
if (this.formModel.trainingName.includes(`{${item.name}}`)) {
const name = this.formModel.trainingName.replace(`{${item.name}}`, `{${item.id}}`);
this.formModel.trainingName = name;
}
if (this.formModel.trainingRemark.includes(`{${item.name}}`)) {
const remark = this.formModel.trainingRemark.replace(`{${item.name}}`, `{${item.id}}`);
this.formModel.trainingRemark = remark;
}
});
2019-07-26 13:32:43 +08:00
2019-10-29 13:15:57 +08:00
postTrainingRulesData(this.formModel).then(response => {
self.loading = false;
self.$message.success(this.$t('lesson.createOperateSuccess'));
self.handleClose();
self.$emit('reloadTable');
}).catch(error => {
self.loading = false;
self.$message.error(`${this.$t('error.createOperateRuleFailed')}:${error.message}`);
});
},
update() {
const self = this;
this.placeholderList.forEach(item => {
if (this.formModel.trainingName.includes(`{${item.name}}`)) {
const name = this.formModel.trainingName.replace(`{${item.name}}`, `{${item.id}}`);
this.formModel.trainingName = name;
}
if (this.formModel.trainingRemark.includes(`{${item.name}}`)) {
const remark = this.formModel.trainingRemark.replace(`{${item.name}}`, `{${item.id}}`);
this.formModel.trainingRemark = remark;
}
});
2019-07-26 13:32:43 +08:00
2019-10-29 13:15:57 +08:00
this.loading = true;
putTrainingRulesData(this.formModel).then(response => {
self.loading = false;
2019-10-30 19:36:29 +08:00
self.$message.success(this.$t('lesson.updateOperateSuccess'));
2019-10-29 13:15:57 +08:00
self.handleClose();
self.$emit('reloadTable');
}).catch(error => {
self.loading = false;
2019-10-30 19:36:29 +08:00
self.$message.error(`${this.$t('error.updateOperateRuleFailed')}:${error.message}`);
2019-10-29 13:15:57 +08:00
});
},
handleClose() {
this.formModel = {
trainingName: '',
trainingType: '',
operateType: '',
2019-10-30 19:36:29 +08:00
mapId: '',
2019-10-29 13:15:57 +08:00
minDuration: '',
maxDuration: '',
2019-10-31 11:03:19 +08:00
trainingRemark: '',
productTypes:[]
2019-10-29 13:15:57 +08:00
};
this.$refs.dataform.resetForm();
2019-10-31 11:03:19 +08:00
// this.$refs.dataform.clearValidate();
2019-10-29 13:15:57 +08:00
this.dialogVisible = false;
}
}
2019-08-08 15:57:36 +08:00
};
</script>