rt-sim-training-client/src/views/newMap/newMapdraft/mapoperate/stationcontrol.vue
joylink_cuiweidong 6426a70bd6 代码调整
2019-12-03 15:30:41 +08:00

262 lines
10 KiB
Vue

<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" :model="addModel" label-width="120px" size="mini" :rules="makeRules">
<el-form-item :label="$t('map.stationstandName')" prop="stationCode">
<el-select v-model="addModel.stationCode" filterable multiple style="width: 350px;">
<el-option
v-for="item in stationList"
:key="item.code"
:label="item.name + ' (' + item.code+ ')'"
:value="item.code"
/>
</el-select>
</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: 'StationControlDraft',
components: {
ConfigList
},
props: {
selected: {
type: Object,
default: function () {
return null;
}
}
},
data() {
return {
activeName: 'first',
editModel: {
code: '',
name: '',
position: {
x: 0,
y: 0
},
stationCode: ''
// zokContent: '',
// zakContent: '',
// jjzkContent: '',
// zbjkContent: '',
// zzkContent: '',
// lskContent: ''
},
addModel: {
stationCode: []
},
makeRules: {
stationCode: [
{ required: true, message: this.$t('rules.stationControlStationName'), trigger: 'change' }
]
}
};
},
computed: {
...mapGetters('map', [
'stationList',
'stationControlList',
'lineCode'
]),
form() {
const form = {
labelWidth: '160px',
items: {
code: {
name: '',
item: []
},
draw: {
name: this.$t('map.drawData'),
item: [
{ prop: 'code', label: this.$t('map.stationControlCode'), type: 'select', optionLabel: 'code', optionValue: 'code', options: this.stationControlList, change: true, deviceChange: this.deviceChange },
// { prop: 'zokContent', label: this.$t('map.zokContent'), type: 'input' },
// { prop: 'zakContent', label: this.$t('map.zakContent'), type: 'input' },
// { prop: 'jjzkContent', label: this.$t('map.jjzkContent'), type: 'input' },
// { prop: 'zzkContent', label: this.$t('map.zzkContent'), type: 'input' },
// { prop: 'lskContent', label: `${this.$t('map.interconnected')}:`, type: 'input' },
{ prop: 'position', label: this.$t('map.stationControlPosition'), type: 'coordinate', width: '150px', children: [
{ prop: 'position.x', firstLevel: 'position', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px', change:true, deviceChange:this.updateView },
{ prop: 'position.y', firstLevel: 'position', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px', change:true, deviceChange:this.updateView }
] }
]
},
map: {
name: this.$t('map.mapData'),
item: [
{ prop: 'stationCode', label: this.$t('map.equipmentStation'), type: 'select', optionLabel: 'name&&code', optionValue: 'code', options: this.stationList, change: true, deviceChange:this.updateView}
]
}
}
};
return form;
},
rules() {
const rules = {
code: [
{ required: true, message: this.$t('rules.selectEquipment'), trigger: 'change' }
],
stationCode: [
{ required: true, message: this.$t('rules.stationControlStationCode'), trigger: 'change' }
],
// zokContent: [
// { required: true, message: this.$t('rules.stationControlZokContent'), trigger: 'blur' }
// ],
// zakContent: [
// { required: true, message: this.$t('rules.stationControlZakContent'), trigger: 'blur' }
// ],
// jjzkContent: [
// { required: true, message: this.$t('rules.stationControlJjzkContent'), trigger: 'blur' }
// ],
// zzkContent: [
// { required: true, message: this.$t('rules.stationControlZzkContent'), trigger: 'blur' }
// ],
'position.x': [
{ required: true, message: this.$t('rules.stationControlPositionX'), trigger: 'blur' }
],
'position.y': [
{ required: true, message: this.$t('rules.stationControlPositionY'), trigger: 'blur' }
]
};
// 清空表单验证提示信息
this.$nextTick(() => {
this.$refs.dataform &&
this.$refs.dataform.clearValidate();
});
return rules;
}
},
watch: {
selected(val, oldVal) {
this.deviceSelect(val);
}
},
mounted() {
},
methods: {
deviceChange(code) {
this.$emit('setCenter', code);
this.deviceSelect(this.$store.getters['map/getDeviceByCode'](code));
this.edit();
},
updateView() {
this.edit();
},
deviceSelect(selected) {
this.$refs.dataform.resetFields();
this.$refs.make.resetFields();
if (selected && selected._type.toUpperCase() === 'StationControl'.toUpperCase()) {
this.activeName = 'first';
this.editModel = deepAssign(this.editModel, selected);
} else if (selected && selected._type.toUpperCase() === 'Station'.toUpperCase()) {
this.addModel.stationCode = selected.code;
}
},
create() {
this.$refs['make'].validate((valid) => {
if (valid) {
if (this.addModel.stationCode.length) {
const models = [];
this.addModel.stationCode.forEach(item => {
const uid = getUID('StationControl');
const model = {
_type: 'StationControl',
code: uid
// zokContent: '中控',
// zbjkContent: '总报警',
// zakContent: '站控',
// jjzkContent: '紧急站控',
// zzkContent: '站中控按钮',
// lskContent: '连锁控'
};
this.stationList.forEach(elem => {
if (elem.code === item) {
model.name = 'StationControl_' + elem.name.replace('Station_', '');
model.position = { x: elem.position.x, y: elem.position.y + 30 };
model.stationCode = elem.code;
}
});
models.push(model);
});
this.$emit('updateMapModel', models);
} else {
this.$messageBox(this.$t('tip.selectedStationEmpty'));
}
}
});
},
// 修改对象
edit() {
this.$refs['dataform'].validate((valid) => {
if (valid) {
const data = Object.assign({_type: 'StationControl'}, this.editModel);
this.$emit('updateMapModel', data);
}
});
},
// 删除对象
deleteObj() {
const selected = this.$store.getters['map/getDeviceByCode'](this.editModel.code);
if (selected && selected._type.toUpperCase() === 'StationControl'.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>