fix(uniapp): 外卖订单默认地址

This commit is contained in:
Kroytz committed 2026-07-24 13:25:34 +08:00
1 parent 6d3c640c98
commit 81ccaa6e01
1 file changed
+16
@@ -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) {