From 94471f28b041645e0c769d1843ae18586c29ad1b Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Sat, 11 Jun 2022 22:26:15 +0800 Subject: [PATCH] =?UTF-8?q?:fire:=20=E9=AB=98=E5=BE=B7=E5=9C=B0=E5=9B=BE?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=AE=A1=E7=AE=97=E8=A7=84=E5=88=92=E8=B7=AF?= =?UTF-8?q?=E7=BA=BF=E7=AE=97=E6=B3=95=20todo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AMap/src/TaskModal.vue | 77 ++++++++++++++++++--------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/src/components/AMap/src/TaskModal.vue b/src/components/AMap/src/TaskModal.vue index 9bfe079..ab5cb08 100644 --- a/src/components/AMap/src/TaskModal.vue +++ b/src/components/AMap/src/TaskModal.vue @@ -34,6 +34,7 @@ import { BasicTable, useTable, EditRecordRow, BasicColumn, ActionItem, TableAction } from '/@/components/Table'; import { formTaskColumns, formSchemeColumns, largeHospitalMapList, smallHospitalMapList, } from './map.data'; import { buildUUID } from '/@/utils/uuid'; + import { add, divide } from 'lodash-es'; /** 类型规范统一声明定义区域 */ interface WindowState { @@ -151,46 +152,70 @@ const scheme = []; const origin = state.formData.takeSpecimenId; + // 抽离计算属性 const taskDataSource = getDataSource(); - const smallHospitals = Array(); - const largeHospitals = Array(); - taskDataSource.forEach(item => { + const smallHospitalPositions = Array(); + const largeHospitalPositions = Array(); + taskDataSource.forEach(item => { + // 任务上下级医院唯一匹配ID const key = buildUUID(); - smallHospitals.push({ - key: key, - smallHospitalId: item.smallHospitalId, - workable: false - }); - largeHospitals.push({ - key: key, - largeHospitalId: item.largeHospitalId, - workable: false - }); + const smallHospital = smallHospitalMapList.find(index => index.id == item.smallHospitalId); + if(smallHospital) smallHospitalPositions.push([key, new AMap.LngLat(smallHospital.lng, smallHospital.lat)]); + const largeHospital = largeHospitalMapList.find(index => index.id == item.largeHospitalId); + if(largeHospital) largeHospitalPositions.push([key, new AMap.LngLat(largeHospital.lng, largeHospital.lat)]); }); // 途径点 const waypoints = Array(); // 目的地 let destination; - - - // 循环计算出最优方案 - smallHospitals.forEach(small => { - const smallHospital = smallHospitalMapList.find(index => index.id == small.smallHospitalId); - if(smallHospital) { - small.workable = true; - waypoints.push(new AMap.LngLat(smallHospital.lng, smallHospital.lat)); + // 下级医院规划方案二维数组,默认填充0数据 + const smallHospitalScheme = Array.from({ length: smallHospitalPositions.length }, () => Array(smallHospitalPositions.length).fill(0)); + for(let i = 0; i < smallHospitalPositions.length; ++i) { + // 提取一维数组,方案索引 + const oneDimensionArray = smallHospitalScheme[i]; + // 推动数组位置坐标,实现让每个方案的坐标位置都不一致 + let indexs = Object.keys(smallHospitalPositions); + const reverseIndexs = indexs.slice(0, i); + indexs.splice(0, i); + indexs.push(...reverseIndexs); + // 处理二维数组坐标位置存储 + for(let j = 0; j < indexs.length; ++j) { + const index = indexs[j]; + const smallHospitalPosition = smallHospitalPositions[index]; + oneDimensionArray[j] = smallHospitalPosition; } - largeHospitals.forEach(large => { - const largeHospital = largeHospitalMapList.find(index => index.id == large.largeHospitalId); - largeHospital + } - }); - }) + // 计算不重复插入匹配上级医院 + for (let i = 0; i < smallHospitalScheme.length; ++i) { + } + // 计算下级医院组合次数 + for(let i = 0; i < smallHospitals.length; ++i) { + const composeCycle = add(i,1); + const hospitalCycle = Math.ceil(divide(smallHospitals.length, composeCycle)); + for(let j = 0; j < hospitalCycle; ++j) { + for(let k = 0; k < composeCycle; ++k) { + const index = add(j, k); + const small = smallHospitals[index]; + const smallHospital = smallHospitalMapList.find(index => index.id == small.smallHospitalId); + if(smallHospital) waypoints.push([small.key, new AMap.LngLat(smallHospital.lng, smallHospital.lat)]); + } + for (let k = 0; k < ; ++k) { + } + largeHospitals.forEach(large => { + // 匹配下级医院,当存在时才能存放上级医院途径点,需求必须要在下级医院取完标本才能送往上级医院 + if(waypoints.find(waypoint => waypoint[0] == large.key)){ + const largeHospital = largeHospitalMapList.find(index => index.id == large.largeHospitalId); + if(largeHospital) waypoints.push([large.key, new AMap.LngLat(largeHospital.lng, largeHospital.lat)]); + } + }); + } + } }