diff --git a/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue b/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue index ad825ad..983c8ef 100644 --- a/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue +++ b/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue @@ -76,6 +76,7 @@ import { couponCount } from '@/api/coupon' import { getDeliveryFee } from '@/api/goods' +import { addressAll } from '@/api/address' // #ifdef H5 import * as jweixin from 'weixin-js-sdk' // #endif @@ -215,6 +216,7 @@ onShow(() => { if(orderType.value == 'takeout'){ active.value = true + fillDefaultAddress() }else{ active.value = false } @@ -236,6 +238,20 @@ onLoad((option) => { } }) +// 外卖且未选手动地址时,自动填入默认地址(无默认则取列表第一项) +const fillDefaultAddress = async () => { + if (orderType.value !== 'takeout') return + if (address.value?.id) return + if (!isLogin.value) return + const list = await addressAll() + if (!list || !list.length) return + main.SET_ADDRESSES(list) + const preferred = list.find(item => Number(item.isDefault) === 1) || list[0] + if (preferred) { + main.SET_ADDRESS(preferred) + } +} + const getSubscribeMss = async() => { let data = [] if (data) {