rt-sim-training-client/src/views/newMap/displayNew/demon/scheduling.vue

375 lines
14 KiB
Vue
Raw Normal View History

2019-12-30 09:00:16 +08:00
<template>
<div>
<el-dialog
v-dialogDrag
:title="title"
:visible.sync="show"
top="50px"
width="95%"
:before-do-close="doClose"
:close-on-click-modal="false"
:z-index="2000"
>
<div class="scheduling">
<el-card class="scheduling_header">
<el-form>
<el-row>
<el-col :span="6">
<el-form-item :label="$t('display.schedule.scheduleSelect')">
<el-date-picker
v-model="formModel.planDate"
clearable
size="small"
type="date"
value-format="yyyy-MM-dd"
2020-04-20 15:38:30 +08:00
:picker-options="pickerOptions"
2019-12-30 09:00:16 +08:00
@change="handleQuery"
/>
</el-form-item>
</el-col>
2020-04-20 15:38:30 +08:00
<el-col :span="12">
2019-12-30 09:00:16 +08:00
<el-form-item :label="$t('display.schedule.runDiagramName')">
2020-04-20 15:38:30 +08:00
<!--<el-select v-model="formModel.runPlanName" size="small" style="display: inline-block">-->
<!--<el-option-->
<!--v-for="item in runPlanList"-->
<!--:key="item.value"-->
<!--:label="item.label"-->
<!--:value="item.value"-->
<!--/>-->
<!--</el-select>-->
<el-input v-model="formModel.runPlanName" size="small" style="width:140px;" />
2019-12-30 09:00:16 +08:00
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item style="text-align: right">
<el-button-group>
<el-button size="small" type="primary" @click="handleSave">{{ $t('display.schedule.save') }}</el-button>
</el-button-group>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-card>
<div class="scheduling_body">
<div class="scheduling_body-table">
<edit-table ref="table" v-loading="loading" border stripe :table-data="tableData" :table-form="tableForm" :row-style="handleRowStyle" />
</div>
</div>
</div>
</el-dialog>
</div>
</template>
<script>
2020-04-20 15:38:30 +08:00
import { querySechedulingNew, generateSchedulingNew, saveSchedulingNew, generateSchedulingAgain } from '@/api/scheduling';
2019-12-30 09:00:16 +08:00
import { hexColor } from '@/utils/runPlan';
import EditTable from '@/views/components/editTable/index';
// 排班计划弹窗列表
export default {
name: 'Scheduling',
2019-12-30 09:00:16 +08:00
components: {
EditTable
},
props: {
group: {
type: String,
required: true
}
},
data() {
return {
show: false,
loading: false,
runPlanList: [],
groupNumberList: [],
2020-04-20 15:38:30 +08:00
pickerOptions: {
disabledDate(time) {
return time.getTime() < Date.now() - 24 * 3600 * 1000;
}
},
2019-12-30 09:00:16 +08:00
formModel: {
id: '',
mode: '',
planDate: '',
runPlanName: ''
},
tableForm: {
index: true,
columns: [
2020-04-20 15:38:30 +08:00
// {
// title: this.$t('display.schedule.driverNumber'),
// prop: 'driverCode',
// type: 'text'
// },
2019-12-30 09:00:16 +08:00
{
title: this.$t('display.schedule.trainNumber'),
2020-04-20 15:38:30 +08:00
prop: 'groupNumber',
2019-12-30 09:00:16 +08:00
type: 'select',
width: '150',
options: () => { return this.groupNumberList; },
editable: true,
editing: true
},
{
title: this.$t('display.schedule.onlineSection'),
2020-04-20 15:38:30 +08:00
prop: 'outDepotTrip.outDepotSectionCode',
type: 'text',
format: (row) => { return this.handleDeviceName(row.outDepotTrip.outDepotSectionCode); }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.onlineServerNumber'),
2020-04-20 15:38:30 +08:00
prop: 'outDepotTrip.serviceNumber',
type: 'text',
format: (row) => { return row.outDepotTrip.serviceNumber; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.onlineTargetNumber'),
2020-04-20 15:38:30 +08:00
prop: 'outDepotTrip.destinationCode',
type: 'text',
format: (row) => { return row.outDepotTrip.destinationCode; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.onlineTime'),
2020-04-20 15:38:30 +08:00
prop: 'outDepotTrip.outDepotTime',
type: 'text',
format: (row) => { return row.outDepotTrip.outDepotTime; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.onlineTripNumber'),
2020-04-20 15:38:30 +08:00
prop: 'outDepotTrip.tripNumber',
2019-12-30 09:00:16 +08:00
type: 'text',
2020-04-20 15:38:30 +08:00
format: (row) => { return row.outDepotTrip.tripNumber; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.outDepot'),
2020-04-20 15:38:30 +08:00
prop: 'outDepotTrip.outDepotCode',
type: 'text',
format: (row) => { return this.handleDeviceName(row.outDepotTrip.outDepotCode); }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.outDepotStatus'),
2020-04-20 15:38:30 +08:00
prop: 'outDepotTrip.status',
2019-12-30 09:00:16 +08:00
type: 'tag',
2020-04-20 15:38:30 +08:00
columnValue: (row) => { return this.$ConstSelect.translate(row.outDepotTrip.status, 'Whether'); },
2019-12-30 09:00:16 +08:00
tagType: (row) => {
2020-04-20 15:38:30 +08:00
switch (row.outDepotTrip.status) {
2019-12-30 09:00:16 +08:00
case true: return 'success';
case false: return 'danger';
}
}
},
{
title: this.$t('display.schedule.offlineSection'),
prop: 'offlineSection',
2020-04-20 15:38:30 +08:00
type: 'text',
format: (row) => { return this.handleDeviceName(row.inDepotTrip.inDepotSectionCode); }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.offlineServerNumber'),
prop: 'offlineServerNumber',
2020-04-20 15:38:30 +08:00
type: 'text',
format: (row) => { return row.inDepotTrip.serviceNumber; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.offlineTargetNumber'),
prop: 'offlineTargetNumber',
2020-04-20 15:38:30 +08:00
type: 'text',
format: (row) => { return row.inDepotTrip.destinationCode; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.offlineTime'),
prop: 'offlineTime',
2020-04-20 15:38:30 +08:00
type: 'text',
format: (row) => { return row.inDepotTrip.inDepotTime; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.offlineTripNumber'),
prop: 'offlineTripNumber',
type: 'text',
2020-04-20 15:38:30 +08:00
format: (row) => { return row.inDepotTrip.tripNumber; }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.inDepot'),
prop: 'inDepot',
2020-04-20 15:38:30 +08:00
type: 'text',
format: (row) => { return this.handleDeviceName(row.inDepotTrip.inDepotCode); }
2019-12-30 09:00:16 +08:00
},
{
title: this.$t('display.schedule.inDepotStatus'),
prop: 'inStatus',
type: 'tag',
2020-04-20 15:38:30 +08:00
columnValue: (row) => { return this.$ConstSelect.translate(row.inDepotTrip.status, 'Whether'); },
2019-12-30 09:00:16 +08:00
tagType: (row) => {
2020-04-20 15:38:30 +08:00
switch (row.inDepotTrip.status) {
2019-12-30 09:00:16 +08:00
case true: return 'success';
case false: return 'danger';
}
}
}
]
},
tableData: []
};
},
computed: {
title() {
return this.$t('display.schedule.schedulePlan');
}
},
2020-04-20 15:38:30 +08:00
watch: {
'$store.state.map.mapDataLoadedCount': function () {
const trainList = this.$store.state.map.map.trainList || [];
this.groupNumberList = [];
trainList.forEach(item => {
this.groupNumberList.push({value: item.code, label: item.groupNumber});
});
}
2019-12-30 09:00:16 +08:00
},
methods: {
doShow() {
this.formModel.day = '';
this.show = true;
},
doClose() {
this.show = false;
},
handleQuery(day) {
if (day) {
this.loading = true;
2020-04-20 15:38:30 +08:00
querySechedulingNew(this.group, {day}).then(resp => {
2019-12-30 09:00:16 +08:00
if (!resp.data) {
this.$confirm(this.$t('display.schedule.noSchedulePlan'), this.$t('global.tips'), {
confirmButtonText: this.$t('global.confirm'),
cancelButtonText: this.$t('global.cancel'),
type: 'warning'
}).then(() => {
this.handleGenerate(day);
}).catch(() => {
this.clearData();
this.loading = false;
});
} else {
this.tableData = this.initTableData(resp.data.planList || []);
this.formModel.id = resp.data.id;
this.formModel.planDate = resp.data.planDate;
this.formModel.runPlanName = resp.data.runPlanName;
this.$message.success(`${this.$t('display.schedule.loadData')} ${day} ${this.$t('display.schedule.schedulePlanSuccess')}`);
this.loading = false;
}
}).catch(error => {
this.clearData();
if (error.code == 30002) {
this.handleReGenerate(day);
} else {
this.$messageBox(`${error.message}`);
this.loading = false;
}
});
}
},
handleGenerate(day) {
2020-04-20 15:38:30 +08:00
generateSchedulingNew(this.group, {day}).then(resp => {
2019-12-30 09:00:16 +08:00
this.loading = false;
this.tableData = this.initTableData(resp.data.planList || []);
this.formModel.id = resp.data.id;
2020-04-21 18:43:10 +08:00
// this.formModel.planDate = resp.data.planDate;
2019-12-30 09:00:16 +08:00
this.formModel.runPlanName = resp.data.runPlanName;
this.$message.success(this.$t('display.schedule.createSchedulePlanSuccess'));
}).catch(error => {
this.loading = false;
this.clearData();
this.$messageBox(`${error.message}`);
});
},
handleReGenerate(day) {
generateSchedulingAgain(this.group).then(resp => {
this.loading = false;
this.tableData = this.initTableData(resp.data.planList || []);
this.formModel.id = resp.data.id;
this.formModel.planDate = resp.data.planDate;
this.formModel.runPlanName = resp.data.runPlanName;
this.$message.success(this.$t('display.schedule.regenerateSchedulePlanSuccess'));
}).catch(error => {
this.loading = false;
this.clearData();
this.$messageBox(`${error.message}`);
});
},
2020-04-20 15:38:30 +08:00
handleSave() {
2019-12-30 09:00:16 +08:00
if (this.formModel.planDate) {
2020-04-20 15:38:30 +08:00
saveSchedulingNew(this.group, this.tableData).then(resp => {
if (resp.data && !resp.data.pass) {
this.setConflictList(resp.data.conflictList);
2019-12-30 09:00:16 +08:00
this.$message.warning(this.$t('display.schedule.checkFailed'));
2020-04-20 15:38:30 +08:00
} else {
2020-04-22 09:42:46 +08:00
this.setConflictList([]);
2020-04-20 15:38:30 +08:00
this.$message.success(this.$t('display.schedule.saveSchedulePlanSuccess'));
2019-12-30 09:00:16 +08:00
}
}).catch(() => {
this.$messageBox(this.$t('display.schedule.saveSchedulePlanFail'));
});
} else {
this.$messageBox(this.$t('display.schedule.selectSchedulePlan'));
}
},
2020-04-20 15:38:30 +08:00
handleRowStyle({row, rowIndex}) {
return row['$conflict'] ? {background: row.$conflict} : {background: '#FFF'};
2019-12-30 09:00:16 +08:00
},
setConflictList(list) {
this.tableData.forEach(elem => { elem['$conflict'] = null; });
if (list && list.length) {
list.forEach(idList => {
const color = hexColor.colorRandom();
2019-12-30 09:00:16 +08:00
this.tableData.forEach(elem => {
if (idList.includes(parseInt(elem.id))) {
elem['$conflict'] = color;
}
});
});
}
this.tableData = [...this.tableData];
},
initTableData(tableData) {
tableData.forEach(elem => {
2020-04-20 15:38:30 +08:00
this.$set(elem, '$conflict', null);
2019-12-30 09:00:16 +08:00
});
return tableData;
},
clearData() {
this.formModel.planDate = '';
this.tableData = [];
2020-04-20 15:38:30 +08:00
},
handleDeviceName(code) {
const device = this.$store.getters['map/getDeviceByCode'](code) || {};
return device.name;
2019-12-30 09:00:16 +08:00
}
}
};
</script>
<style scoped rel="stylesheet/scss" lang="scss">
.scheduling {
&_header {
background: #fff;
padding: 30px 30px 0;
}
&_body {
margin-top: 30px;
background: #ffff;
border: 1px solid #F1F1F1;
width: 100%;
overflow: auto;
}
}
/deep/ .el-dialog__body {
background: #fafafa;
}
/deep/ label {
font-weight: 0;
}
</style>