rt-sim-training-client/src/views/newMap/newMapdraft/mapoperate/station.vue
2020-05-25 15:06:34 +08:00

542 lines
26 KiB
Vue

<template>
<el-tabs v-model="activeName" class="card">
<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">
<el-button
icon="el-icon-plus"
circle
size="small"
style="position: absolute; right: 50px; top: 0px; z-index: 10;"
class="point-button"
@click="addModelList"
/>
<el-form ref="make" label-width="140px" :model="addModel" size="mini" :rules="mergeRules">
<el-form-item label="距区段高度:" prop="positionY">
<el-input-number v-model="addModel.positionY" />
</el-form-item>
<el-table :data="addModel.modelList" style="width: 100%">
<el-table-column label="计轴区段" prop="sectionName" width="160">
<template slot-scope="scope">
<el-select v-model="scope.row.sectionCode" filterable size="mini" placeholder="请选择">
<el-option
v-for="item in PhysicalSectionList"
:key="item.code"
:label="item.name + '(' + item.code +')'"
:value="item.code"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="车站名称">
<template slot-scope="scope">
<el-input v-model="scope.row.stationName" placeholder="请输入内容" size="mini" />
</template>
</el-table-column>
<el-table-column label="控制模式">
<template slot-scope="scope">
<el-checkbox v-model="scope.row.control" />
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button size="mini" type="text" @click="handleDelete(scope.$index, scope.row)">{{ $t('map.deleteObj') }}</el-button>
</template>
</el-table-column>
</el-table>
</el-form>
</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-tab-pane class="view-control" :label="$t('map.batchSettings')" name="three" :lazy="lazy">
<div style="height: 100%;">
<el-scrollbar wrap-class="scrollbar-wrapper">
<el-form ref="oprt" :model="allModel" label-width="130px" size="mini">
<el-form-item label="车站字体大小:" prop="nameFont">
<el-font v-model="allModel.nameFont" :placeholder="this.$t('tip.stationFont')" />
</el-form-item>
<el-form-item label="公里标字体大小:" prop="kmPostFont">
<el-font v-model="allModel.kmPostFont" :placeholder="this.$t('tip.stationFont')" />
</el-form-item>
<el-form-item label="车站Y坐标:" prop="positionY">
<el-input-number v-model="allModel.positionY" />
</el-form-item>
<el-form-item>
<el-button-group>
<el-button type="primary" @click="batchSettings">{{ $t('global.set') }}</el-button>
</el-button-group>
</el-form-item>
</el-form>
</el-scrollbar>
</div>
</el-tab-pane>
</el-tabs>
</template>
<script>
import ElFont from '@/views/components/font/index';
import { mapGetters } from 'vuex';
import { getUID } from '@/jmapNew/utils/Uid';
import ConfigList from './config/list';
import { deepAssign } from '@/utils/index';
export default {
name: 'StationDraft',
components: {
ConfigList,
ElFont
},
props: {
selected: {
type: Object,
default: function () {
return null;
}
}
},
data() {
return {
activeName: 'first',
lazy: true,
// field: '',
chargeStation:[],
relStationList: [], // 车站列表
controlled:false,
editModel: {
centralized: false,
// concentrateStationCode: '', // 所属集中站
ciStation: false, // 是否联锁站
depot:false, // 是否停车场或者车辆段
reentry:false, // 是否折返车站
number:'', // 编号
code: '',
zcCode: '',
visible: true,
runPlanName: '',
name: '',
nameFont: '',
nameFontColor: '#FFFFFF',
subheadDisplay:false,
subhead:'', // 副标题
subheadFont:'',
subheadFontColor:'#FFFFFF',
subheadPosition:{ x: 0, y: 0 },
kmPostShow: '',
kmRange: 0,
kmPost: '',
kmPostFont: '',
kmPostFontColor: '#FFFFFF',
isShowControlMode: '',
chargeStationCodeList:[],
relStationCodeList: [], // 联锁站关联车站列表
position: { x: 0, y: 0 },
kilometerPosition: { x: 0, y: 0 }, // 公里标偏移坐标
// controlled:false,
createControlMode:false,
createTurnBack:false,
turnBackPoint: {x: 0, y: 0}, // 按图折返坐标
controlModePoint: { x: 0, y: 0 } // 控制模式坐标
},
addModel: {
modelList: [],
positionY: 0
},
skins: [],
mergeRules: {
positionY: [
{ required: true, message: '请输入高度值', trigger: 'blur' }
]
},
allModel: {
nameFont: '',
kmPostFont: '',
positionY: 0
}
};
},
computed: {
...mapGetters('map', [
'stationList',
'sectionList',
'zcList',
'lineCode',
'stationStandList'
]),
form() {
return {
labelWidth: '130px',
items: {
code: {
name: '',
item: []
},
draw: {
name: this.$t('map.drawData'),
item: [
{ prop: 'code', label: this.$t('map.stationCode'), type: 'select', optionLabel: 'name&&code', optionValue: 'code', options: this.stationList, change: true, deviceChange: this.deviceChange },
{ prop: 'name', label: this.$t('map.stationName'), type: 'input' },
{ prop: 'number', label: this.$t('map.stationNumber'), type: 'input' },
{ prop: 'position', label: this.$t('map.stationPosition'), type: 'coordinate', width: '120px', children: [
{ prop: 'position.x', firstLevel: 'position', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px' },
{ prop: 'position.y', firstLevel: 'position', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px' }
] },
{ prop: 'visible', label: this.$t('map.stationstandShowName'), type: 'checkbox' },
{ prop: 'nameFont', label: this.$t('map.stationNameFont'), type: 'font', placeholder: this.$t('tip.stationFont') },
{ prop: 'nameFontColor', label: this.$t('map.stationNameFontColor'), type: 'color' },
{ prop: 'subheadDisplay', label: this.$t('map.subheadDisplay'), type: 'checkbox' },
{ prop: 'subhead', label: this.$t('map.subhead'), type: 'input', isHidden:!this.editModel.subheadDisplay },
{ prop: 'subheadFont', label: this.$t('map.subheadFont'), type: 'font', isHidden:!this.editModel.subheadDisplay },
{ prop: 'subheadFontColor', label: this.$t('map.subheadFontColor'), type: 'color', isHidden:!this.editModel.subheadDisplay },
{ prop: 'subheadPosition', label: this.$t('map.subheadPosition'), type: 'coordinate', width: '120px', isHidden:!this.editModel.subheadDisplay, children: [
{ prop: 'subheadPosition.x', firstLevel: 'subheadPosition', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px' },
{ prop: 'subheadPosition.y', firstLevel: 'subheadPosition', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px' }
] },
{ prop: 'depot', label: this.$t('map.isParkingArea'), type: 'checkbox' },
{ prop: 'reentry', label: this.$t('map.isReentryStation'), type: 'checkbox' },
{ prop: 'kilometerPosition', label: '公里标偏移坐标:', type: 'coordinate', width: '120px', children: [
{ prop: 'kilometerPosition.x', firstLevel: 'kilometerPosition', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px' },
{ prop: 'kilometerPosition.y', firstLevel: 'kilometerPosition', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px' }
] },
{ prop: 'kmRange', label: this.$t('map.stationKmRange'), type: 'number', min: 0, placeholder: this.$t('tip.meter') },
{ prop: 'kmPost', label: this.$t('map.stationKmPost'), type: 'input' },
{ prop: 'kmPostFont', label: this.$t('map.stationKmPostFont'), type: 'font', placeholder: this.$t('tip.kilometerFont') },
{ prop: 'kmPostFontColor', label: this.$t('map.stationKmPostFontColor'), type: 'color' },
{ prop: 'createControlMode', label: '控制模式:', type: 'checkbox', change:true, deviceChange:this.changeControlMode},
{ prop: 'controlModePoint', label: this.$t('map.stationControlPosition'), type: 'coordinate', width: '120px', isHidden:!this.editModel.createControlMode, children: [
{ prop: 'controlModePoint.x', firstLevel: 'controlModePoint', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px'},
{ prop: 'controlModePoint.y', firstLevel: 'controlModePoint', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px'}
] },
{ prop: 'createTurnBack', label: '按图折返:', type: 'checkbox' },
{ prop: 'turnBackPoint', label: '按图折返坐标:', type: 'coordinate', width: '120px', isHidden: !this.isPointsShow, children: [
{ prop: 'turnBackPoint.x', firstLevel: 'turnBackPoint', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px' },
{ prop: 'turnBackPoint.y', firstLevel: 'turnBackPoint', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px' }
] }
]
},
map: {
name: this.$t('map.mapData'),
item: [
{ prop: 'ciStation', label: this.$t('map.isCIStation'), type: 'checkbox'},
{ prop: 'centralized', label: this.$t('map.centralized'), type: 'checkbox', disabled:this.controlled, change:true, deviceChange:this.changeCentralized },
{ prop: 'zcCode', label: this.$t('map.zcCode'), type: 'select', optionLabel: 'code&&name', optionValue: 'code', options: this.zcList, isHidden: !this.isZcCode, disabled:true },
{ prop: 'chargeStationCodeList', label: this.$t('map.chargeStationList'), type: 'multiSelect', optionLabel: 'name', optionValue: 'code', options: this.chargeStation, isHidden: !this.isZcCode, deviceChange:this.changeChargeStation},
{ prop: 'relStationCodeList', label: '联锁站关联车站:', type: 'multiSelect', optionLabel: 'name', optionValue: 'code', options: this.relStationList, isHidden: !this.idCiStation},
{ prop: 'runPlanName', label: this.$t('map.stationRunPlanName'), type: 'input' }
]
}
}
};
},
rules() {
return {
code: [
{ required: true, message: this.$t('rules.selectEquipment'), trigger: 'change' }
],
name: [
{ required: true, message: this.$t('rules.stationName'), trigger: 'blur' }
],
kmRange: [
{ required: true, message: this.$t('rules.stationKmRange'), trigger: 'blur' }
],
kmPost: [
{ required: true, message: this.$t('rules.stationKmPost'), trigger: 'blur' }
],
'position.x': [
{ required: true, message: this.$t('rules.pleaseEnterXCoordinate'), trigger: 'blur' }
],
'position.y': [
{ required: true, message: this.$t('rules.pleaseEnterYCoordinate'), trigger: 'blur' }
]
};
},
PhysicalSectionList() {
let list = [];
if (this.sectionList && this.sectionList.length) {
list = this.sectionList.filter(elem => { return elem.type === '01' && !elem.switchSection; });
}
return list;
},
isPointsShow() {
return this.editModel.createTurnBack;
},
isZcCode() {
return this.editModel.centralized;
},
idCiStation() {
return this.editModel.ciStation;
}
},
watch: {
// selected: function (val) {
// this.deviceSelect(val);
// }
},
methods: {
deviceChange(code) {
this.$emit('setCenter', code);
this.deviceSelect(this.$store.getters['map/getDeviceByCode'](code));
},
deviceSelect(selected) {
if (selected && selected._type.toUpperCase() === 'Station'.toUpperCase()) {
this.$refs.dataform && this.$refs.dataform.resetFields();
this.activeName = 'first';
this.editModel = deepAssign(this.editModel, selected);
// 被控制的车站数据
const beCentralizedStation = {};
this.relStationList = JSON.parse(JSON.stringify(this.stationList));
this.stationList.forEach(data=>{
if (data.centralized) {
data.chargeStationCodeList.forEach(charge=>{
beCentralizedStation[charge] = data.code;
});
}
if (data.ciStation && data.code != this.selected.code) {
const arr = data.relStationCodeList || [];
arr.forEach(stationCode => {
this.relStationList.forEach((data, index) => {
if (data.code == stationCode) {
this.relStationList.splice(index, 1);
}
});
});
}
});
// 筛选数据 去掉已经是集中站的数据,去掉自己本身,去掉被别的集中站选中的数据
this.chargeStation = this.stationList.filter(data=>{
return !data.centralized && data.code != this.editModel.code && !(beCentralizedStation[data.code] && beCentralizedStation[data.code] != this.editModel.code);
});
this.controlled = !!beCentralizedStation[selected.code];
}
},
changeControlMode(data) {
if (data) {
this.editModel.controlModePoint = {
x:this.editModel.position.x,
y:this.editModel.position.y + 30
};
} else {
this.editModel.controlModePoint = {
x:0,
y:0
};
}
},
// 选择管理车站
changeChargeStation(data) {
if (data.length > 0) {
this.chargeStation.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();
},
changeCentralized(data) {
if (!data) {
// 将当前车站选为非集中站
this.editModel.chargeStationCodeList = [];
this.edit();
this.modifyChargeStation();
this.setStationStand(this.editModel, '');
} else {
this.setStationStand(this.editModel, this.editModel.code);
}
},
modifyChargeStation() {
this.chargeStation.forEach(station=>{
const newModal = Object.assign({}, station);
// newModal.controlled = false;
// newModal.concentrateStationCode = '';
// 将原来被控制的车站下的站台,属性{所属设备集中站}设置为空
this.setStationStand(station, '');
this.$emit('updateMapModel', newModal);
});
},
// 设置属性{所属设备集中站}
setStationStand(station, code) {
this.stationStandList.forEach(elem=>{
if (elem.stationCode == station.code) {
const stationStand = Object.assign({}, elem);
stationStand.deviceStationCode = code;
this.$emit('updateMapModel', stationStand);
}
});
},
// hover(field) {
// this.field = field === this.field ? '' : field;
// this.$emit('stationSectionCode', this.field);
// },
create() {
this.$refs['make'].validate((valid) => {
if (valid) {
if (this.addModel.modelList.length) {
const models = [];
this.addModel.modelList.forEach((item) => {
const uid = getUID('Station', [...this.stationList, ...models]);
const model = {
_type: 'Station',
code: uid,
name: item.stationName,
number:'',
subheadDisplay:false,
zcCode: '',
runPlanName: '',
visible: true,
nameFont: '22',
nameFontColor: '#FFFFFF',
kmPost: '1000km~2000km',
kmPostShow: true,
kmPostFont: '8',
kmPostFontColor: '#FFFFFF',
kilometerPosition: { x: 0, y: 0 },
centralized: false,
depot:false,
reentry:false,
// concentrateStationCode: '',
// controlled: false,
chargeStationCodeList:[],
relStationCodeList: [], // 联锁站关联车站列表
createControlMode: item.control,
createTurnBack: false,
turnBackPoint: {x: 0, y: 0}, // 按图折返坐标
textControlMode: false, // 状态模式
textControlModePosition: { x: 0, y: 0},
showUnmanned: false, // 无人折返
unmannedPosition: {x: 0, y: 0},
showLampFilament: false, // 信号灯丝警告
lampFilamentPosition: {x: 0, y: 0},
showControlSwitch: false, // LCW/ATS开关控制
controlSwitchPosition: {x: 0, y: 0},
showFoldbackMode: false, // 折返模式
foldbackModePosition: {x: 0, y: 0}
};
this.sectionList.forEach(elem => {
if (elem.code === item.sectionCode) {
const l = 0;
const r = elem.points.length - 1;
model.position = {
x: elem.points[l].x + (elem.points[r].x - elem.points[l].x) / 2,
y: elem.points[l].y - this.addModel.positionY
};
if (item.control) {
model.controlModePoint = {
x: elem.points[l].x + (elem.points[r].x - elem.points[l].x) / 2,
y: elem.points[l].y - this.addModel.positionY + 30
};
}
}
});
models.push(model);
});
this.$emit('updateMapModel', models);
this.addModel = {
modelList: [],
positionY: 0
};
} else {
this.$message('请添加数据');
}
}
});
},
// 修改对象
edit() {
this.$refs['dataform'].validate((valid) => {
if (valid) {
const data = Object.assign({_type: 'Station'}, this.editModel);
this.$emit('updateMapModel', data);
}
});
},
// 删除对象
deleteObj() {
const selected = this.$store.getters['map/getDeviceByCode'](this.editModel.code);
if (selected && selected._type.toUpperCase() === 'Station'.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.$emit('updateMapModel', {...selected, _dispose: true});
this.$refs.dataform && this.$refs.dataform.resetFields();
}).catch(() => {
this.$message.info(this.$t('tip.cancelledDelete'));
});
}
},
// 批量设置
batchSettings() {
const models = [];
this.stationList.forEach(station => {
const model = deepAssign({}, station);
model.nameFont = this.allModel.nameFont;
model.kmPostFont = this.allModel.kmPostFont;
model.position.y = this.allModel.positionY;
models.push(model);
});
this.$emit('updateMapModel', models);
},
handleDelete(index, row) {
this.addModel.modelList.splice(index, 1);
},
addModelList() {
this.addModel.modelList.push({
sectionCode: '',
sectionName: '',
stationName: `车站 ${this.addModel.modelList.length + 1}`,
control: false
});
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.view-control{
height: 100%;
}
.card {
height: 100%;
}
</style>