From c1d210b161d8bbbe65dea09723e9113def21c695 Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Wed, 7 Sep 2022 12:27:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=85=B0=20=E6=94=AF=E6=8C=81=E4=BA=A4?= =?UTF-8?q?=E6=8E=A5=20=E4=B8=8A=E7=BA=A7=E4=B8=8B=E7=BA=A7=20ID=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=20=E4=BC=98=E5=85=88=E7=BA=A7=E4=B8=BA=E4=B8=8A?= =?UTF-8?q?=E7=BA=A7=E4=B8=8B=E7=BA=A7=20ID=20=E2=80=94>=20=E6=94=B6?= =?UTF-8?q?=E6=A0=B7=E5=91=98=E8=87=AA=E5=AE=9A=E4=B9=89=E4=BA=A4=E6=8E=A5?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AMap/src/AMapDesigner/index.vue | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/components/AMap/src/AMapDesigner/index.vue b/src/components/AMap/src/AMapDesigner/index.vue index 7cda39e..c99d525 100644 --- a/src/components/AMap/src/AMapDesigner/index.vue +++ b/src/components/AMap/src/AMapDesigner/index.vue @@ -119,9 +119,11 @@ import { buildUUID } from '/@/utils/uuid'; import { RuleObject } from 'ant-design-vue/es/form/interface'; import { MapLogisticPoint } from '/@/api/platform/common/entity/mapLogisticPoint'; + import { isArray, isString } from '/@/utils/is'; /** 类型规范统一声明定义区域 */ interface MapState { + first: boolean; loading: boolean; defaultZoom: number; toggleOperatePanelClass: Recordable; @@ -171,6 +173,8 @@ const { notification } = useMessage(); const { mapDesigner } = componentSetting; const mapState = reactive({ + /** 首次初始化 */ + first: false, /** 遮罩层状态 */ loading: false, /** 默认缩放大小 */ @@ -492,6 +496,8 @@ if (map) { map.on('complete', () => { mapState.loading = false; + mapState.first = true; + setMapDataJson(mapProps.options); }); } } @@ -503,12 +509,11 @@ if (!mapProps.sidebarControl) mapState.toggleOperatePanelClass.siderWidth = 0; if (!mapProps.toolbarControl) mapState.toggleOperatePanelClass.toolbarHeight = 0; }); - watch(toRefs(mapProps).options, (newValue: MapLogistic) => { - nextTick(() => setMapDataJson(newValue)); - }, { - immediate: true, - deep: true - }); + watch(toRefs(mapProps).options, (newValue) => { + if (mapState.first) { + setMapDataJson(newValue); + } + }, { deep: true }); watch([() => mapState.mapData.sendOrderId, () => mapState.mapData.sendOrderTaskType], ([sendOrderIdValue,sendOrderTaskTypeValue], [sendOrderIdOldValue, sendOrderTaskTypeOldValue]) => { if (!sendOrderIdValue || !sendOrderTaskTypeValue) return; @@ -547,7 +552,7 @@ mapState.mapData.mapTask = [...taskOrdinaryData, ...taskPresetData]; } } - nextTick(() => handleMapPointGenerate()); + handleMapPointGenerate(); }); /** 处理切换操作面板 */ @@ -651,8 +656,8 @@ } /** 设置地图数据json */ - function setMapDataJson(mapData: MapLogistic) { - let options: Nullable = mapData; + function setMapDataJson(mapData: MapLogistic | string) { + let options: Nullable = mapData; if (typeof options === 'string') { try { options = eval('(' + options + ')'); @@ -667,6 +672,16 @@ handleMapReset(); nextTick(() => { mapState.mapData = cloneDeep(merge(defaultMapData(), options)); + // 处理数据格式转换 + isString(mapState.mapData.fileId) && (mapState.mapData.fileId = mapState.mapData.fileId.split(',')); + mapState.mapData.mapTask.forEach(item => { + isString(item.fileId) && (item.fileId = item.fileId.split(',')); + if (~~item.taskType == 1) { + item?.mapTaskPreset?.forEach(childItem => { + isString(childItem.fileId) && (childItem.fileId = childItem.fileId.split(',')); + }); + } + }); setTableData(mapState.mapData.mapTask); if (!isEmpty(mapState.mapData.mapLogisticPoint)) { drawMapNavigate(mapState.mapData.mapLogisticPoint); @@ -707,7 +722,7 @@ const pointData:MapLogisticPoint[] = []; mapState.mapData.mapTask.forEach(item => { const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId), - org = mapState.orgList.find(e => e.value == item.orgId); + org = item.orgId ? mapState.orgList.find(e => e.value == item.orgId) : {} as MapPointType; // 下级医院必选,也不能由收样员设置交接位置,所以必须查到,没有数据说明数据被更新过了 if (!hospital) { throw notification.error({ @@ -724,35 +739,37 @@ taskType: item.taskType, hospitalId: hospital.value, hospitalName: hospital.label - }, { + }, { lng: org?.mapLng, lat: org?.mapLat, type: '1', key: item.key, taskType: item.taskType, hospitalId: org?.value, - hospitalName: org?.label + hospitalName: org?.label ?? item.orgName }); }); // 查找并添加与自己有关的交接预设任务,只能添加设置了位置的标记点 await listMapTaskPreset({ size: 40, courierUserId: mapState.mapData.courierUserId }).then(res => { res.data?.map(item => { + const taskPresetHospital = item.orginPresetId ? mapState.hospitalList.find(e => e.value == item.orginPresetId) : {} as MapPointType, + taskPresetOrg = item.destinationPresetId ? mapState.orgList.find(e => e.value == item.destinationPresetId) : {} as MapPointType; pointData.push({ - lng: item.orginPresetLng, - lat: item.orginPresetLat, + lng: taskPresetHospital?.mapLng ?? item.orginPresetLng, + lat: taskPresetHospital?.mapLat ?? item.orginPresetLat, type: '0', taskType: '1', mapTaskId: item.id, - hospitalId: item.orginPresetId, - hospitalName: item.orginPresetName + hospitalId: taskPresetHospital?.value ?? item.orginPresetId, + hospitalName: taskPresetHospital?.label ?? item.orginPresetName }, { - lng: item.destinationPresetLng, - lat: item.destinationPresetLat, + lng: taskPresetOrg?.mapLng ?? item.destinationPresetLng, + lat: taskPresetOrg?.mapLat ?? item.destinationPresetLat, type: '1', taskType: '1', mapTaskId: item.id, - hospitalId: item.destinationPresetId, - hospitalName: item.destinationPresetName + hospitalId: taskPresetOrg?.value ?? item.destinationPresetId, + hospitalName: taskPresetOrg?.label ?? item.destinationPresetName }); }); }); @@ -773,7 +790,7 @@ async function handleMapSave() { await formElRef.value.validate(); const mapData = toRaw(mapState.mapData); - mapData.fileId = (mapData.fileId as[])?.join(','); + isArray(mapData.fileId) && (mapData.fileId = mapData.fileId.join(',')); mapData.mapTask.forEach(item => { const hospital = item.hospitalId && mapState.hospitalList.find(e => e.value == item.hospitalId), org = item.orgId && mapState.orgList.find(e => e.value == item.orgId); @@ -788,7 +805,7 @@ orgLng: org.mapLng, orgLat: org.mapLat }); - item.fileId = (item.fileId as [])?.join(','); + isArray(item.fileId) && (item.fileId = item.fileId.join(',')); if (~~item.taskType == 1) { item?.mapTaskPreset?.forEach(childItem => { const childHospital = childItem.orginPresetId && mapState.hospitalList.find(e => e.value == childItem.orginPresetId), @@ -804,7 +821,7 @@ destinationPresetLng: childOrg.mapLng, destinationPresetLat: childOrg.mapLat }); - childItem.fileId = (childItem.fileId as [])?.join(','); + isArray(childItem.fileId) && (childItem.fileId = childItem.fileId.join(',')); }); } });