From 07553918d0fc0abac06210f8c5c52f8a0ca391b0 Mon Sep 17 00:00:00 2001 From: Taric Xin Date: Fri, 4 Mar 2022 14:56:56 +0800 Subject: [PATCH] edit --- .../vehicle-detail-change.component.html | 4 +-- .../vehicle-detail-change.component.ts | 23 +++++++------- .../amap-poi-picker.component.ts | 30 ++++++++++++++----- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/app/routes/order-management/components/vehicle-detail-change/vehicle-detail-change.component.html b/src/app/routes/order-management/components/vehicle-detail-change/vehicle-detail-change.component.html index 1901a4c1..37eae198 100644 --- a/src/app/routes/order-management/components/vehicle-detail-change/vehicle-detail-change.component.html +++ b/src/app/routes/order-management/components/vehicle-detail-change/vehicle-detail-change.component.html @@ -75,7 +75,7 @@ { - this.totalDistance = res.distance; - this.totalTime = res.time; - }); - } + // 计算里程,时间 + if (this.startInfo?.[0]?.area && this.endInfo?.[0]?.area) { + this.amapService.drivingCompute([...this.startInfo], [...this.endInfo]).subscribe(res => { + this.totalDistance = res.distance; + this.totalTime = res.time; + }); + } } }); } @@ -560,12 +560,13 @@ export class OrderManagementVehicleDetailChangeComponent implements OnInit { } // -------------------装卸货信息处理 // 打开地图 - openMap(type: string, index: number) { + openMap(type: string, index: number, address: string) { console.log(type); console.log(index); - + const modalRef = this.modalService.create({ nzTitle: '', + nzComponentParams: { selectedAddress: address }, nzContent: AmapPoiPickerComponent, nzWidth: 900, nzOnOk: item => { @@ -883,8 +884,8 @@ export class OrderManagementVehicleDetailChangeComponent implements OnInit { } console.log(elf); } - // 装卸货地址互换 - swapAddress() { + // 装卸货地址互换 + swapAddress() { this.startInfo.forEach((element: any, index: any) => { this.validateForm1.removeControl(`loadAddress${index}`); this.validateForm1.removeControl(`loadName${index}`); diff --git a/src/app/shared/components/amap/amap-poi-picker/amap-poi-picker.component.ts b/src/app/shared/components/amap/amap-poi-picker/amap-poi-picker.component.ts index fb9441d3..1394a6ca 100644 --- a/src/app/shared/components/amap/amap-poi-picker/amap-poi-picker.component.ts +++ b/src/app/shared/components/amap/amap-poi-picker/amap-poi-picker.component.ts @@ -1,5 +1,5 @@ import AMapLoader from '@amap/amap-jsapi-loader'; -import { Component, OnInit, ViewChild } from '@angular/core'; +import { ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core'; import { amapConf } from '@conf/amap.config'; import { NzModalRef } from 'ng-zorro-antd/modal'; import { throwError } from 'rxjs'; @@ -27,7 +27,10 @@ export class AmapPoiPickerComponent implements OnInit { infoWindow: any; geocoder: any; - constructor(private modalRef: NzModalRef, private service: AmapService) {} + @Input() + selectedAddress!: string; + + constructor(private modalRef: NzModalRef, private service: AmapService, private cdr: ChangeDetectorRef) {} ngOnInit(): void { this.mapInit(); // this.PoiPicker(); @@ -77,6 +80,8 @@ export class AmapPoiPickerComponent implements OnInit { // 地图创建成功 this.aMap.on('complete', () => { + console.log('地图创建成功'); + this.cdr.detectChanges(); this.poiPickerReady(poiPicker); }); @@ -113,12 +118,21 @@ export class AmapPoiPickerComponent implements OnInit { radius: 1000 //范围,默认:500 }); - // 获取当前定位 - this.service.getCurrentPosition().subscribe(res => { - if (res) { - this.selectedPOI(res.position); - } - }); + if (this.selectedAddress) { + this.geocoder.getLocation(this.selectedAddress, (status: any, result: any) => { + if (status === 'complete' && result.info === 'OK') { + // result中对应详细地理坐标信息 + this.selectedPOI(result.geocodes?.[0].location); + } + }); + } else { + // 获取当前定位 + this.service.getCurrentPosition().subscribe(res => { + if (res) { + this.selectedPOI(res.position); + } + }); + } //选取了某个POI poiPicker.on('poiPicked', (poiResult: any) => {