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

333 lines
14 KiB
Vue
Raw Normal View History

2019-11-29 12:51:58 +08:00
<template>
<el-tabs v-model="activeName" class="card">
<el-tab-pane class="view-control" :label="$t('map.property')" name="first">
<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">
<div style="height: calc(100% - 46px);">
<el-scrollbar wrap-class="scrollbar-wrapper">
<el-form ref="make" label-width="140px" :model="addModel" size="mini" :rules="mergeRules">
<el-form-item :label="$t('map.physicalSegmentName')" prop="sectionCode">
<el-select v-model="addModel.sectionCode" filterable>
<el-option
v-for="item in PhysicalSectionList"
:key="item.code"
:label="item.name + ' (' + item.code+ ')'"
:value="item.code"
/>
</el-select>
<el-button
:type="field === 'selectStationCode' ? 'danger' : 'primary'"
size="small"
@click="hover('selectStationCode')"
>{{ $t('map.activate') }}</el-button>
</el-form-item>
</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-tabs>
</template>
<script>
import { mapGetters } from 'vuex';
import { getUID } from '@/jmap/utils/Uid';
import ConfigList from './config/list';
import { deepAssign } from '@/utils/index';
export default {
name: 'StationDraft',
components: {
ConfigList
},
props: {
selected: {
type: Object,
default: function () {
return null;
}
}
},
data() {
return {
activeName: 'first',
field: '',
2019-12-03 13:24:22 +08:00
chargeStation:[],
2019-11-29 12:51:58 +08:00
editModel: {
centralized: false,
concentrateStationCode: '',
code: '',
zcCode: '',
visible: true,
runPlanName: '',
name: '',
nameFont: '',
nameFontColor: '#FFFFFF',
kmPostShow: '',
kmRange: 0,
kmPost: '',
kmPostFont: '',
kmPostFontColor: '#FFFFFF',
isShowControlMode: '',
2019-12-03 13:24:22 +08:00
chargeStationCodeList:[],
2019-11-29 12:51:58 +08:00
position: {
x: 0,
y: 0
2019-12-03 13:24:22 +08:00
},
controlled:false
2019-11-29 12:51:58 +08:00
},
addModel: {
sectionCode: ''
},
skins: [],
mergeRules: {
sectionCode: [
{ required: true, message: this.$t('rules.selectPhysicalExtentName'), trigger: 'blur' }
]
}
};
},
computed: {
...mapGetters('map', [
'stationList',
'sectionList',
'zcList',
'lineCode'
]),
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: '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: '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' }
]
},
map: {
name: this.$t('map.mapData'),
item: [
2019-12-03 13:24:22 +08:00
{ prop: 'concentrateStationCode', label: this.$t('map.concentrateStationCode'), type: 'select', optionLabel: 'code&&name', optionValue: 'code', options: this.stationList, disabled:this.editModel.controlled },
{ prop: 'centralized', label: this.$t('map.centralized'), type: 'checkbox', disabled:this.editModel.controlled, change:true, deviceChange:this.changeCentralized },
2019-11-29 12:51:58 +08:00
{ prop: 'zcCode', label: this.$t('map.zcCode'), type: 'select', optionLabel: 'code&&name', optionValue: 'code', options: this.zcList, isHidden: !this.isZcCode },
2019-12-03 13:24:22 +08:00
{ prop: 'chargeStationCodeList', label: this.$t('map.chargeStationList'), type: 'multiSelect', optionLabel: 'name', optionValue: 'code', options: this.chargeStation, isHidden: !this.isZcCode, deviceChange:this.changeChargeStation},
2019-11-29 12:51:58 +08:00
{ 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.isSwitchSection; });
}
return list;
},
isZcCode() {
return this.editModel.centralized;
}
},
watch: {
selected: function (val) {
this.deviceSelect(val);
}
},
methods: {
deviceChange(code) {
this.$emit('setCenter', code);
this.deviceSelect(this.$store.getters['map/getDeviceByCode'](code));
},
deviceSelect(selected) {
this.$refs.dataform.resetFields();
this.$refs.make.resetFields();
if (selected && selected._type.toUpperCase() === 'Station'.toUpperCase()) {
this.activeName = 'first';
this.editModel = deepAssign(this.editModel, selected);
this.editModel.runPlanName = selected.runPlanName || '';
2019-12-03 13:24:22 +08:00
this.chargeStation = this.stationList.filter(data=>{
return !data.centralized && data.code != this.editModel.code && !(data.controlled && data.concentrateStationCode != this.editModel.code);
});
2019-11-29 12:51:58 +08:00
}
if (this.field.toUpperCase() === 'selectStationCode'.toUpperCase()) {
this.addModel.sectionCode = selected.code;
this.activeName = 'second';
this.field = '';
this.$emit('stationSectionCode', '');
}
},
2019-12-03 13:24:22 +08:00
changeChargeStation(data) {
if (data.length > 0) {
this.chargeStation.forEach(station=>{
const newModal = Object.assign({}, station);
newModal.controlled = false;
newModal.concentrateStationCode = '';
data.forEach(each=>{
switch (each) {
case station.code: {
newModal.controlled = true;
newModal.concentrateStationCode = this.editModel.code;
break;
}
}
});
this.$emit('updateMapModel', newModal);
});
} else {
this.chargeStation.forEach(station=>{
const newModal = Object.assign({}, station);
newModal.controlled = false;
newModal.concentrateStationCode = '';
this.$emit('updateMapModel', newModal);
});
}
this.edit();
},
changeCentralized(data) {
if (!data) {
this.editModel.chargeStationCodeList = [];
this.edit();
this.chargeStation.forEach(station=>{
const newModal = Object.assign({}, station);
newModal.controlled = false;
newModal.concentrateStationCode = '';
this.$emit('updateMapModel', newModal);
});
}
},
2019-11-29 12:51:58 +08:00
hover(field) {
this.field = field === this.field ? '' : field;
this.$emit('stationSectionCode', this.field);
},
create() {
this.$refs['make'].validate((valid) => {
if (valid) {
if (this.addModel.sectionCode) {
const uid = getUID('Station');
const model = {
_type: 'Station',
code: uid,
zcCode: '',
runPlanName: '',
visible: true,
nameFont: '14px consolas',
nameFontColor: '#FFFFFF',
kmPost: '1000km~2000km',
kmPostShow: true,
kmPostFont: '8px consolas',
kmPostFontColor: '#FFFFFF',
centralized: false,
2019-12-03 13:24:22 +08:00
concentrateStationCode: '',
controlled:false,
chargeStationCodeList:[]
2019-11-29 12:51:58 +08:00
};
this.sectionList.forEach(elem => {
if (elem.code === this.addModel.sectionCode) {
const l = 0;
const r = elem.points.length - 1;
model.name = 'Station_' + elem.name.replace('Station_', '');
model.position = {
x: elem.points[l].x + (elem.points[r].x - elem.points[l].x) / 2,
y: elem.points[l].y
};
}
});
this.$emit('updateMapModel', model);
}
}
});
},
// 修改对象
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()) {
const _that = this;
this.$confirm(this.$t('tip.confirmDeletion'), this.$t('tip.hint'), {
confirmButtonText: this.$t('tip.confirm'),
cancelButtonText: this.$t('tip.cancel'),
type: 'warning'
}).then(() => {
_that.$emit('updateMapModel', {...selected, _dispose: true});
_that.deviceSelect();
}).catch(() => {
_that.$message.info(this.$t('tip.cancelledDelete'));
});
}
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.view-control{
height: 100%;
}
.card {
height: 100%;
}
</style>