rt-sim-training-client/src/views/newMap/newMapdraft/mapoperate/zcControl.vue

348 lines
14 KiB
Vue

<template>
<el-tabs v-model="activeName" class="card" @tab-click="handleClick">
<el-tab-pane class="view-control" :label="$t('map.property')" name="first" :lazy="lazy">
<div style="height: calc(100% - 46px);">
<el-scrollbar wrap-class="scrollbar-wrapper">
<config-list ref="dataform" :form="form" :form-model="editModel" :rules="rules" />
</el-scrollbar>
</div>
<div class="button_box">
<el-button-group class="map-draft-group">
<el-button type="primary" size="small" @click="edit">{{ $t('map.updateObj') }}</el-button>
<el-button type="danger" size="small" @click="deleteObj">{{ $t('map.deleteObj') }}</el-button>
</el-button-group>
</div>
</el-tab-pane>
<el-tab-pane class="view-control" :label="$t('map.newConstruction')" name="second" :lazy="lazy">
<div style="height: calc(100% - 46px);">
<el-scrollbar wrap-class="scrollbar-wrapper">
<config-data ref="make" :form="formMake" :form-model="addModel" :rules="createRules" />
</el-scrollbar>
</div>
<div class="button_box">
<el-button-group class="map-draft-group">
<el-button type="primary" size="small" @click="create">{{ $t('map.create') }}</el-button>
</el-button-group>
</div>
</el-tab-pane>
</el-tabs>
</template>
<script>
import { mapGetters } from 'vuex';
import { getUID } from '@/jmapNew/utils/Uid';
import ConfigList from './config/list';
import ConfigData from './config/data';
import { deepAssign } from '@/utils/index';
export default {
name: 'ZcControlDraft',
components: {
ConfigList,
ConfigData
},
props: {
selected: {
type: Object,
default: function () {
return null;
}
}
},
data() {
return {
activeName: 'first',
lazy: true,
concertrateStation:[],
mapData: null,
editModel: {
code: '',
name: '',
// visible: '',
concentrateStationList:[],
position: {
x: 0,
y: 0
}
},
addModel: {
code: '',
name: '',
// visible: '',
concentrateStationList:[],
position: {
x: 0,
y: 0
}
},
rules: {
code: [
{ required: true, message: this.$t('rules.pleaseSelectEncoding'), trigger: 'change' }
],
name: [
{ required: true, message: this.$t('rules.pleaseEnterStatusSignal'), trigger: 'blur' }
],
// visible: [
// { required: true, message: this.$t('rules.visible'), trigger: 'change' }
// ],
concentrateStationList:[
{ required: true, message: this.$t('rules.selectConcentrateStation'), trigger: 'change' }
],
'position.x': [
{ required: true, message: this.$t('rules.trainPositionX'), trigger: 'blur' }
],
'position.y': [
{ required: true, message: this.$t('rules.trainPositionY'), trigger: 'blur' }
]
}
};
},
computed: {
...mapGetters('map', [
'sectionList',
'trainModelList',
'zcList',
'lineCode',
'stationList'
]),
form() {
const form = {
labelWidth: '150px',
items: {
code: {
name: '',
item: []
},
draw: {
name: this.$t('map.drawData'),
item: [
{ prop: 'code', label: `${this.$t('map.zcZoneControl')}${this.$t('map.code')}`, type: 'select', optionLabel: 'name&&code', optionValue: 'code', options: this.zcList, change: true, deviceChange: this.deviceChange },
{ prop: 'name', label: this.$t('map.statusSignalName'), type: 'input' },
// { prop: 'visible', label: this.$t('map.showZc'), type: 'checkboxx' },
{ prop: 'position', label: this.$t('map.stateSignalsPlotCoordinates'), type: 'coordinate', width: '140px', children: [
{ prop: 'position.x', firstLevel: 'position', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '20px' },
{ prop: 'position.y', firstLevel: 'position', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '20px' }
] },
{ prop:'concentrateStationList', label:this.$t('map.concentrateStationList'), type: 'multiSelect', optionLabel: 'name', optionValue: 'code', options: this.concertrateStation, deviceChange: this.changeConcentrateStation }
]
}
}
};
return form;
},
formMake() {
const form = {
labelWidth: '150px',
items: [
{ prop: 'name', label: this.$t('map.statusSignalName'), type: 'input' },
{ prop: 'position', label: this.$t('map.stateSignalsPlotCoordinates'), type: 'coordinate', width: '140px', children: [
{ prop: 'position.x', firstLevel: 'position', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '20px' },
{ prop: 'position.y', firstLevel: 'position', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '20px' }
] },
{ prop:'concentrateStationList', label:this.$t('map.concentrateStationList'), type: 'multiSelect', optionLabel: 'name', optionValue: 'code', options: this.concertrateStation, deviceChange: this.changeConcentrateStation }
]
};
return form;
},
createRules: function () {
return {
name: [
{ required: true, message: this.$t('rules.pleaseEnterStatusSignal'), trigger: 'blur' }
],
'position.x': [
{ required: true, message: this.$t('rules.trainPositionX'), trigger: 'blur' }
],
'position.y': [
{ required: true, message: this.$t('rules.trainPositionY'), trigger: 'blur' }
],
concentrateStationList:[
{ required: true, message: this.$t('rules.selectConcentrateStation'), trigger: 'change' }
]
};
}
},
watch: {
stationList() {
this.getConcertrateStation();
}
},
mounted() {
this.getConcertrateStation();
},
methods: {
deviceChange(code) {
this.$emit('setCenter', code);
this.deviceSelect(this.$store.getters['map/getDeviceByCode'](code));
},
changeConcentrateStation() {},
handleClick() {
this.getConcertrateStation();
},
deviceSelect(selected) {
this.$refs.dataform && this.$refs.dataform.resetFields();
this.$refs.make && this.$refs.make.resetFields();
if (selected && selected._type.toUpperCase() === 'ZcControl'.toUpperCase()) {
this.activeName = 'first';
this.editModel = deepAssign(this.editModel, selected);
this.getConcertrateStation();
}
},
getConcertrateStation() {
// 被选中的集中站站数据
const beConcentrateStation = {};
this.zcList.forEach(data=>{
data.concentrateStationList.forEach(concentrate=>{
beConcentrateStation[concentrate] = data.code;
});
});
this.concertrateStation = this.stationList.filter(station=>{
// if (this.activeName == 'first') {
// return station.centralized && !( beConcentrateStation[station.code] && (beConcentrateStation[station.code] != this.editModel.code));
return station.centralized;
// } else {
// return station.centralized && !( beConcentrateStation[station.code]);
// }
});
},
create() {
this.$refs.make.validate((valid) => {
if (valid) {
const uid = getUID('ZcControl', this.zcList);
let models = [];
const model = {
_type: 'ZcControl',
code: uid,
name: this.addModel.name,
position: {
x: this.addModel.position.x,
y: this.addModel.position.y
},
concentrateStationList:this.addModel.concentrateStationList
};
models.push(model);
model.concentrateStationList.forEach(stationCode=>{
const arr = this.setStationStand(stationCode, model.code);
models = [...models, ...arr];
});
this.$emit('updateMapModel', models);
this.getConcertrateStation();
this.$refs.make.resetForm();
}
});
},
// 修改对象
edit() {
this.$refs['dataform'].validate((valid) => {
if (valid) {
const data = Object.assign({_type: 'ZcControl'}, this.editModel);
let models = [data];
data.concentrateStationList.forEach(stationCode=>{
const arr = this.setStationStand(stationCode, data.code);
models = [...models, ...arr];
});
this.$emit('updateMapModel', models);
}
});
},
// 删除对象
deleteObj() {
const selected = this.$store.getters['map/getDeviceByCode'](this.editModel.code);
if (selected && selected._type.toUpperCase() === 'ZcControl'.toUpperCase()) {
this.$confirm(this.$t('tip.confirmDeletion'), this.$t('tip.hint'), {
confirmButtonText: this.$t('tip.confirm'),
cancelButtonText: this.$t('tip.cancel'),
type: 'warning'
}).then(() => {
this.concertrateStation.forEach(station=>{
selected.concentrateStationList.forEach(stationCode=>{
switch (stationCode) {
case station.code: {
this.setStationStand(station.code, '');
break;
}
}
});
});
this.$emit('updateMapModel', {...selected, _dispose: true});
this.$refs.dataform && this.$refs.dataform.resetFields();
}).catch(() => {
this.$message.info(this.$t('tip.cancelledDelete'));
});
}
},
// 设置车站所属ZC区域
setStationStand(stationCode, code) {
const arr = [];
this.stationList.forEach(elem=>{
if (elem.code == stationCode) {
const station = deepAssign({}, elem);
// const station = Object.assign({}, elem);
station.zcCode = code;
arr.push(station);
// this.$emit('updateMapModel', station);
}
});
return arr; // 返回设置的车站list
}
// changeConcertrateStation(data) {
// if (data.length > 0) {
// debugger;
// this.concertrateStation.forEach(station=>{
// const newModal = Object.assign({}, station);
// // newModal.controlled = false;
// // newModal.concentrateStationCode = '';
// this.setStationStand(station, '');
// data.forEach(each=>{
// switch (each) {
// case station.code: {
// // newModal.controlled = true;
// // newModal.concentrateStationCode = this.editModel.code;
// this.setStationStand(station, this.editModel.code);
// break;
// }
// }
// });
// this.$emit('updateMapModel', newModal);
// });
// } else {
// // 没有选中数据,直接将其他车站设置
// this.modifyChargeStation();
// }
// this.edit();
// }
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.view-control{
height: 100%;
}
.card {
height: 100%;
}
.coordinate {
overflow: hidden;
.title {
text-align: right;
font-size: 14px;
color: #606266;
line-height: 40px;
padding: 0 12px 0 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
line-height: 28px;
width: 160px;
font-weight: bold;
display: block;
float: left;
}
}
.map-draft-group {
color: #3E44BE;
}
</style>