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" />
|
2019-11-19 13:00:36 +08:00
|
|
|
<div style="overflow: hidden; margin-bottom: 20px;">
|
|
|
|
<div class="param-title">条件参数:</div>
|
|
|
|
<el-table :data="formModel.conditionList" border class="param-table">
|
|
|
|
<el-table-column prop="name" label="参数名" />
|
|
|
|
<el-table-column prop="value" label="参数值" />
|
|
|
|
<el-table-column :label="this.$t('global.operate')" width="180">
|
|
|
|
<template slot-scope="scope">
|
|
|
|
<el-button type="text" size="small" @click="editConditionData(scope.$index, scope.row)">修改</el-button>
|
|
|
|
<el-button type="text" size="small" @click="delCondition(scope.$index)">删除</el-button>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
|
|
|
<div class="button-box">
|
|
|
|
<el-button type="primary" size="small" round @click="addConditionData">添加</el-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-11-18 14:29:43 +08:00
|
|
|
<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-19 13:00:36 +08:00
|
|
|
<el-button @click="handleBack">返回</el-button>
|
2019-11-18 14:29:43 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<command-edit ref="create" type="ADD" @addData="addData" />
|
|
|
|
<command-edit ref="edit" type="EDIT" @editData="editData" />
|
2019-11-19 13:00:36 +08:00
|
|
|
<edit-condition ref="addCondition" type="ADD" @addData="addCondition" />
|
|
|
|
<edit-condition ref="editCondition" type="EDIT" @editData="editCondition" />
|
2019-11-18 14:29:43 +08:00
|
|
|
</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-19 13:00:36 +08:00
|
|
|
import EditCondition from './editCondition';
|
|
|
|
import Commands from '@/scripts/plugin/Commands';
|
2019-11-15 16:31:48 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DictionaryEdit',
|
2019-11-18 14:29:43 +08:00
|
|
|
components: {
|
2019-11-19 13:00:36 +08:00
|
|
|
CommandEdit,
|
|
|
|
EditCondition
|
2019-11-18 14:29:43 +08:00
|
|
|
},
|
2019-11-15 16:31:48 +08:00
|
|
|
props: {
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-11-18 14:29:43 +08:00
|
|
|
taskStatusList: [],
|
2019-11-19 13:00:36 +08:00
|
|
|
deviceTypeList: [],
|
|
|
|
operateList: [],
|
2019-11-18 14:29:43 +08:00
|
|
|
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: '',
|
2019-11-19 13:00:36 +08:00
|
|
|
paramList: [],
|
|
|
|
conditionList: []
|
2019-11-15 16:31:48 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
form() {
|
|
|
|
const form = {
|
|
|
|
labelWidth: '120px',
|
|
|
|
items: [
|
2019-11-19 13:00:36 +08:00
|
|
|
{ prop: 'lineCode', label: this.$t('system.lineCode'), type: 'select', options: this.taskStatusList },
|
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 },
|
2019-11-19 13:00:36 +08:00
|
|
|
{ prop: 'operateObject', label: this.$t('system.deviceType'), type: 'select', options: this.$ConstSelect.deviceTypeList, change: true, onChange: this.deviceChange },
|
|
|
|
{ prop: 'operate', label: this.$t('system.instructionType'), type: 'select', options: this.operateList }
|
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;
|
2019-11-19 13:00:36 +08:00
|
|
|
this.operateList = Object.values(Commands[this.formModel.operateObject]);
|
2019-11-18 14:29:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2019-11-19 13:00:36 +08:00
|
|
|
deviceChange(code) { // 操作对象变化
|
|
|
|
this.operateList = Object.values(Commands[code]);
|
2019-11-18 14:29:43 +08:00
|
|
|
},
|
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: { } });
|
|
|
|
},
|
|
|
|
|
|
|
|
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-19 13:00:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
editConditionData(index, row) {
|
|
|
|
this.$refs.editCondition.doShow(row);
|
|
|
|
this.editIndex = index;
|
|
|
|
},
|
|
|
|
addConditionData() {
|
|
|
|
this.$refs.addCondition.doShow();
|
|
|
|
},
|
|
|
|
addCondition(Condition) {
|
|
|
|
this.formModel.conditionList.push(Condition);
|
|
|
|
},
|
|
|
|
editCondition(Condition) {
|
|
|
|
this.formModel.conditionList.splice(this.editIndex, 1, Condition);
|
|
|
|
},
|
|
|
|
delCondition(index) {
|
|
|
|
this.formModel.conditionList.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>
|