rt-sim-training-client/src/views/display/scriptRecord/addAction.vue

291 lines
13 KiB
Vue
Raw Normal View History

2019-07-26 13:32:43 +08:00
<template>
<div>
2019-08-16 09:25:12 +08:00
<el-form :model="modalData" ref="modalData" :rules="rules" label-width="100px" class="actionInfo" label-position="right">
<el-form-item label="主体角色" class="conditionVO" prop="actionVO.memberId">
<el-select v-model="modalData.actionVO.memberId" placeholder="请选择主体角色">
<el-option v-for="member in memberList" :key="member.id" :label="member.name" :value="member.id"></el-option>
2019-07-26 13:32:43 +08:00
</el-select>
</el-form-item>
<el-form-item label="完成时间" class="conditionVO">
2019-08-16 09:25:12 +08:00
<el-input-number v-model="modalData.actionVO.time " class="inputStyle" :min="0"></el-input-number>
</el-form-item>
<el-form-item label="动作类型" class="conditionVO" prop="actionVO.type">
<el-select v-model="modalData.actionVO.type " placeholder="请选择动作类型" @change="changeType">
<el-option v-for="actionType in actionTypeList" :key="actionType.label" :label="actionType.label" :value="actionType.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="目标角色" class="conditionVO" prop="actionVO.targetId" v-if="isConversitionAdd">
<el-select v-model="modalData.actionVO.targetId" placeholder="请选择目标角色">
<el-option v-for="member in memberList" :key="member.id" :label="member.name" :value="member.id"></el-option>
</el-select>
2019-07-26 13:32:43 +08:00
</el-form-item>
2019-08-16 09:25:12 +08:00
<el-form-item label="回复消息" class="conditionVO" prop="actionVO.reply" v-if="isConversitionAdd">
<el-input v-model="modalData.actionVO.reply" type="textarea" class="textareaStyle" rows="3"></el-input>
2019-07-26 13:32:43 +08:00
</el-form-item>
2019-08-16 09:25:12 +08:00
<el-form-item label="设备指令" class="conditionVO" prop="actionVO.type" v-if="isCommandAdd">
<el-select v-model="modalData.actionVO.deviceCommand " placeholder="请选择设备指令" @change="changeCommand" class="inputStyle">
2019-08-08 10:31:46 +08:00
<el-option v-for="deviceCommand in deviceCommandList" :key="deviceCommand.deviceCommand" :label="deviceCommand.label" :value="deviceCommand.deviceCommand"></el-option>
</el-select>
</el-form-item>
<el-form-item label="起始站台" class="conditionVO" v-if="isJinLu" prop="param.startStation">
<el-select v-model="modalData.param.startStation " placeholder="请选择起始站台" class="inputStyle">
<el-option v-for="station in stationList" :key="station.code" :label="station.name" :value="station.code"></el-option>
</el-select>
</el-form-item>
<el-form-item label="终点站台" class="conditionVO" v-if="isJinLu" prop="param.endStation">
<el-select v-model="modalData.param.endStation " placeholder="请选择终点站台" class="inputStyle">
<el-option v-for="station in stationList" :key="station.code" :label="station.name" :value="station.code"></el-option>
</el-select>
</el-form-item>
2019-07-26 13:32:43 +08:00
<el-form-item>
2019-08-16 09:25:12 +08:00
<el-button type="primary" @click="addScriptActionInfo('modalData')">{{buttonName}}</el-button>
2019-07-26 13:32:43 +08:00
</el-form-item>
</el-form>
</div>
</template>
<script>
import Vue from 'vue';
2019-08-08 10:31:46 +08:00
import DeviceTypeDic from '@/scripts/DeviceTypeDic';
// import CommandForm from "./commandForm";
2019-08-16 09:25:12 +08:00
import {addScriptAction,modifyScriptAction,getAvailableDeviceCommand,getDeviceCodeByDeviceType,getScriptMemberData} from '@/api/simulation';
2019-07-26 13:32:43 +08:00
export default {
name: 'addAction',
props: {
group: {
type: String,
required: true
},
2019-08-08 10:31:46 +08:00
buttonName:{
type:String,
required: true
},
operateType:{
type:String,
required: true
2019-07-26 13:32:43 +08:00
}
},
2019-08-08 10:31:46 +08:00
// components:{
// CommandForm,
// },
2019-07-26 13:32:43 +08:00
data() {
return {
2019-08-08 10:31:46 +08:00
modalData:{
2019-08-16 09:25:12 +08:00
actionVO:{
memberId:"",
targetId:"",
2019-08-08 10:31:46 +08:00
time:0,
2019-08-16 09:25:12 +08:00
reply:"",
2019-08-08 10:31:46 +08:00
type:"Conversation",
2019-08-16 09:25:12 +08:00
// deviceCommand:"",
2019-08-08 10:31:46 +08:00
commandParamList:[]
},
param:{
startStation:"",
endStation:"",
2019-08-16 09:25:12 +08:00
}
2019-07-26 13:32:43 +08:00
},
2019-08-08 10:31:46 +08:00
isConversitionAdd:true,
isCommandAdd:false,
2019-08-16 09:25:12 +08:00
actionTypeList:DeviceTypeDic.ConstSelect.actionType,
isJinLu:false,
2019-08-08 10:31:46 +08:00
stationList:[],
2019-08-16 09:25:12 +08:00
memberList:[],
deviceCommandList:[],
2019-07-26 13:32:43 +08:00
rules:{
2019-08-16 09:25:12 +08:00
actionVO:{
memberId:[
{ required: true, message: '请选择主体角色', trigger: 'change' }
2019-08-08 10:31:46 +08:00
],
2019-08-16 09:25:12 +08:00
reply:[
{ required: true, message: '请输入回复消息', trigger: 'blur' }
2019-08-08 10:31:46 +08:00
],
2019-08-16 09:25:12 +08:00
targetId:[
{ required: true, message: '请选择目标角色', trigger: 'change' }
2019-08-08 10:31:46 +08:00
]
},
param:{
startStation:[
{ required: true, message: '请选择起始站台', trigger: 'change' }
],
endStation:[
{ required: true, message: '请选择终点站台', trigger: 'change' }
]
}
2019-08-16 09:25:12 +08:00
}
2019-07-26 13:32:43 +08:00
}
},
2019-08-08 10:31:46 +08:00
mounted(){
this.initData();
},
2019-07-26 13:32:43 +08:00
methods:{
2019-08-16 09:25:12 +08:00
initData(){
getScriptMemberData(this.group).then(resp => {
this.memberList=resp.data;
getAvailableDeviceCommand().then(response=>{
this.deviceCommandList=response.data;
this.getDeviceCode();
});
}).catch(error => {})
},
getDeviceCode(){
let params = {deviceType:"StationStand"};
let group=this.group;
getDeviceCodeByDeviceType(group,params).then(response =>{
// debugger;
let resultData=response.data;
resultData=JSON.parse(JSON.stringify(response.data).replace(/groupNumber/g,"name"));
this.stationList=resultData;
})
},
addScriptActionInfo(formName){
2019-07-26 13:32:43 +08:00
this.$refs[formName].validate((valid) => {
if (valid) {
2019-08-16 09:25:12 +08:00
let group=this.group;
if(this.modalData.actionVO.deviceCommand==""){
delete this.modalData.actionVO.deviceCommand;
2019-08-08 10:31:46 +08:00
}
2019-08-16 09:25:12 +08:00
if(this.modalData.actionVO.deviceCommand=="Train_Manual_Route_Blocking_Drive")
{this.modalData.actionVO.commandParamList=[this.modalData.param.startStation,this.modalData.param.endStation];}
let data=this.modalData.actionVO;
2019-08-08 10:31:46 +08:00
let obj=this;
2019-08-16 09:25:12 +08:00
if(this.$props.operateType=="add")
{
addScriptAction(group,data).then(response=>{
this.initActionData();
this.$message.success('添加动作成功');
2019-08-08 10:31:46 +08:00
this.$emit('create');
2019-07-26 13:32:43 +08:00
}).catch(error => {
2019-08-16 09:25:12 +08:00
this.$messageBox(`添加动作失败: ${error.message}`);
2019-08-08 10:31:46 +08:00
});
2019-08-16 09:25:12 +08:00
}
else
{
let actionId=this.modalData.actionVO.id;
modifyScriptAction(group,actionId,data).then(response=>{
this.initActionData();
this.$emit('modifyButtonName');
this.$message.success('修改动作成功');
this.$emit('create');
}).catch(error => {
this.$messageBox(`修改动作失败: ${error.message}`);
});
}
2019-07-26 13:32:43 +08:00
}
else {
console.log('error submit!!');
return false;
}
});
},
2019-08-16 09:25:12 +08:00
initActionData(){
this.modalData.actionVO.memberId="";
this.modalData.actionVO.targetId="";
this.modalData.actionVO.type="Conversation";
this.modalData.actionVO.time=0;
this.modalData.actionVO.reply="";
this.modalData.param.startStation="";
this.isConversitionAdd=true;
this.isCommandAdd=false;
this.isJinLu=false;
this.modalData.actionVO.deviceCommand=null;
this.modalData.param.endStation="";
2019-08-08 10:31:46 +08:00
},
changeType(index){
switch(index)
{
case "Conversation":{
this.isConversitionAdd=true;
this.isCommandAdd=false;
2019-08-16 09:25:12 +08:00
this.isJinLu=false;
2019-08-08 10:31:46 +08:00
break;
}
case "Command":{
this.isConversitionAdd=false;
this.isCommandAdd=true;
2019-08-16 09:25:12 +08:00
//
if(this.modalData.actionVO.deviceCommand=="Train_Manual_Route_Blocking_Drive")
{
this.isJinLu=true;
}
else
{
this.isJinLu=false;
}
2019-08-08 10:31:46 +08:00
break;
}
default:{
break;
}
}
},
2019-08-16 09:25:12 +08:00
changeCommand(index){
switch(index)
{
case "Train_Manual_Route_Blocking_Drive":{
this.isJinLu=true;
this.getDeviceCode();
break;
}
default:{
this.isJinLu=false;
break;
}
}
},
2019-08-08 10:31:46 +08:00
doShow(data){
if(data)
{
2019-08-16 09:25:12 +08:00
// debugger;
this.initData();
this.modalData.actionVO.id=data.id;
this.modalData.actionVO.memberId=data.memberId;
this.modalData.actionVO.type=data.type;
this.modalData.actionVO.time=data.time;
if(data.type=="Conversation")
2019-08-08 10:31:46 +08:00
{
2019-08-16 09:25:12 +08:00
this.modalData.actionVO.targetId=data.targetId;
this.isConversitionAdd=true;
this.isCommandAdd=false;
this.modalData.actionVO.reply=data.reply;
}
else if(data.type=="Command")
{
this.isConversitionAdd=false;
this.isCommandAdd=true;
this.modalData.actionVO.reply="";
this.modalData.actionVO.deviceCommand=data.deviceCommand;
if(this.modalData.actionVO.deviceCommand=="Train_Manual_Route_Blocking_Drive")
{
this.isJinLu=true;
this.modalData.param.startStation=data.commandParamList[0];
this.modalData.param.endStation=data.commandParamList[1];
}
2019-08-08 10:31:46 +08:00
}
}
2019-07-26 13:32:43 +08:00
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.addAction{
margin-top: 20px;
margin-left: 5px;
font-size: 15px;
}
.actionInfo{
2019-08-09 17:26:33 +08:00
margin-top:20px;
2019-07-26 13:32:43 +08:00
margin-left: 5px;
font-size: 15px;
width:98%;
}
.inputStyle{
2019-08-08 10:31:46 +08:00
width:300px;
2019-07-26 13:32:43 +08:00
height:30px;
}
2019-08-08 10:31:46 +08:00
.textareaStyle{
width:300px;
}
2019-07-26 13:32:43 +08:00
</style>