diff --git a/src/components/AMap/src/AMapDesigner/index.vue b/src/components/AMap/src/AMapDesigner/index.vue index 1b6b0ec..a63417a 100644 --- a/src/components/AMap/src/AMapDesigner/index.vue +++ b/src/components/AMap/src/AMapDesigner/index.vue @@ -633,7 +633,7 @@ mapState.mapData.courierUserName = courierUserMap.label; mapState.mapData.courierLng = courierUserMap.mapLng; mapState.mapData.courierLat = courierUserMap.mapLat; - drawMapNavigate(concat(mapState.mapData.mapLogisticPoint, mapState.mapData.mapTaskPresetLogisticPoint)); + handleMapPointGenerate(); } else notification.warn({ message: '查找不到起点数据,请检查起点!', duration: 2 @@ -744,62 +744,63 @@ /** 绘制地图导航路线 */ function drawMapNavigate(points: MapLogisticPoint[] = []) { - debugger + if (isEmpty(points) && mapState.mapData.courierUserId && mapState.mapData.courierLng && mapState.mapData.courierLat) + throw console.warn('检查到当前起点数据为空或标记点集合为空,请选择起点!'); points = points.filter(item => item.lng && item.lat); - if (points.length > 0 && mapState.mapData.courierLng && mapState.mapData.courierLat) { - const lngLats = points.map(item => new AMap.LngLat(item.lng, item.lat)); - const destination = lngLats.pop(); - destination && driving.search(new AMap.LngLat(mapState.mapData.courierLng, mapState.mapData.courierLat), destination, { - waypoints: lngLats - }, function(status, result) { - notification.success({ - message: status === 'complete' ? '绘制地图路线完成!' : `获取地图数据失败:${result}`, - duration: 2 - }); + const lngLats = points.map(item => new AMap.LngLat(item.lng, item.lat)); + const destination = lngLats.pop(); + destination && driving.search(new AMap.LngLat(mapState.mapData.courierLng, mapState.mapData.courierLat), destination, { + waypoints: lngLats + }, function(status, result) { + notification.success({ + message: status === 'complete' ? '绘制地图路线完成!' : `获取地图数据失败:${result}`, + duration: 2 }); - } + }); } /** 处理地图标记点生成 */ async function handleMapPointGenerate() { setTableData(mapState.mapData.mapTask); - const pointData:MapLogisticPoint[] = []; - mapState.mapData.mapTask.forEach(item => { - const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId), + if (mapState.mapData.courierUserId) { + const pointData:MapLogisticPoint[] = []; + mapState.mapData.mapTask.forEach(item => { + const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId), org = item.orgId ? mapState.orgList.find(e => e.value == item.orgId) : {} as MapPointType; - // 下级医院必选,也不能由收样员设置交接位置,所以必须查到,没有数据说明数据被更新过了 - if (!hospital) { - throw notification.error({ - message: '地图标记点生成错误', - description: '当前机构数据或者医院数据已经更新,请重新刷新页面!', - duration: 2 + // 下级医院必选,也不能由收样员设置交接位置,所以必须查到,没有数据说明数据被更新过了 + if (!hospital) { + throw notification.error({ + message: '地图标记点生成错误', + description: '当前机构数据或者医院数据已经更新,请重新刷新页面!', + duration: 2 + }); + } + pointData.push({ + lng: hospital.mapLng, + lat: hospital.mapLat, + type: '0', + key: item.key, + taskType: item.taskType, + hospitalId: hospital.value, + hospitalName: hospital.label, + courierUserId: mapState.mapData.courierUserId + }, { + lng: org?.mapLng, + lat: org?.mapLat, + type: '1', + key: item.key, + taskType: item.taskType, + hospitalId: org?.value, + hospitalName: org?.label ?? item.orgName, + courierUserId: mapState.mapData.courierUserId, }); - } - pointData.push({ - lng: hospital.mapLng, - lat: hospital.mapLat, - type: '0', - key: item.key, - taskType: item.taskType, - hospitalId: hospital.value, - hospitalName: hospital.label, - courierUserId: mapState.mapData.courierUserId - }, { - lng: org?.mapLng, - lat: org?.mapLat, - type: '1', - key: item.key, - taskType: item.taskType, - hospitalId: org?.value, - hospitalName: org?.label ?? item.orgName, - courierUserId: mapState.mapData.courierUserId, }); - }); - // 查找并添加与自己有关的交接预设任务,只能添加设置了位置的标记点 - mapState.mapData.mapTaskPresetLogisticPoint = await getTaskPresetPointByCourierUserId(mapState.mapData.courierUserId); - pointData.forEach((item, index)=> item.sort = add(index, 1)); - mapState.mapData.mapLogisticPoint = pointData; - drawMapNavigate(concat(mapState.mapData.mapLogisticPoint, mapState.mapData.mapTaskPresetLogisticPoint)); + // 查找并添加与自己有关的交接预设任务,只能添加设置了位置的标记点 + pointData.forEach((item, index)=> item.sort = add(index, 1)); + mapState.mapData.mapLogisticPoint = pointData; + mapState.mapData.courierUserId && (mapState.mapData.mapTaskPresetLogisticPoint = await getTaskPresetPointByCourierUserId(mapState.mapData.courierUserId)); + drawMapNavigate(concat(mapState.mapData.mapLogisticPoint, mapState.mapData.mapTaskPresetLogisticPoint)); + } } /** 处理地图标记点数据 */