|
@@ -12,7 +12,7 @@ Page({
|
|
|
addressShow: false,
|
|
|
addressAfterLeave: false,
|
|
|
showDialog: false,
|
|
|
-
|
|
|
+ cacheArea: [] as { cityCode: string, shiftCityCode: string }[], // 临时存储的对应关系
|
|
|
showArea: false,
|
|
|
areaList: [] as any,
|
|
|
currentValues: [] as any,
|
|
@@ -108,8 +108,19 @@ Page({
|
|
|
province_list[item.code] = item.name;
|
|
|
});
|
|
|
area.forEach((item: any) => {
|
|
|
- item.areas && item.areas.forEach((city: any) => {
|
|
|
- city_list[city.code] = city.name;
|
|
|
+ item.areas && item.areas.forEach((city: any, index: number) => {
|
|
|
+ let code = city.code + ""
|
|
|
+ // 某些数据不标准 这里需要转换一下
|
|
|
+ if (code[4] !== "0" || code[5] !== "0") {
|
|
|
+ // 现在把区域的数据改为市的
|
|
|
+ const newCode = code.substring(0, 2) + (index < 10 ? `a${index}` : index < 20 ? `b${index - 10}` : index < 30 ? `c${index - 20}` : `d${index - 30}`) + "00";
|
|
|
+ this.data.cacheArea.push({
|
|
|
+ cityCode: code,
|
|
|
+ shiftCityCode: newCode
|
|
|
+ })
|
|
|
+ code = newCode
|
|
|
+ }
|
|
|
+ city_list[code] = city.name;
|
|
|
});
|
|
|
});
|
|
|
area.forEach((item: any) => {
|
|
@@ -125,6 +136,16 @@ Page({
|
|
|
county_list
|
|
|
};
|
|
|
},
|
|
|
+ // 转换
|
|
|
+ formateCityCode(reverse?: boolean) {
|
|
|
+ if (!this.data.regionCode && this.data.cityCode) {
|
|
|
+ const cityCodeObj = this.data.cacheArea.find((item: any) => {
|
|
|
+ return item[reverse ? "cityCode" : "shiftCityCode"] == this.data.cityCode
|
|
|
+ })
|
|
|
+ return cityCodeObj ? cityCodeObj[reverse ? "shiftCityCode" : "cityCode"] : ""
|
|
|
+ }
|
|
|
+ return this.data.cityCode
|
|
|
+ },
|
|
|
/** 显示选择地区 */
|
|
|
onShowAreaList() {
|
|
|
this.setData({
|
|
@@ -143,10 +164,10 @@ Page({
|
|
|
this.setData({
|
|
|
provinceCode: selectedOptions[0].code,
|
|
|
cityCode: selectedOptions[1].code,
|
|
|
- regionCode: selectedOptions[2].code,
|
|
|
- provinceName: selectedOptions[0].name,
|
|
|
- cityName: selectedOptions[1].name,
|
|
|
- regionName: selectedOptions[2].name,
|
|
|
+ regionCode: selectedOptions[2]?.code || null,
|
|
|
+ provinceName: selectedOptions[0].name || '',
|
|
|
+ cityName: selectedOptions[1].name || '',
|
|
|
+ regionName: selectedOptions[2]?.name || '',
|
|
|
showArea: false,
|
|
|
})
|
|
|
},
|
|
@@ -193,10 +214,10 @@ Page({
|
|
|
onUpdateAddress(e: any) {
|
|
|
const id = e.target.dataset.id
|
|
|
const addressInfo = this.data.addressList.find((item: any) => item.id === id)
|
|
|
-
|
|
|
this.setData({
|
|
|
addressShow: true,
|
|
|
- id: addressInfo.id,
|
|
|
+ addressAfterLeave: false,
|
|
|
+ selectAddressId: addressInfo.id,
|
|
|
name: addressInfo.name,
|
|
|
phoneNumber: addressInfo.phoneNumber,
|
|
|
detailAddress: addressInfo.detailAddress,
|
|
@@ -270,7 +291,7 @@ Page({
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if (!addressForm.provinceCode || !addressForm.cityCode || !addressForm.regionCode) {
|
|
|
+ if (!addressForm.provinceCode || !addressForm.cityCode) {
|
|
|
wx.showToast({
|
|
|
title: '请选择地区',
|
|
|
icon: "none"
|
|
@@ -284,17 +305,18 @@ Page({
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
+ const citycode = this.formateCityCode()
|
|
|
const params = {
|
|
|
name: addressForm.name,
|
|
|
phoneNumber: addressForm.phoneNumber,
|
|
|
province: addressForm.provinceCode,
|
|
|
- city: addressForm.cityCode,
|
|
|
- region: addressForm.regionCode,
|
|
|
+ city: citycode,
|
|
|
+ region: addressForm.regionCode || '',
|
|
|
detailAddress: addressForm.detailAddress
|
|
|
}
|
|
|
- if (addressForm.id) {
|
|
|
+ if (addressForm.selectAddressId) {
|
|
|
await api_userReceiveAddressUpdate({
|
|
|
- id: addressForm.id,
|
|
|
+ id: addressForm.selectAddressId,
|
|
|
...params
|
|
|
})
|
|
|
wx.showToast({
|