Commit 8b04f323 authored by chenqikuai's avatar chenqikuai

fix: 修复地址映射

parent f02b0639
...@@ -16,9 +16,37 @@ export default class AddressService { ...@@ -16,9 +16,37 @@ export default class AddressService {
this.max_len_gps = 10 this.max_len_gps = 10
} }
getGpses(data: { addrs: string[] }): Promise<string[]> { // getGpses(data: { addrs: string[] }): Promise<string[]> {
// return new Promise((resolve, reject) => {
// const resultList = [] as string[]
// if (data.addrs.length) {
// for (
// let i = 0;
// i < Math.ceil(data.addrs.length / this.max_len_gps);
// ++i
// ) {
// const reqList = data.addrs.slice(
// i * this.max_len_gps,
// i * this.max_len_gps + this.max_len_gps,
// )
// this.__getGpses(reqList).then((ret) => {
// if (ret.code === 200) {
// resultList.push(...ret.data.gps)
// if (resultList.length === data.addrs.length) {
// resolve(resultList)
// }
// } else {
// reject('解析错误')
// }
// })
// }
// }
// })
// }
getGpses2(data: { addrs: string[] }): Promise<{ [props: string]: string }> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const resultList = [] as string[] const theMap = {} as { [props: string]: string }
if (data.addrs.length) { if (data.addrs.length) {
for ( for (
let i = 0; let i = 0;
...@@ -31,9 +59,14 @@ export default class AddressService { ...@@ -31,9 +59,14 @@ export default class AddressService {
) )
this.__getGpses(reqList).then((ret) => { this.__getGpses(reqList).then((ret) => {
if (ret.code === 200) { if (ret.code === 200) {
resultList.push(...ret.data.gps) const locations = reqList
if (resultList.length === data.addrs.length) { const gpses = ret.data.gps
resolve(resultList)
locations.map((location, index) => {
theMap[location] = gpses[index]
})
if (Object.keys(theMap).length === data.addrs.length) {
resolve(theMap)
} }
} else { } else {
reject('解析错误') reject('解析错误')
...@@ -47,7 +80,7 @@ export default class AddressService { ...@@ -47,7 +80,7 @@ export default class AddressService {
if (addrs.length > 10) { if (addrs.length > 10) {
throw new Error('长度超过10') throw new Error('长度超过10')
} else { } else {
return baseAxios<{ gps: string[]}>({ return baseAxios<{ gps: string[] }>({
url: this.prefix + '/getGps', url: this.prefix + '/getGps',
method: 'post', method: 'post',
data: { data: {
...@@ -71,7 +104,7 @@ export default class AddressService { ...@@ -71,7 +104,7 @@ export default class AddressService {
// }) // })
// } // }
getOutlets(data: { level?: number; id?: number, branch_name?:string }) { getOutlets(data: { level?: number; id?: number; branch_name?: string }) {
return baseAxios<iOutLetDetail[]>({ return baseAxios<iOutLetDetail[]>({
url: '/address/getOutlets', url: '/address/getOutlets',
method: 'post', method: 'post',
...@@ -119,7 +152,7 @@ export default class AddressService { ...@@ -119,7 +152,7 @@ export default class AddressService {
url: '/address/add', url: '/address/add',
method: 'post', method: 'post',
data: { data: {
outlets_req: [data] outlets_req: [data],
}, },
}) })
} }
......
...@@ -33,14 +33,14 @@ function getAddressList(dataList: any[]) { ...@@ -33,14 +33,14 @@ function getAddressList(dataList: any[]) {
} }
async function getAddressLalonObj(locationList: string[]) { async function getAddressLalonObj(locationList: string[]) {
const rets = await AddressService.getInstance().getGpses({ const rets = await AddressService.getInstance().getGpses2({
addrs: locationList, addrs: locationList,
}) })
let obj = {} as any // let obj = {} as any
locationList.forEach((item, index) => { // locationList.forEach((item, index) => {
obj[item] = rets[index] // obj[item] = rets[index]
}) // })
return obj return rets
} }
function formatPositionToNumber(str: string) { function formatPositionToNumber(str: string) {
...@@ -181,9 +181,11 @@ export const handle建设银行excelFileChange = (e: Event) => { ...@@ -181,9 +181,11 @@ export const handle建设银行excelFileChange = (e: Event) => {
const list = (parseJSYHSheet( const list = (parseJSYHSheet(
Sheets[SheetsKeys[0]], Sheets[SheetsKeys[0]],
) as unknown) as any[] ) as unknown) as any[]
console.log(list, 'show list');
const locationList = getAddressList((list as unknown) as any) const locationList = getAddressList((list as unknown) as any)
console.log(JSON.stringify(locationList)) console.log(JSON.stringify(locationList))
getAddressLalonObj(locationList).then((addressLalonObj) => { getAddressLalonObj(locationList).then((addressLalonObj) => {
console.log(addressLalonObj,' show addressLalonObj');
list.forEach((data) => { list.forEach((data) => {
data.la_lon = addressLalonObj[data.location] data.la_lon = addressLalonObj[data.location]
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment