rt-sim-training-client/src/views/jointTraining/menuDraft/operateMenu.vue
sunzhenyu d7efef41e4 pull
2019-08-29 17:16:33 +08:00

136 lines
2.5 KiB
Vue

<template>
<div>
<pop-menu ref="popMenu" :menu="menu" />
<choose-role ref="chooseRole" @setDriver="setDriver" />
</div>
</template>
<script>
import PopMenu from '@/components/PopMenu';
import ChooseRole from './chooseRole';
import { putUserRoles } from '@/api/chat';
import { DeviceMenu } from '@/scripts/ConstDic';
export default {
name: 'OperateMenu',
components: {
PopMenu,
ChooseRole
},
props: {
group: {
type: String,
required: true
},
point: {
type: Object,
required: true
},
selected: {
type: Object,
required: true
},
driverList: {
type: Array,
required: true
},
driverMapDict: {
type: Object,
required: true
}
},
data() {
return {
menuShow: false,
menu: [
{
label: '设置司机',
handler: this.chooseDriver
},
{
label: '取消司机',
handler: this.cancelDriver
}
]
};
},
watch: {
'$store.state.menuOperation.menuCount': function (val) {
if (this.$store.getters['menuOperation/checkDialogIsOpen'](DeviceMenu.SetDriver)) {
this.doShow(this.$store.state.menuOperation.menuPosition);
} else {
this.doClose();
}
}
},
mounted() {
this.closeEvent();
},
methods: {
closeEvent() {
const self = this;
window.onclick = function (e) {
self.doClose();
};
},
doShow(point) {
this.closeEvent();
if (this.$refs && this.$refs.popMenu) {
this.$refs.popMenu.resetShowPosition(point);
}
this.menuShow = true;
},
doClose() {
if (this.$refs && this.$refs.popMenu) {
this.$refs.popMenu.close();
}
this.menuShow = false;
},
chooseDriver() {
const arrs = Object.values(this.driverMapDict);
const list = this.driverList.filter(elem => {
let ret = true;
arrs.forEach(item => {
if (item.id == elem.id) {
ret = false;
}
});
return ret;
});
this.$refs.chooseRole.doShow({ title: '设置列车', list: list });
},
async setDriver(obj) {
if (obj && this.selected) {
const params = [{
id: obj.id,
nickName: obj.name,
userRole: 'Driver',
stationCode: '',
trainCode: this.selected._code
}];
await putUserRoles(params, this.group);
}
},
async cancelDriver() {
const data = this.driverMapDict[this.selected._code];
if (data) {
const params = [{
id: data.id,
nickName: data.name,
userRole: 'Driver',
stationCode: '',
trainCode: ''
}];
await putUserRoles(params, this.group);
}
},
refresh() {
this.$emit('refresh');
}
}
};
</script>