2019-07-26 13:32:43 +08:00
|
|
|
<template>
|
2019-08-29 17:16:33 +08:00
|
|
|
<div>
|
|
|
|
<pop-menu ref="popMenu" :menu="menu" />
|
|
|
|
<choose-role ref="chooseRole" @setDriver="setDriver" />
|
|
|
|
</div>
|
2019-07-26 13:32:43 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-08-29 17:16:33 +08:00
|
|
|
import PopMenu from '@/components/PopMenu';
|
|
|
|
import ChooseRole from './chooseRole';
|
|
|
|
import { putUserRoles } from '@/api/chat';
|
|
|
|
import { DeviceMenu } from '@/scripts/ConstDic';
|
2019-07-26 13:32:43 +08:00
|
|
|
|
2019-08-29 17:16:33 +08:00
|
|
|
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;
|
|
|
|
});
|
2019-07-26 13:32:43 +08:00
|
|
|
|
2019-08-29 17:16:33 +08:00
|
|
|
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
|
|
|
|
}];
|
2019-07-26 13:32:43 +08:00
|
|
|
|
2019-08-29 17:16:33 +08:00
|
|
|
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: ''
|
|
|
|
}];
|
2019-07-26 13:32:43 +08:00
|
|
|
|
2019-08-29 17:16:33 +08:00
|
|
|
await putUserRoles(params, this.group);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
refresh() {
|
|
|
|
this.$emit('refresh');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-07-26 13:32:43 +08:00
|
|
|
</script>
|