rt-sim-training-client/src/views/scriptManage/allScriptRole.vue

187 lines
6.1 KiB
Vue
Raw Normal View History

2020-08-17 18:47:38 +08:00
<template>
<div style="width:95%;height:100%">
<div>
<el-input v-model="queryMember" placeholder="请输入搜索人员" style="width:300px">
<el-button slot="append" icon="el-icon-search" />
</el-input>
<el-button @click="addMember">添加仿真成员</el-button>
</div>
<el-tree
ref="tree"
2020-10-29 10:45:35 +08:00
v-loading="loading"
2020-09-01 18:27:36 +08:00
:data="treeData"
2020-08-17 18:47:38 +08:00
:props="defaultProps"
node-key="id"
default-expand-all
:filter-node-method="filterNode"
style="margin: 10px;overflow-y:auto;height:255px;margin-right: 0;"
>
<span :id="data.id" slot-scope="{ node, data }" style="width:100%">
2020-09-01 18:27:36 +08:00
<span v-if="data.children">
2020-10-29 11:18:47 +08:00
<span style="font-size: 14px">{{ node.label }}</span>
2020-08-17 18:47:38 +08:00
</span>
2020-09-01 18:27:36 +08:00
<span v-else>
<span style="font-size: 14px">{{ data.normalName }}</span>
<span v-if="data.type!='role'" class="setGroup">
<span v-if="!data.disabled" class="settingBtn" @click="changeRole(data)">设置</span>
<span v-else class="hasSetted">已设置</span>
</span>
</span>
2020-08-17 18:47:38 +08:00
</span>
</el-tree>
</div>
</template>
<script>
import { getToken } from '@/utils/auth';
import {changeScriptRole} from '@/api/script';
export default {
name:'AllScriptRole',
props:{
2020-09-01 18:27:36 +08:00
treeData:{
2020-08-17 18:47:38 +08:00
type: Array,
default() {
return [];
}
},
memberId:{
type: String,
default() {
return '';
}
},
group: {
type: String,
required: true
}
},
data() {
return {
covertMemberList:[],
driverList:[],
2020-09-01 18:27:36 +08:00
oldMember:{id:null, type:''},
2020-08-17 18:47:38 +08:00
queryMember:'',
2020-10-29 10:45:35 +08:00
loading:false,
2020-08-17 18:47:38 +08:00
defaultProps: {
children: 'children',
label: 'label'
}
};
},
watch:{
queryMember(val) {
if (this.$refs.tree) {
this.$refs.tree.filter(val);
}
2020-09-01 18:27:36 +08:00
},
'treeData':function(val) {
const roleName = this.$store.state.scriptRecord.userRole;
this.oldMember = {id:this.memberId, type:roleName};
2020-08-17 18:47:38 +08:00
}
},
methods:{
filterNode(value, data) {
return data.label.indexOf(value) !== -1;
},
changeRole(member) {
if (member) {
this.switchMode(member);
}
},
addMember() {
this.$emit('addMember');
},
2020-09-01 18:27:36 +08:00
switchMode(member) {
2020-10-29 10:45:35 +08:00
this.loading = true;
2020-09-01 18:27:36 +08:00
changeScriptRole(this.group, member.id).then(res=>{
2020-08-17 18:47:38 +08:00
let prdType = '';
if (this.openWindow) {
this.openWindow.close();
}
2020-09-01 18:27:36 +08:00
const role = Object.assign({}, member);
2020-08-17 18:47:38 +08:00
if (role.type == '行值') {
prdType = '01';
2020-09-01 18:27:36 +08:00
role.type = 'STATION_SUPERVISOR';
2020-08-17 18:47:38 +08:00
this.$store.dispatch('training/setRoles', 'STATION_SUPERVISOR');
this.$store.dispatch('training/setRoleDeviceCode', role.deviceCode);
} else if (role.type == '行调') {
prdType = '02';
2020-09-01 18:27:36 +08:00
role.type = 'DISPATCHER';
2020-08-17 18:47:38 +08:00
this.$store.dispatch('training/setRoles', 'DISPATCHER');
} else if (role.type == '司机') {
prdType = '04';
2020-09-01 18:27:36 +08:00
role.type = 'DRIVER';
2020-08-25 13:44:18 +08:00
this.$store.dispatch('training/setRoles', 'DRIVER');
2020-08-17 18:47:38 +08:00
} else if (role.type == '通号') {
prdType = '';
2020-09-01 18:27:36 +08:00
role.type = 'MAINTAINER';
2020-08-25 13:44:18 +08:00
this.$store.dispatch('training/setRoles', 'MAINTAINER');
2020-08-17 18:47:38 +08:00
const routeData = this.$router.resolve({
path:'/jlmap3d/maintainer',
query:{
mapid:this.$route.query.mapId,
group:this.group,
token:getToken(),
project: this.project,
noPreLogout: true
}
});
this.openWindow = window.open(routeData.href);
2020-10-13 13:06:17 +08:00
} else if (role.type == '车辆段调度') {
2020-09-01 18:27:36 +08:00
prdType = '05';
role.type = 'DEPOT_DISPATCHER';
this.$store.dispatch('training/setRoles', 'DEPOT_DISPATCHER');
2020-10-13 13:06:17 +08:00
} else if (role.type == '上级部门') {
prdType = '';
role.type = 'PARENT_DEPARTMENT';
this.$store.dispatch('training/setRoles', 'PARENT_DEPARTMENT');
2020-08-17 18:47:38 +08:00
} else {
prdType = '';
}
2020-10-29 11:18:47 +08:00
this.$store.dispatch('training/setPrdType', prdType);
this.$store.dispatch('scriptRecord/updateRole', role.type + ':' + role.id);
this.$emit('setMemberId', {newRole:role, oldRole:this.oldMember});
2020-08-17 18:47:38 +08:00
this.$store.dispatch('training/updateMemberListInScript',
{
2020-10-29 10:45:35 +08:00
oldMemberId:Object.assign({}, this.oldMember).id,
2020-08-17 19:11:59 +08:00
newMemberId:role.id,
2020-08-17 18:47:38 +08:00
userId:this.$store.state.user.id,
name:this.$store.state.user.nickname
}
);
2020-10-29 10:45:35 +08:00
this.oldMember = Object.assign({}, role);
this.loading = false;
2020-08-17 18:47:38 +08:00
this.$message('切换角色成功');
}).catch(()=>{
this.$messageBox('切换角色失败');
// this.$refs.changeScriptRole.blur();
});
}
}
};
</script>
<style scoped>
.setGroup{
font-size: 14px;
float: right;
margin-right: 15px;
}
.settingBtn{
color: #409eff;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
}
.hasSetted{
}
</style>
2020-10-29 11:18:47 +08:00
<style>
.eachScriptPanel .el-tree-node:focus>.el-tree-node__content {
background-color: #b7b7b7;
}
.eachScriptPanel .el-tree-node__content:hover {
background-color: #b7b7b7;
}
</style>