feat:小车列表取首个car_id/car_code,无小车弹窗中断

This commit is contained in:
97694732@qq.com 2026-06-17 17:04:47 +08:00
parent af2b05a6a8
commit f7d8a7d805

View File

@ -2328,8 +2328,12 @@ export default {
const token = uni.getStorageSync('token') || ''
//
await this.callCarListApi(timestamp)
// car_id / car_code
var carInfo = await this.callCarListApi(timestamp)
if (!carInfo) {
// callCarListApi
return
}
//
const params = {
@ -2340,8 +2344,8 @@ export default {
'items[0][quantity]': stock,
'items[0][unit_price]': price,
direction: '1',
car_id: '',
car_code: '',
car_id: String(carInfo.car_id),
car_code: String(carInfo.car_code),
timestamp: timestamp,
sign_method: 'md5'
}
@ -2373,7 +2377,7 @@ export default {
}
},
//
// {car_id, car_code} null
async callCarListApi(timestamp) {
const token = uni.getStorageSync('token') || ''
const params = {
@ -2391,7 +2395,7 @@ export default {
const res = await new Promise(function (resolve, reject) {
uni.request({
url: 'https://psi.api.buzhiyushu.cn/api/car/list',
method: 'POST',
method: 'GET',
header: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ' + token
@ -2402,8 +2406,30 @@ export default {
})
})
console.log('【小车列表】返回值:', res.statusCode, res.data)
if (res.statusCode === 200 && res.data && res.data.code === 0 && res.data.data) {
var list = res.data.data.list || []
if (list.length > 0) {
var firstCar = list[0]
return { car_id: firstCar.id, car_code: firstCar.code }
}
}
// null
uni.showModal({
title: '系统提示',
content: '当前没有可用的购物车,请先创建购物车',
showCancel: false
})
return null
} catch (e) {
console.warn('【小车列表】请求失败:', e)
uni.showModal({
title: '系统提示',
content: '获取购物车列表失败,请稍后重试',
showCancel: false
})
return null
}
},