🐞 fix(ID1001405): 【内部小程序】-【领取色卡】--已有默认地址,手动选择地址后,还是显示默认地址

【【内部小程序】-【领取色卡】--已有默认地址,手动选择地址后,还是显示默认地址】 https://www.tapd.cn/53459131/bugtrace/bugs/view/1153459131001001405
This commit is contained in:
xuan 2023-03-01 11:35:10 +08:00
parent 1ad57791b6
commit 739367022b
3 changed files with 59 additions and 32 deletions

View File

@ -86,6 +86,20 @@
"query": "id=45", "query": "id=45",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
},
{
"name": "",
"pathName": "pages/getColorCard/addColorCard/index",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/sampleCutting/addSampleCutting/index",
"query": "",
"launchMode": "default",
"scene": null
} }
] ]
} }

View File

@ -166,7 +166,11 @@ const AddColorCard = () => {
clientName: currPage.data?.clientName, clientName: currPage.data?.clientName,
clientPhone: currPage.data?.clientPhone, clientPhone: currPage.data?.clientPhone,
}) })
getAddressList(currPage.data?.clientId) // 当前客户不是已选客户 重新获取默认地址
console.log(clientInfo.clientId, currPage.data?.clientId)
if (clientInfo.clientId !== currPage.data?.clientId) {
getDefaultAddressList(currPage.data?.clientId)
}
} }
// 默认客户 // 默认客户
if (currPage.data?.clientId == null) { if (currPage.data?.clientId == null) {
@ -177,6 +181,9 @@ const AddColorCard = () => {
clientPhone: clientList.length > 0 ? clientList[0]?.phone : '', clientPhone: clientList.length > 0 ? clientList[0]?.phone : '',
} }
}) })
if (clientList.length > 0) {
getDefaultAddressList(clientList[0]?.id)
}
} }
}) })
@ -258,20 +265,26 @@ const AddColorCard = () => {
} }
const { fetchData: addressListApi } = MpPurchaserAddressList() const { fetchData: addressListApi } = MpPurchaserAddressList()
const getAddressList = async(purchaser_id: number) => { // 获取默认地址
const getDefaultAddressList = async(purchaser_id: number) => {
const res = await addressListApi({ purchaser_id }) const res = await addressListApi({ purchaser_id })
if (res.success) { if (res.success) {
const { list } = res.data const { list } = res.data
let defaultAddress = list?.find((item) => { return item.is_default })
if (!defaultAddress) {
defaultAddress = list?.[0]
}
setAddressInfo(val => ({ setAddressInfo(val => ({
...val, ...val,
province_name: list?.[0]?.province_name || '', province_name: defaultAddress.province_name || '',
address_id: list?.[0]?.id || '', address_id: defaultAddress.id || '',
city_name: list?.[0]?.city_name || '', city_name: defaultAddress.city_name || '',
address_detail: list?.[0]?.address_detail || '', address_detail: defaultAddress.address_detail || '',
district_name: list?.[0]?.district_name || '', district_name: defaultAddress.district_name || '',
target_user_name: list?.[0]?.name || '', target_user_name: defaultAddress.name || '',
purchaser_phone: list?.[0]?.phone || '', purchaser_phone: defaultAddress.phone || '',
})) }))
currPage.data.addressObj = defaultAddress
} }
} }
@ -293,10 +306,10 @@ const AddColorCard = () => {
{ {
clientInfo.clientId !== -1 clientInfo.clientId !== -1
? (<> ? (<>
<Text> <Text style={{ color: '#333333' }}>
{clientInfo.clientName} {clientInfo.clientName}
</Text> </Text>
<Text> <Text style={{ color: '#333333' }}>
{clientInfo.clientPhone} {clientInfo.clientPhone}
</Text> </Text>
</> </>

View File

@ -91,20 +91,10 @@ const AddColorCard = () => {
// 提交订单 // 提交订单
const handleSubmitOrder = async() => { const handleSubmitOrder = async() => {
if (!addressInfo.address_id) { if (!addressInfo.address_id) {
Taro.showToast({ return alert.none('请选择地址')
title: '请选择地址',
icon: 'none',
duration: 2000,
})
return
} }
if (!clientInfo.clientId) { if (!clientInfo.clientId) {
Taro.showToast({ return alert.none('请选择客户')
title: '请选择客户',
icon: 'none',
duration: 2000,
})
return
} }
const productColorList: any[] = [] const productColorList: any[] = []
order.forEach((item) => { order.forEach((item) => {
@ -210,7 +200,9 @@ const AddColorCard = () => {
clientName: currPage.data?.clientName, clientName: currPage.data?.clientName,
clientPhone: currPage.data?.clientPhone, clientPhone: currPage.data?.clientPhone,
}) })
getAddressList(currPage.data?.clientId) if (clientInfo.clientId !== currPage.data?.clientId) {
getDefaultAddressList(currPage.data?.clientId)
}
} }
// 默认客户 // 默认客户
if (currPage.data?.clientId == null) { if (currPage.data?.clientId == null) {
@ -221,6 +213,9 @@ const AddColorCard = () => {
clientPhone: clientList.length > 0 ? clientList[0]?.phone : '', clientPhone: clientList.length > 0 ? clientList[0]?.phone : '',
} }
}) })
if (clientList.length > 0) {
getDefaultAddressList(clientList[0]?.id)
}
} }
}) })
@ -316,20 +311,25 @@ const AddColorCard = () => {
} }
const { fetchData: addressListApi } = MpPurchaserAddressList() const { fetchData: addressListApi } = MpPurchaserAddressList()
const getAddressList = async(purchaser_id: number) => { const getDefaultAddressList = async(purchaser_id: number) => {
const res = await addressListApi({ purchaser_id }) const res = await addressListApi({ purchaser_id })
if (res.success) { if (res.success) {
const { list } = res.data const { list } = res.data
let defaultAddress = list?.find((item) => { return item.is_default })
if (!defaultAddress) {
defaultAddress = list?.[0]
}
setAddressInfo(val => ({ setAddressInfo(val => ({
...val, ...val,
province_name: list?.[0]?.province_name || '', province_name: defaultAddress.province_name || '',
address_id: list?.[0]?.id || '', address_id: defaultAddress.id || '',
city_name: list?.[0]?.city_name || '', city_name: defaultAddress.city_name || '',
address_detail: list?.[0]?.address_detail || '', address_detail: defaultAddress.address_detail || '',
district_name: list?.[0]?.district_name || '', district_name: defaultAddress.district_name || '',
target_user_name: list?.[0]?.name || '', target_user_name: defaultAddress.name || '',
purchaser_phone: list?.[0]?.phone || '', purchaser_phone: defaultAddress.phone || '',
})) }))
currPage.data.addressObj = defaultAddress
} }
} }