diff --git a/project.private.config.json b/project.private.config.json index 61eebd9..b643435 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -86,6 +86,20 @@ "query": "id=45", "launchMode": "default", "scene": null + }, + { + "name": "", + "pathName": "pages/getColorCard/addColorCard/index", + "query": "", + "launchMode": "default", + "scene": null + }, + { + "name": "", + "pathName": "pages/sampleCutting/addSampleCutting/index", + "query": "", + "launchMode": "default", + "scene": null } ] } diff --git a/src/pages/getColorCard/addColorCard/index.tsx b/src/pages/getColorCard/addColorCard/index.tsx index 9ad899f..814057d 100644 --- a/src/pages/getColorCard/addColorCard/index.tsx +++ b/src/pages/getColorCard/addColorCard/index.tsx @@ -166,7 +166,11 @@ const AddColorCard = () => { clientName: currPage.data?.clientName, 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) { @@ -177,6 +181,9 @@ const AddColorCard = () => { 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 getAddressList = async(purchaser_id: number) => { + // 获取默认地址 + const getDefaultAddressList = async(purchaser_id: number) => { const res = await addressListApi({ purchaser_id }) if (res.success) { const { list } = res.data + let defaultAddress = list?.find((item) => { return item.is_default }) + if (!defaultAddress) { + defaultAddress = list?.[0] + } setAddressInfo(val => ({ ...val, - province_name: list?.[0]?.province_name || '', - address_id: list?.[0]?.id || '', - city_name: list?.[0]?.city_name || '', - address_detail: list?.[0]?.address_detail || '', - district_name: list?.[0]?.district_name || '', - target_user_name: list?.[0]?.name || '', - purchaser_phone: list?.[0]?.phone || '', + province_name: defaultAddress.province_name || '', + address_id: defaultAddress.id || '', + city_name: defaultAddress.city_name || '', + address_detail: defaultAddress.address_detail || '', + district_name: defaultAddress.district_name || '', + target_user_name: defaultAddress.name || '', + purchaser_phone: defaultAddress.phone || '', })) + currPage.data.addressObj = defaultAddress } } @@ -293,10 +306,10 @@ const AddColorCard = () => { { clientInfo.clientId !== -1 ? (<> - + {clientInfo.clientName} - + {clientInfo.clientPhone} diff --git a/src/pages/sampleCutting/addSampleCutting/index.tsx b/src/pages/sampleCutting/addSampleCutting/index.tsx index 7e818ec..6e5b20f 100644 --- a/src/pages/sampleCutting/addSampleCutting/index.tsx +++ b/src/pages/sampleCutting/addSampleCutting/index.tsx @@ -91,20 +91,10 @@ const AddColorCard = () => { // 提交订单 const handleSubmitOrder = async() => { if (!addressInfo.address_id) { - Taro.showToast({ - title: '请选择地址', - icon: 'none', - duration: 2000, - }) - return + return alert.none('请选择地址') } if (!clientInfo.clientId) { - Taro.showToast({ - title: '请选择客户', - icon: 'none', - duration: 2000, - }) - return + return alert.none('请选择客户') } const productColorList: any[] = [] order.forEach((item) => { @@ -210,7 +200,9 @@ const AddColorCard = () => { clientName: currPage.data?.clientName, clientPhone: currPage.data?.clientPhone, }) - getAddressList(currPage.data?.clientId) + if (clientInfo.clientId !== currPage.data?.clientId) { + getDefaultAddressList(currPage.data?.clientId) + } } // 默认客户 if (currPage.data?.clientId == null) { @@ -221,6 +213,9 @@ const AddColorCard = () => { 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 getAddressList = async(purchaser_id: number) => { + const getDefaultAddressList = async(purchaser_id: number) => { const res = await addressListApi({ purchaser_id }) if (res.success) { const { list } = res.data + let defaultAddress = list?.find((item) => { return item.is_default }) + if (!defaultAddress) { + defaultAddress = list?.[0] + } setAddressInfo(val => ({ ...val, - province_name: list?.[0]?.province_name || '', - address_id: list?.[0]?.id || '', - city_name: list?.[0]?.city_name || '', - address_detail: list?.[0]?.address_detail || '', - district_name: list?.[0]?.district_name || '', - target_user_name: list?.[0]?.name || '', - purchaser_phone: list?.[0]?.phone || '', + province_name: defaultAddress.province_name || '', + address_id: defaultAddress.id || '', + city_name: defaultAddress.city_name || '', + address_detail: defaultAddress.address_detail || '', + district_name: defaultAddress.district_name || '', + target_user_name: defaultAddress.name || '', + purchaser_phone: defaultAddress.phone || '', })) + currPage.data.addressObj = defaultAddress } }