2019-07-25 10:30:30 +08:00
|
|
|
<template>
|
2019-08-22 10:25:23 +08:00
|
|
|
<el-dialog :title="$t('map.mapEditor')" :visible.sync="dialogShow" :close-on-click-modal="false" width="30%" :before-close="handleClose">
|
2019-07-25 10:30:30 +08:00
|
|
|
<div>
|
|
|
|
<template v-if="basicInfo">
|
|
|
|
<el-form
|
|
|
|
ref="edit"
|
|
|
|
label-position="right"
|
|
|
|
:model="editModel"
|
|
|
|
:rules="editRules"
|
|
|
|
label-width="120px"
|
|
|
|
size="mini"
|
|
|
|
@submit.native.prevent
|
|
|
|
>
|
2019-08-14 09:35:38 +08:00
|
|
|
<el-form-item :label="$t('map.skinName')" prop="skinCode">
|
|
|
|
<el-select v-model="editModel.skinCode" :placeholder="$t('map.pleaseSelect')" size="mini">
|
2019-07-25 10:30:30 +08:00
|
|
|
<el-option
|
2019-08-14 16:37:17 +08:00
|
|
|
v-for="item in skinCodeList"
|
2019-07-25 10:30:30 +08:00
|
|
|
:key="item.code"
|
|
|
|
:label="item.name"
|
|
|
|
:value="item.code"
|
|
|
|
/>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
2019-08-23 09:14:21 +08:00
|
|
|
<el-form-item :label="$t('map.mapName')" prop="name">
|
|
|
|
<el-input v-model="editModel.name" />
|
|
|
|
</el-form-item>
|
2019-07-25 10:30:30 +08:00
|
|
|
</el-form>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<el-form
|
|
|
|
ref="updt"
|
|
|
|
label-position="right"
|
|
|
|
:model="updtModel"
|
|
|
|
:rules="updtRules"
|
|
|
|
label-width="120px"
|
|
|
|
size="mini"
|
|
|
|
@submit.native.prevent
|
|
|
|
>
|
2019-08-09 15:40:33 +08:00
|
|
|
<el-form-item :label="$t('map.offsetXColon')" :prop="'origin.x'">
|
2019-08-22 10:25:23 +08:00
|
|
|
<el-input v-model="updtModel.origin.x" :label="$t('map.offsetX')" disabled />
|
2019-07-25 10:30:30 +08:00
|
|
|
</el-form-item>
|
2019-08-09 15:40:33 +08:00
|
|
|
<el-form-item :label="$t('map.offsetYColon')" :prop="'origin.y'">
|
2019-08-22 10:25:23 +08:00
|
|
|
<el-input v-model="updtModel.origin.y" :label="$t('map.offsetY')" disabled />
|
2019-07-25 10:30:30 +08:00
|
|
|
</el-form-item>
|
2019-08-09 15:40:33 +08:00
|
|
|
<el-form-item :label="$t('map.scalingColon')" prop="scaling">
|
2019-08-22 10:25:23 +08:00
|
|
|
<el-input-number v-model="updtModel.scaling" :precision="1" :step="0.2" disabled />
|
2019-07-25 10:30:30 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<span slot="footer" class="dialog-footer">
|
2019-08-09 15:40:33 +08:00
|
|
|
<el-button @click="dialogShow = false">{{ $t('map.cancel') }}</el-button>
|
|
|
|
<el-button type="primary" :loading="loading" @click="save">{{ $t('map.confirm') }}</el-button>
|
2019-07-25 10:30:30 +08:00
|
|
|
</span>
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { updateMap, getMapDetail } from '@/api/jmap/mapdraft';
|
2019-08-14 16:37:17 +08:00
|
|
|
import { getSkinCodeList } from '@/api/management/mapskin';
|
2019-08-21 18:49:39 +08:00
|
|
|
import { saveMap } from '@/api/jmap/mapdraft';
|
2019-07-25 10:30:30 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'MapEdit',
|
|
|
|
props: {
|
|
|
|
map: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
basicInfo: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
default: function () {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
2019-08-14 09:35:38 +08:00
|
|
|
skinCode: {
|
2019-07-25 10:30:30 +08:00
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dialogShow: false,
|
|
|
|
loading: false,
|
2019-08-14 16:37:17 +08:00
|
|
|
skinCodeList: [],
|
2019-07-25 10:30:30 +08:00
|
|
|
cityList: [],
|
|
|
|
editModel: {
|
|
|
|
id: '',
|
|
|
|
name: '',
|
2019-08-23 09:14:21 +08:00
|
|
|
skinCode: '01',
|
2019-07-25 10:30:30 +08:00
|
|
|
cityCode: ''
|
|
|
|
},
|
|
|
|
updtModel: {
|
|
|
|
code: '',
|
|
|
|
scaling: '',
|
|
|
|
origin: {
|
|
|
|
x: '',
|
|
|
|
y: ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isUpdate: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
editRules() {
|
|
|
|
return {
|
|
|
|
name: [
|
2019-08-19 15:53:14 +08:00
|
|
|
{ required: true, message: this.$t('rules.pleaseEnterMapName'), trigger: 'blur' }
|
2019-07-25 10:30:30 +08:00
|
|
|
],
|
2019-08-14 09:35:38 +08:00
|
|
|
skinCode: [
|
2019-08-19 15:53:14 +08:00
|
|
|
{ required: true, message: this.$t('rules.pleaseSelectAssociatedSkin'), trigger: 'change' }
|
2019-07-25 10:30:30 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
|
|
|
updtRules() {
|
|
|
|
return {
|
2019-08-21 18:49:39 +08:00
|
|
|
'origin.x': [
|
2019-09-17 13:16:49 +08:00
|
|
|
{ required: true, message: this.$t('rules.enterXOffset'), trigger: 'blur' }
|
2019-07-25 10:30:30 +08:00
|
|
|
],
|
2019-08-21 18:49:39 +08:00
|
|
|
'origin.y': [
|
2019-09-17 13:16:49 +08:00
|
|
|
{ required: true, message: this.$t('rules.enterYOffset'), trigger: 'blur' }
|
2019-08-21 18:49:39 +08:00
|
|
|
],
|
|
|
|
scaling: [
|
|
|
|
{ required: true, message: this.$t('rules.enterScale'), trigger: 'blur' }
|
2019-07-25 10:30:30 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
map: function (val, old) {
|
|
|
|
if (val) {
|
|
|
|
Object.assign(this.editModel, this.map);
|
|
|
|
}
|
|
|
|
},
|
2019-07-29 17:57:00 +08:00
|
|
|
'$store.state.map.mapDataLoadedCount': function () {
|
2019-08-14 09:35:38 +08:00
|
|
|
if (this.$jlmap.skinCode) {
|
2019-07-29 17:57:00 +08:00
|
|
|
this.isUpdate = true;
|
|
|
|
}
|
2019-07-25 10:30:30 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.initLoadData();
|
|
|
|
},
|
|
|
|
methods: {
|
2019-08-27 15:02:55 +08:00
|
|
|
show(type) {
|
2019-08-22 10:25:23 +08:00
|
|
|
const dataZoom = this.$store.state.map.dataZoom;
|
2019-08-27 15:02:55 +08:00
|
|
|
if (type == 'editCode') {
|
|
|
|
this.editModel.skinCode = this.editModel.skinCode ? this.editModel.skinCode : '';
|
|
|
|
this.editModel.name = this.editModel.name ? this.editModel.name : '';
|
|
|
|
} else if (type == 'editPoint') {
|
|
|
|
if (dataZoom && dataZoom.offsetX) {
|
|
|
|
this.updtModel.origin.x = Number.parseInt(dataZoom.offsetX);
|
|
|
|
this.updtModel.origin.y = Number.parseInt(dataZoom.offsetY);
|
|
|
|
this.updtModel.scaling = dataZoom.scaleRate;
|
|
|
|
}
|
2019-07-25 10:30:30 +08:00
|
|
|
}
|
2019-08-27 15:02:55 +08:00
|
|
|
|
2019-07-25 10:30:30 +08:00
|
|
|
this.dialogShow = true;
|
|
|
|
},
|
|
|
|
close() {
|
|
|
|
if (this.basicInfo) {
|
|
|
|
this.$refs.edit.resetFields();
|
|
|
|
} else {
|
|
|
|
this.$refs.updt.resetFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dialogShow = false;
|
|
|
|
},
|
|
|
|
handleClose() {
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
save() {
|
|
|
|
this.loading = true;
|
|
|
|
if (this.basicInfo) {
|
2019-08-27 15:02:55 +08:00
|
|
|
// this.editModel.id = this.$route.params.mapId;
|
2019-07-25 10:30:30 +08:00
|
|
|
this.$refs['edit'].validate((valid) => {
|
|
|
|
if (valid) {
|
|
|
|
updateMap(this.editModel).then(response => {
|
|
|
|
this.loading = false;
|
|
|
|
if (this.isUpdate && this.$route.params.mapId) {
|
|
|
|
getMapDetail(this.$route.params.mapId).then(response => {
|
|
|
|
this.$store.dispatch('map/setMapData', response.data);
|
|
|
|
});
|
|
|
|
}
|
2019-08-09 15:40:33 +08:00
|
|
|
this.$message.success(this.$t('map.mapUpdateSuccessful'));
|
2019-07-25 10:30:30 +08:00
|
|
|
this.$emit('refresh');
|
|
|
|
this.close();
|
|
|
|
}).catch(error => {
|
|
|
|
this.loading = false;
|
2019-08-09 15:40:33 +08:00
|
|
|
this.$message.error(this.$t('map.operationUnusual') + error.message);
|
2019-07-25 10:30:30 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2019-08-14 09:35:38 +08:00
|
|
|
this.updtModel.code = this.skinCode;
|
2019-08-21 18:49:39 +08:00
|
|
|
const map = this.$store.state.map.map;
|
2019-07-25 10:30:30 +08:00
|
|
|
this.$refs['updt'].validate((valid) => {
|
|
|
|
if (valid) {
|
2019-08-21 18:49:39 +08:00
|
|
|
this.$store.dispatch('map/saveMapDeviceDefaultRelations').then(() => {
|
|
|
|
const param = {
|
|
|
|
mapId: this.$route.params.mapId,
|
|
|
|
skinVO: {
|
|
|
|
code: this.$store.state.map.map.skinVO.code,
|
2019-08-21 18:51:16 +08:00
|
|
|
name: this.$store.state.map.map.skinVO.name,
|
2019-08-21 18:49:39 +08:00
|
|
|
origin: {
|
|
|
|
x: this.updtModel.origin.x,
|
|
|
|
y: this.updtModel.origin.y
|
|
|
|
},
|
|
|
|
scaling: this.updtModel.scaling
|
|
|
|
}
|
|
|
|
};
|
|
|
|
saveMap(Object.assign(map, param)).then(response => {
|
|
|
|
this.loading = false;
|
|
|
|
this.close();
|
|
|
|
this.$message.success(this.$t('map.updateSuccessfully'));
|
|
|
|
}).catch(() => {
|
|
|
|
this.loading = false;
|
|
|
|
this.$messageBox(this.$t('map.updateFailed'));
|
|
|
|
});
|
2019-07-25 10:30:30 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
initLoadData() {
|
|
|
|
this.cityList = [];
|
2019-08-01 15:19:24 +08:00
|
|
|
this.$Dictionary.cityType().then(list => {
|
|
|
|
this.cityList = list;
|
|
|
|
}).catch(() => {
|
2019-08-09 15:40:33 +08:00
|
|
|
this.$messageBox(this.$t('map.failedLoadCityList'));
|
2019-08-01 15:19:24 +08:00
|
|
|
});
|
2019-07-25 10:30:30 +08:00
|
|
|
|
2019-08-14 16:37:17 +08:00
|
|
|
this.skinCodeList = [];
|
|
|
|
getSkinCodeList().then(response => {
|
|
|
|
this.skinCodeList = response.data;
|
2019-07-25 10:30:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|