2020-08-20 20:27:19 +08:00
|
|
|
<template>
|
2020-12-16 10:54:55 +08:00
|
|
|
<el-select v-model="oldShowMemberId" :style="styleCss" size="small" @change="switchStationMode">
|
2020-08-20 20:27:19 +08:00
|
|
|
<el-option v-for="item in stationListMode" :key="item.value" :label="item.name" :value="item.value" />
|
|
|
|
</el-select>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import { mapGetters } from 'vuex';
|
2020-12-16 10:54:55 +08:00
|
|
|
import { assignUsersPlayRoles } from '@/api/jointSimulation';
|
2021-01-25 15:46:18 +08:00
|
|
|
import { EventBus } from '@/scripts/event-bus';
|
|
|
|
|
2020-08-20 20:27:19 +08:00
|
|
|
export default {
|
|
|
|
name:'SelectStation',
|
|
|
|
props:{
|
|
|
|
styleCss: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
stationListMode: [], // 设备集中站列表
|
2020-12-16 10:54:55 +08:00
|
|
|
showMemberId: '', // 展示的值班站memberId
|
|
|
|
oldShowMemberId: '',
|
|
|
|
stationCentralizedMap: {},
|
|
|
|
showStation: ''
|
2020-08-20 20:27:19 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed:{
|
|
|
|
...mapGetters('map', [
|
|
|
|
'map',
|
|
|
|
'stationList'
|
|
|
|
])
|
|
|
|
},
|
|
|
|
watch:{
|
2020-12-16 10:54:55 +08:00
|
|
|
'$store.state.training.memberData': function (val) {
|
2021-01-26 17:13:00 +08:00
|
|
|
this.initStationListMode();
|
2020-08-20 20:27:19 +08:00
|
|
|
},
|
2020-12-16 10:54:55 +08:00
|
|
|
'$store.state.training.simulationUserList': function(val) {
|
2021-01-26 17:13:00 +08:00
|
|
|
this.initData();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.initStationListMode();
|
|
|
|
this.initData();
|
|
|
|
EventBus.$on('switchStationMode', (stationCode) => {
|
|
|
|
this.$store.state.training.memberList.filter(el => el.type == 'STATION_SUPERVISOR').find(el => {
|
|
|
|
if (el.deviceCode == stationCode) {
|
2021-01-28 18:22:13 +08:00
|
|
|
this.oldShowMemberId = el.id;
|
2021-01-26 17:13:00 +08:00
|
|
|
this.switchStationMode(el.id);
|
2020-08-20 20:27:19 +08:00
|
|
|
}
|
2020-12-16 10:54:55 +08:00
|
|
|
});
|
2021-01-26 17:13:00 +08:00
|
|
|
});
|
|
|
|
},
|
2020-08-20 20:27:19 +08:00
|
|
|
methods:{
|
|
|
|
switchStationMode(val) {
|
2020-12-16 10:54:55 +08:00
|
|
|
assignUsersPlayRoles([{ userId: this.$store.state.user.id, memberId: val}], this.$route.query.group).then(resp => {
|
2021-01-28 18:22:13 +08:00
|
|
|
this.showMemberId = val;
|
|
|
|
const nameList = Object.keys(this.$store.state.map.map || {});
|
2020-08-20 20:27:19 +08:00
|
|
|
let list = [];
|
2020-12-16 10:54:55 +08:00
|
|
|
const member = this.$store.state.training.memberData[val];
|
2021-01-28 18:22:13 +08:00
|
|
|
const station = this.$store.getters['map/getDeviceByCode'](member.deviceCode);
|
|
|
|
if (station) {
|
|
|
|
this.showStation = station.code;
|
|
|
|
const showStationCode = this.stationCentralizedMap[station.code];
|
|
|
|
nameList.forEach(item => {
|
|
|
|
if (this.$store.state.map.map[item] && this.$store.state.map.map[item].constructor === Array) {
|
|
|
|
if (item === 'trainList') {
|
|
|
|
this.$store.state.map.map[item].forEach(elem => {
|
|
|
|
elem && list.push(elem);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
list = [...list, ...this.$store.state.map.map[item]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$jlmap.updateShowStation(list, showStationCode);
|
|
|
|
this.setCenter(showStationCode);
|
|
|
|
}
|
2021-01-27 09:27:44 +08:00
|
|
|
}).catch((err) => {
|
2021-01-28 18:22:13 +08:00
|
|
|
console.log(err);
|
2020-12-16 10:54:55 +08:00
|
|
|
this.showMemberId = this.oldShowMemberId;
|
|
|
|
this.$message.error('调整角色成员失败!');
|
|
|
|
});
|
2020-08-20 20:27:19 +08:00
|
|
|
},
|
|
|
|
setCenter(code) {
|
|
|
|
this.$jlmap.setCenter(code);
|
2021-01-26 17:13:00 +08:00
|
|
|
},
|
|
|
|
initStationListMode() {
|
|
|
|
this.stationListMode = [];
|
|
|
|
this.$store.state.training.memberList.forEach(item => {
|
|
|
|
if (item.type === 'STATION_SUPERVISOR') {
|
2021-01-28 18:22:13 +08:00
|
|
|
const station = this.$store.getters['map/getDeviceByCode'](item.deviceCode);
|
|
|
|
if (station) {
|
|
|
|
this.stationListMode.push({value:item.id, name: station.name});
|
|
|
|
}
|
2021-01-26 17:13:00 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
initData() {
|
|
|
|
this.$store.state.training.simulationUserList.forEach(item => {
|
2021-01-28 18:22:13 +08:00
|
|
|
if (item.type === 'STATION_SUPERVISOR' && item.userId == this.$store.state.user.id) {
|
2021-01-26 17:13:00 +08:00
|
|
|
this.showMemberId = item.memberId;
|
|
|
|
this.oldShowMemberId = item.memberId;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.stationList.forEach(item => {
|
|
|
|
if (item.centralized) {
|
|
|
|
this.stationCentralizedMap[item.code] = item.code;
|
|
|
|
item.chargeStationCodeList.forEach(ele => {
|
|
|
|
this.stationCentralizedMap[ele] = item.code;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (this.showMemberId) {
|
|
|
|
this.switchStationMode( this.showMemberId);
|
|
|
|
}
|
2020-08-20 20:27:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|