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

220 lines
7.0 KiB
Vue
Raw Normal View History

2019-11-15 16:31:48 +08:00
<template>
2019-11-18 14:29:43 +08:00
<div class="dictionary_box">
<div class="joylink-card">
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
<div style="overflow: hidden;">
<div class="param-title">指令参数:</div>
<el-table :data="formModel.paramList" border class="param-table">
<el-table-column prop="name" label="参数名" />
<el-table-column :label="this.$t('global.operate')" width="180">
<template slot-scope="scope">
<el-button type="text" size="small" @click="editParam(scope.$index, scope.row)">修改</el-button>
<el-button type="text" size="small" @click="delParam(scope.$index)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="button-box">
<el-button type="primary" size="small" round @click="addParam">添加</el-button>
</div>
</div>
</div>
<div class="dialog-footer">
2019-11-15 16:31:48 +08:00
<el-button type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
2019-11-18 14:29:43 +08:00
<el-button @click="back">返回</el-button>
</div>
<command-edit ref="create" type="ADD" @addData="addData" />
<command-edit ref="edit" type="EDIT" @editData="editData" />
</div>
2019-11-15 16:31:48 +08:00
</template>
<script>
2019-11-18 14:29:43 +08:00
import { createCommand, editCommand, getCommandDetail } from '@/api/management/dictionary';
import CommandEdit from './editParam';
import { getLineCodeList } from '@/api/management/mapline';
2019-11-15 16:31:48 +08:00
export default {
name: 'DictionaryEdit',
2019-11-18 14:29:43 +08:00
components: {
CommandEdit
},
2019-11-15 16:31:48 +08:00
props: {
},
data() {
return {
2019-11-18 14:29:43 +08:00
taskStatusList: [],
deviceTypeList: [
{ label: '区段', value: 'section' },
{ label: '道岔', value: 'switch' },
{ label: '信号机', value: 'signal' },
{ label: '站台', value: 'station' },
{ label: '控制模式', value: 'stationConter' },
{ label: '临时全线限速', value: 'limitConter' }
],
type: 'add',
editIndex: 0,
2019-11-15 16:31:48 +08:00
formModel: {
2019-11-18 14:29:43 +08:00
id: '',
simulationRole: '',
controlMode: '',
lineCode: '',
operateObject: '',
operate: '',
paramList: []
2019-11-15 16:31:48 +08:00
}
};
},
computed: {
form() {
const form = {
labelWidth: '120px',
items: [
2019-11-18 14:29:43 +08:00
{ prop: 'simulationRole', label: this.$t('system.simulationRole'), type: 'select', options: this.$ConstSelect.simulationRole },
{ prop: 'controlMode', label: this.$t('system.controlMode'), type: 'select', options: this.$ConstSelect.controlMode },
{ prop: 'lineCode', label: this.$t('system.lineCode'), type: 'select', options: this.taskStatusList },
{ prop: 'operateObject', label: this.$t('system.deviceType'), type: 'select', options: this.deviceTypeList, change: true, onChange: this.deviceChange },
{ prop: 'operate', label: this.$t('system.instructionType'), type: 'text' }
2019-11-15 16:31:48 +08:00
]
};
return form;
},
rules() {
return {
controlMode: [
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
],
2019-11-18 14:29:43 +08:00
operateObject: [
2019-11-15 16:31:48 +08:00
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
],
lineCode: [
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
],
2019-11-18 14:29:43 +08:00
simulationRole: [
2019-11-15 16:31:48 +08:00
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
],
2019-11-18 14:29:43 +08:00
operate: [
2019-11-15 16:31:48 +08:00
{ required: true, message: this.$t('rules.pleaseSelectStatus'), trigger: 'change' }
]
};
}
},
2019-11-18 14:29:43 +08:00
mounted () {
this.loadInitData();
this.init();
},
2019-11-15 16:31:48 +08:00
methods: {
2019-11-18 14:29:43 +08:00
async loadInitData() {
try {
this.taskStatusList = [];
const list = await getLineCodeList();
list.data.forEach(elem => {
elem.value = elem.code;
elem.label = elem.name;
2019-11-15 16:31:48 +08:00
});
2019-11-18 14:29:43 +08:00
this.taskStatusList = list.data;
} catch (error) {
console.log(error);
2019-11-15 16:31:48 +08:00
}
},
2019-11-18 14:29:43 +08:00
init() {
this.type = this.$route.query.type;
if (this.$route.query.id) {
getCommandDetail(this.$route.query.id).then(res => {
this.formModel = res.data;
});
}
},
deviceChange(code) {
console.log(code);
},
2019-11-15 16:31:48 +08:00
doSave() {
this.$refs.dataform.validateForm(() => {
2019-11-18 14:29:43 +08:00
if (this.type == 'add') {
this.create();
2019-11-15 16:31:48 +08:00
} else {
2019-11-18 14:29:43 +08:00
this.update();
2019-11-15 16:31:48 +08:00
}
});
},
create() {
2019-11-18 14:29:43 +08:00
createCommand(this.formModel).then(response => {
this.$message.success(this.$t('system.createSuccess'));
this.handleBack();
2019-11-15 16:31:48 +08:00
}).catch(error => {
2019-11-18 14:29:43 +08:00
console.log(error);
this.$message.error('创建指令失败');
2019-11-15 16:31:48 +08:00
});
},
update() {
2019-11-18 14:29:43 +08:00
editCommand(this.formModel).then(response => {
this.$message.success(this.$t('system.updateSuccess'));
this.handleBack();
2019-11-15 16:31:48 +08:00
}).catch(error => {
2019-11-18 14:29:43 +08:00
console.log(error);
this.$message.error('更新指令失败');
2019-11-15 16:31:48 +08:00
});
},
2019-11-18 14:29:43 +08:00
handleBack() {
this.$router.push({ path: `/system/commands`, query: { } });
},
back() {
this.$router.go(-1);
},
editData(data) {
this.formModel.paramList.splice(this.editIndex, 1, data);
},
addData(data) {
this.formModel.paramList.push(data);
},
addParam() {
this.$refs.create.doShow();
},
editParam(index, row) {
this.$refs.edit.doShow(row);
this.editIndex = index;
},
delParam(index) {
this.formModel.paramList.splice(index, 1);
2019-11-15 16:31:48 +08:00
}
}
};
</script>
2019-11-18 14:29:43 +08:00
<style rel="stylesheet/scss" lang="scss" scoped>
.dictionary_box{
margin: 40px auto 20px;
width: 800px;
.joylink-card{
padding: 24px;
.param-title{
width: 120px;
text-align: right;
float: left;
font-size: 14px;
color: #606266;
line-height: 40px;
padding: 0 12px 0 0;
box-sizing: border-box;
font-weight: 700;
}
.param-table{
width: calc(100% - 190px);
min-height: 200px;
float: left;
}
.button-box{
float: left;
margin-left: 10px;
}
}
.dialog-footer{
margin: 20px auto;
display: flex;
justify-content: center;
}
}
</style>