Commit 8b04f323 authored by chenqikuai's avatar chenqikuai

fix: 修复地址映射

parent f02b0639
......@@ -16,9 +16,37 @@ export default class AddressService {
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) => {
const resultList = [] as string[]
const theMap = {} as { [props: string]: string }
if (data.addrs.length) {
for (
let i = 0;
......@@ -31,9 +59,14 @@ export default class AddressService {
)
this.__getGpses(reqList).then((ret) => {
if (ret.code === 200) {
resultList.push(...ret.data.gps)
if (resultList.length === data.addrs.length) {
resolve(resultList)
const locations = reqList
const gpses = ret.data.gps
locations.map((location, index) => {
theMap[location] = gpses[index]
})
if (Object.keys(theMap).length === data.addrs.length) {
resolve(theMap)
}
} else {
reject('解析错误')
......@@ -47,7 +80,7 @@ export default class AddressService {
if (addrs.length > 10) {
throw new Error('长度超过10')
} else {
return baseAxios<{ gps: string[]}>({
return baseAxios<{ gps: string[] }>({
url: this.prefix + '/getGps',
method: 'post',
data: {
......@@ -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[]>({
url: '/address/getOutlets',
method: 'post',
......@@ -119,7 +152,7 @@ export default class AddressService {
url: '/address/add',
method: 'post',
data: {
outlets_req: [data]
outlets_req: [data],
},
})
}
......
......@@ -33,14 +33,14 @@ function getAddressList(dataList: any[]) {
}
async function getAddressLalonObj(locationList: string[]) {
const rets = await AddressService.getInstance().getGpses({
const rets = await AddressService.getInstance().getGpses2({
addrs: locationList,
})
let obj = {} as any
locationList.forEach((item, index) => {
obj[item] = rets[index]
})
return obj
// let obj = {} as any
// locationList.forEach((item, index) => {
// obj[item] = rets[index]
// })
return rets
}
function formatPositionToNumber(str: string) {
......@@ -181,9 +181,11 @@ export const handle建设银行excelFileChange = (e: Event) => {
const list = (parseJSYHSheet(
Sheets[SheetsKeys[0]],
) as unknown) as any[]
console.log(list, 'show list');
const locationList = getAddressList((list as unknown) as any)
console.log(JSON.stringify(locationList))
getAddressLalonObj(locationList).then((addressLalonObj) => {
console.log(addressLalonObj,' show addressLalonObj');
list.forEach((data) => {
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