|
@@ -14,6 +14,7 @@ Component({
|
|
|
name: "",
|
|
|
phoneNumber: "",
|
|
|
|
|
|
+ cacheArea: [] as { cityCode: string, shiftCityCode: string }[], // 临时存储的对应关系
|
|
|
showArea: false,
|
|
|
areaList: [] as any, // 省市区
|
|
|
province: "",
|
|
@@ -48,6 +49,10 @@ Component({
|
|
|
regionName: params.regionName,
|
|
|
detailAddress: params.detailAddress
|
|
|
})
|
|
|
+ // 回显市区
|
|
|
+ this.setData({
|
|
|
+ city: this.formateCityCode(true)
|
|
|
+ })
|
|
|
}
|
|
|
} catch (e: any) {
|
|
|
console.log(e, 888)
|
|
@@ -85,7 +90,7 @@ Component({
|
|
|
/** 确定选择地区 */
|
|
|
submitArea(e: any) {
|
|
|
const selectedOptions: any = e.detail.values
|
|
|
- if (!selectedOptions || !selectedOptions[selectedOptions.length - 1]) {
|
|
|
+ if (!selectedOptions || !selectedOptions[0]) {
|
|
|
wx.showToast({
|
|
|
title: '未选中值',
|
|
|
icon: 'none'
|
|
@@ -95,10 +100,10 @@ Component({
|
|
|
this.setData({
|
|
|
province: selectedOptions[0].code,
|
|
|
city: selectedOptions[1].code,
|
|
|
- region: selectedOptions[2].code,
|
|
|
+ region: selectedOptions[2]?.code,
|
|
|
provinceName: selectedOptions[0].name,
|
|
|
cityName: selectedOptions[1].name,
|
|
|
- regionName: selectedOptions[2].name,
|
|
|
+ regionName: selectedOptions[2]?.name,
|
|
|
showArea: false
|
|
|
})
|
|
|
},
|
|
@@ -121,8 +126,19 @@ Component({
|
|
|
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) => {
|
|
@@ -138,6 +154,16 @@ Component({
|
|
|
county_list
|
|
|
};
|
|
|
},
|
|
|
+ // 转换
|
|
|
+ formateCityCode(reverse?: boolean) {
|
|
|
+ if (!this.data.region && this.data.city) {
|
|
|
+ const cityCodeObj = this.data.cacheArea.find((item: any) => {
|
|
|
+ return item[reverse ? "cityCode" : "shiftCityCode"] == this.data.city
|
|
|
+ })
|
|
|
+ return cityCodeObj ? cityCodeObj[reverse ? "shiftCityCode" : "cityCode"] : ""
|
|
|
+ }
|
|
|
+ return this.data.city
|
|
|
+ },
|
|
|
/** 最终提交 */
|
|
|
async onSubmit() {
|
|
|
try {
|
|
@@ -157,7 +183,7 @@ Component({
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (!params.province || !params.city || !params.region) {
|
|
|
+ if (!params.province || !params.city) {
|
|
|
wx.showToast({
|
|
|
title: '请选择地区',
|
|
|
icon: "none"
|
|
@@ -175,6 +201,8 @@ Component({
|
|
|
mask: true,
|
|
|
title: "",
|
|
|
});
|
|
|
+ // 转换CityCode
|
|
|
+ const citycode = this.formateCityCode()
|
|
|
// 编辑
|
|
|
let id
|
|
|
if (params.editId) {
|
|
@@ -184,7 +212,7 @@ Component({
|
|
|
phoneNumber: params.phoneNumber,
|
|
|
name: params.name,
|
|
|
province: params.province,
|
|
|
- city: params.city,
|
|
|
+ city: citycode,
|
|
|
region: params.region,
|
|
|
detailAddress: params.detailAddress,
|
|
|
defaultStatus: false,
|
|
@@ -199,7 +227,7 @@ Component({
|
|
|
phoneNumber: params.phoneNumber,
|
|
|
name: params.name,
|
|
|
province: params.province,
|
|
|
- city: params.city,
|
|
|
+ city: citycode,
|
|
|
region: params.region,
|
|
|
detailAddress: params.detailAddress,
|
|
|
defaultStatus: false,
|
|
@@ -212,7 +240,7 @@ Component({
|
|
|
})
|
|
|
}
|
|
|
wx.hideLoading()
|
|
|
- this.triggerEvent('addAddress', { addressInfo: { id, name: params.name, phoneNumber: params.phoneNumber, addressDes: params.provinceName + params.cityName + params.regionName + params.detailAddress } }, {})
|
|
|
+ this.triggerEvent('addAddress', { addressInfo: { id, name: params.name, phoneNumber: params.phoneNumber, addressDes: params.provinceName + params.cityName + (params.regionName || "") + params.detailAddress } }, {})
|
|
|
this.onDialogClose()
|
|
|
} catch {
|
|
|
wx.hideLoading()
|