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

275 lines
10 KiB
Vue
Raw Normal View History

2020-03-04 20:59:16 +08:00
<template>
<el-tabs v-model="activeName" class="card" @tab-click="handleClick">
<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">
<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';
import { getAutoReentryList} from '@/api/jmap/mapdraft';
export default {
2020-03-05 15:48:51 +08:00
name: 'MapCycleButtonVO',
2020-03-04 20:59:16 +08:00
components: {
ConfigList,
ConfigData
},
props: {
selected: {
type: Object,
default: function () {
return null;
}
}
},
data() {
return {
activeName: 'first',
autoList: [],
editModel: {
code: '',
name: '',
subtitleName: '', //副标题
2020-03-05 15:48:51 +08:00
cycleCode: '', // 关联自动折返code
2020-03-04 20:59:16 +08:00
position: {
x: 0,
y: 0
}
},
addModel: {
code: '',
name: '',
subtitleName: '', // 副标题
2020-03-05 15:48:51 +08:00
cycleCode: '', // 关联自动折返code
2020-03-04 20:59:16 +08:00
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' }
],
2020-03-05 15:48:51 +08:00
cycleCode:[
2020-03-04 20:59:16 +08:00
{ 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', [
2020-03-05 15:48:51 +08:00
'cycleButtonList'
2020-03-04 20:59:16 +08:00
]),
form() {
const form = {
labelWidth: '150px',
items: {
code: {
name: '',
item: []
},
draw: {
name: this.$t('map.drawData'),
item: [
2020-03-05 15:48:51 +08:00
{ prop: 'code', label: `${this.$t('map.code')}`, type: 'select', optionLabel: 'name&&code', optionValue: 'code', options: this.cycleButtonList, change: true, deviceChange: this.deviceChange },
{ prop: 'name', label: '标题名称:', type: 'input' },
{ prop: 'subtitleName', label: '副标题名称:', type: 'input' },
{ prop: 'position', label: '坐标:', type: 'coordinate', width: '140px', children: [
2020-03-04 20:59:16 +08:00
{ 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' }
] },
2020-03-05 15:48:51 +08:00
{ prop:'cycleCode', label: '自动折返进路code:', type: 'select', optionLabel: 'name', optionValue: 'code', options: this.autoList },
2020-03-04 20:59:16 +08:00
]
}
}
};
return form;
},
formMake() {
const form = {
labelWidth: '150px',
items: [
2020-03-05 15:48:51 +08:00
{ prop:'cycleCode', label: '自动折返进路:', type: 'select', optionLabel: 'name', optionValue: 'code', options: this.autoList },
2020-03-04 20:59:16 +08:00
{ prop: 'name', label: '自动折返名称:', type: 'input' },
{ prop: 'subtitleName', label: '副标题名称:', type: 'input' },
{ prop: 'position', label: '坐标:', type: 'coordinate', width: '140px', 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' }
2020-03-04 20:59:16 +08:00
] },
]
};
return form;
},
createRules: function () {
return {
2020-03-05 15:48:51 +08:00
cycleCode: [
2020-03-04 20:59:16 +08:00
{ required: true, message: '请选择自动折返进路', trigger: 'change' }
],
name: [
{ required: true, message: '请输入名称', trigger: 'blur' }
],
'position.x': [
{ required: true, message: this.$t('rules.trainPositionX'), trigger: 'blur' }
],
'position.y': [
{ required: true, message: this.$t('rules.trainPositionY'), trigger: 'blur' }
]
};
}
},
watch: {
selected(val, oldVal) {
this.deviceSelect(val);
}
},
mounted() {
this.getAutoMaticList();
},
methods: {
deviceChange(code) {
this.$emit('setCenter', code);
this.deviceSelect(this.$store.getters['map/getDeviceByCode'](code));
},
handleClick() {
this.getAutoMaticList();
},
deviceSelect(selected) {
this.$refs.dataform.resetFields();
this.$refs.make.resetFields();
2020-03-05 15:48:51 +08:00
if (selected && selected._type.toUpperCase() === 'MapCycleButtonVO'.toUpperCase()) {
2020-03-04 20:59:16 +08:00
this.activeName = 'first';
this.editModel = deepAssign(this.editModel, selected);
}
},
async getAutoMaticList() {
const params = {
pageSize: 9999,
pageNum: 1
};
const resp = await getAutoReentryList(this.$route.params.mapId, params);
this.autoList = resp.data.list;
},
// 创建对象
create() {
this.$refs.make.validate((valid) => {
if (valid) {
2020-03-05 15:48:51 +08:00
const uid = getUID('MapCycleButtonVO', this.cycleButtonList);
2020-03-04 20:59:16 +08:00
let models = [];
const model = {
2020-03-05 15:48:51 +08:00
_type: 'MapCycleButtonVO',
2020-03-04 20:59:16 +08:00
code: uid,
name: this.addModel.name,
subtitleName: this.addModel.subtitleName,
2020-03-04 20:59:16 +08:00
position: {
x: this.addModel.position.x,
y: this.addModel.position.y
},
2020-03-05 15:48:51 +08:00
cycleCode:this.addModel.cycleCode
2020-03-04 20:59:16 +08:00
};
models.push(model);
this.$emit('updateMapModel', models);
this.$refs.make.resetForm();
}
});
},
// 修改对象
edit() {
this.$refs['dataform'].validate((valid) => {
if (valid) {
2020-03-05 15:48:51 +08:00
const data = Object.assign({_type: 'MapCycleButtonVO'}, this.editModel);
2020-03-04 20:59:16 +08:00
let models = [data];
this.$emit('updateMapModel', models);
}
});
},
// 删除对象
deleteObj() {
const selected = this.$store.getters['map/getDeviceByCode'](this.editModel.code);
2020-03-05 15:48:51 +08:00
if (selected && selected._type.toUpperCase() === 'MapCycleButtonVO'.toUpperCase()) {
2020-03-04 20:59:16 +08:00
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%;
}
.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>