This commit is contained in:
aihe 2024-04-29 11:18:29 +08:00
parent 307654abf3
commit 7744c81745
4 changed files with 32 additions and 7 deletions

View File

@ -170,8 +170,16 @@ const pageEventNames = {
chooseAddress: "chooseAddress", // 地址选择 chooseAddress: "chooseAddress", // 地址选择
} }
const addressNameCodeMap = [
{ nameKey: 'countryName', codeKey: 'country' },
{ nameKey: 'provinceName', codeKey: 'province' },
{ nameKey: 'cityName', codeKey: 'city' },
{ nameKey: 'countyName', codeKey: 'county' },
{ nameKey: 'townName', codeKey: 'town' }
]
export { export {
addressNameCodeMap,
ordStaEnum, ordStaEnum,
ordStatusList, ordStatusList,
payTypeEnum, payTypeEnum,

View File

@ -97,7 +97,7 @@ const numberToChinese = (num)=> {
// - 获取地址详情 // - 获取地址详情
const getAddressDetail = (item= {})=> { const getAddressDetail = (item= {})=> {
return `${item.countryName||''}${item.provinceName||''}${item.cityName||''}${item.countyName||''}${item.address||''}` return `${item.countryName||''}${item.provinceName||''}${item.cityName||''}${item.countyName||''}${item.townName||''}${item.address||''}`
} }
// - 转换list的key val // - 转换list的key val

View File

@ -26,7 +26,7 @@
</view> </view>
<view class="mt-40 pos-rlt"> <view class="mt-40 pos-rlt">
<tpx-input v-model:value="_area" placeholder="所在地区"></tpx-input> <tpx-input :value="getAddressDetail(submitParam)" placeholder="所在地区"></tpx-input>
<view @click="handleDialogClick(addressModal)" class="pos-abt-all"></view> <view @click="handleDialogClick(addressModal)" class="pos-abt-all"></view>
</view> </view>
@ -82,6 +82,8 @@
<script> <script>
import { getAddressModels } from "./model" import { getAddressModels } from "./model"
import * as apiService from "@/common/api" import * as apiService from "@/common/api"
import { addressNameCodeMap } from "@/common/enum"
import { getAddressDetail } from "@/common/util"
export default { export default {
props: { props: {
@ -120,6 +122,7 @@
}, },
methods: { methods: {
getAddressDetail,
async initData() { async initData() {
if(this.queryOption.id) { if(this.queryOption.id) {
let res = await apiService.getAddressById({ id: this.queryOption.id, _loading: true }) let res = await apiService.getAddressById({ id: this.queryOption.id, _loading: true })
@ -127,16 +130,24 @@
res.data.blDefaultFlag = [true] res.data.blDefaultFlag = [true]
} }
this.submitParam = res.data this.submitParam = res.data
// 回显 国家-省市区组件数据
addressNameCodeMap.map((t, index)=> {
let name = res.data[t.nameKey]
let code = res.data[t.codeKey]
name && (this.addressModal.values.regIds[index] = name);
code && (this.addressModal.values.regNames[index] = code);
})
} }
}, },
handleAnsText(){ handleAnsText(){
}, },
handleAddressChoose(data) { handleAddressChoose(data) {
this.submitParam.country = data.regIds[0] data.regIds.map((regId, index)=> {
this.submitParam.province = data.regIds[1] let nameCodeMap = addressNameCodeMap[index]
this.submitParam.city = data.regIds[2] this.submitParam[nameCodeMap.codeKey] = regId
this.submitParam.county = data.regIds[3] this.submitParam[nameCodeMap.nameKey] = data.regNames[index]
})
}, },
handleReset(){ handleReset(){
this.submitParam = getAddressModels() this.submitParam = getAddressModels()

View File

@ -4,9 +4,15 @@ export const getAddressModels = () => {
"name": "", // 姓名 "name": "", // 姓名
"phone": "", // 手机号 "phone": "", // 手机号
"country": "", // 国家代码 "country": "", // 国家代码
"countryName": "", // 国家名称
"province": "", // 省份code "province": "", // 省份code
"provinceName": "", // 省份名称
"city": "", // 城市code "city": "", // 城市code
"county": "", // 区 code "cityName": "", // 城市名称
"county": "", // 城镇 code
"countyName": "", // 城镇名称
"town": "", // 街道编号
"townName": "", // 街道名称
"address": "", // 详细地址 "address": "", // 详细地址
"postCode": "", // 邮编 "postCode": "", // 邮编
"email": null, "email": null,