From f7d8a7d805d6c92d9c890669fd7bc49b50ab1834 Mon Sep 17 00:00:00 2001 From: "97694732@qq.com" Date: Wed, 17 Jun 2026 17:04:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=B0=8F=E8=BD=A6=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=8F=96=E9=A6=96=E4=B8=AAcar=5Fid/car=5Fcode,=E6=97=A0?= =?UTF-8?q?=E5=B0=8F=E8=BD=A6=E5=BC=B9=E7=AA=97=E4=B8=AD=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/upload.vue | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/pages/upload/upload.vue b/pages/upload/upload.vue index c533719..c3fbc0d 100644 --- a/pages/upload/upload.vue +++ b/pages/upload/upload.vue @@ -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 } },