hookehuyr

refactor(订单): 重构订单确认收货逻辑并移除mock数据

移除订单列表中的mock数据,改为直接调用API获取真实数据
重构确认收货成功处理逻辑,增加状态查询API调用
移除成功时的冗余toast提示,改为在状态查询成功后显示
1 /* 1 /*
2 * @Date: 2025-06-28 10:33:00 2 * @Date: 2025-06-28 10:33:00
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-25 15:53:11 4 + * @LastEditTime: 2025-07-28 12:26:05
5 * @FilePath: /jgdl/src/app.js 5 * @FilePath: /jgdl/src/app.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -53,12 +53,6 @@ const App = createApp({ ...@@ -53,12 +53,6 @@ const App = createApp({
53 transactionId: req_extradata.transaction_id, 53 transactionId: req_extradata.transaction_id,
54 merchantTradeNo: req_extradata.merchant_trade_no, 54 merchantTradeNo: req_extradata.merchant_trade_no,
55 }) 55 })
56 -
57 - Taro.showToast({
58 - title: '确认收货成功',
59 - icon: 'success',
60 - duration: 2000
61 - })
62 } else if (status === 'fail') { 56 } else if (status === 'fail') {
63 Taro.showToast({ 57 Taro.showToast({
64 title: errormsg || '确认收货失败', 58 title: errormsg || '确认收货失败',
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-28 11:52:38 4 + * @LastEditTime: 2025-07-28 12:48:34
5 * @FilePath: /jgdl/src/pages/myOrders/index.vue 5 * @FilePath: /jgdl/src/pages/myOrders/index.vue
6 * @Description: 订单管理页面 6 * @Description: 订单管理页面
7 --> 7 -->
...@@ -106,8 +106,8 @@ ...@@ -106,8 +106,8 @@
106 <nut-button type="default" size="small" @click="viewOrderDetail(order.id)"> 106 <nut-button type="default" size="small" @click="viewOrderDetail(order.id)">
107 查看详情 107 查看详情
108 </nut-button> 108 </nut-button>
109 - <nut-button type="primary" size="small" @click="handleConfirmReceive(order)" color="orange" 109 + <nut-button type="primary" size="small" @click="handleConfirmReceive(order)" color="orange" class="ml-2"
110 - class="ml-2" :loading="receivingOrderId === order.id" :disabled="receivingOrderId === order.id"> 110 + :loading="receivingOrderId === order.id" :disabled="receivingOrderId === order.id">
111 {{ receivingOrderId === order.id ? '收货中...' : '确认收货' }} 111 {{ receivingOrderId === order.id ? '收货中...' : '确认收货' }}
112 </nut-button> 112 </nut-button>
113 </template> 113 </template>
...@@ -365,7 +365,7 @@ import './index.less' ...@@ -365,7 +365,7 @@ import './index.less'
365 import { $ } from '@tarojs/extend' 365 import { $ } from '@tarojs/extend'
366 import payCard from '@/components/payCard.vue' 366 import payCard from '@/components/payCard.vue'
367 // 导入接口 367 // 导入接口
368 -import { getOrderListAPI, getOrderDetailAPI, reviewOrderAPI, cancelOrderAPI, deleteOrderAPI } from '@/api/orders' 368 +import { getOrderListAPI, getOrderDetailAPI, reviewOrderAPI, cancelOrderAPI, deleteOrderAPI, shipOrderAPI, receiptOrderStatusAPI } from '@/api/orders'
369 import { DEFAULT_COVER_IMG } from '@/utils/config' 369 import { DEFAULT_COVER_IMG } from '@/utils/config'
370 370
371 const scrollStyle = ref({ 371 const scrollStyle = ref({
...@@ -479,40 +479,40 @@ const loadOrderData = async (isLoadMore = false) => { ...@@ -479,40 +479,40 @@ const loadOrderData = async (isLoadMore = false) => {
479 const status = activeTab.value || undefined 479 const status = activeTab.value || undefined
480 const page = isLoadMore ? currentPage.value + 1 : 0 480 const page = isLoadMore ? currentPage.value + 1 : 0
481 481
482 - // 添加mock数据用于测试 482 + // TAG: 添加mock数据用于测试
483 - if (page === 0) { 483 + // if (page === 0) {
484 - const mockOrder = { 484 + // const mockOrder = {
485 - id: `mock_${type}_${Date.now()}`, 485 + // id: `mock_${type}_${Date.now()}`,
486 - status: 9, // 已发货/待收货状态 486 + // status: 9, // 已发货/待收货状态
487 - created_time: new Date().toLocaleString('zh-CN'), 487 + // created_time: new Date().toLocaleString('zh-CN'),
488 - total_amount: 15000, 488 + // total_amount: 15000,
489 - details: { 489 + // details: {
490 - id: `detail_${Date.now()}`, 490 + // id: `detail_${Date.now()}`,
491 - vehicle: { 491 + // vehicle: {
492 - id: `vehicle_${Date.now()}`, 492 + // id: `vehicle_${Date.now()}`,
493 - brand: '雅迪', 493 + // brand: '雅迪',
494 - model: 'DE2', 494 + // model: 'DE2',
495 - manufacture_year: 2023, 495 + // manufacture_year: 2023,
496 - range_km: 60, 496 + // range_km: 60,
497 - battery_capacity_ah: 48, 497 + // battery_capacity_ah: 48,
498 - price: 15000, 498 + // price: 15000,
499 - front_photo: DEFAULT_COVER_IMG, 499 + // front_photo: DEFAULT_COVER_IMG,
500 - seller: { 500 + // seller: {
501 - nickname: '测试卖家', 501 + // nickname: '测试卖家',
502 - phone: '138****8888' 502 + // phone: '138****8888'
503 - } 503 + // }
504 - } 504 + // }
505 - }, 505 + // },
506 - buyer: { 506 + // buyer: {
507 - nickname: '测试买家', 507 + // nickname: '测试买家',
508 - phone: '139****9999' 508 + // phone: '139****9999'
509 - }, 509 + // },
510 - is_sold: false 510 + // is_sold: false
511 - } 511 + // }
512 - 512 +
513 - const targetOrders = viewMode.value === 'buy' ? boughtOrders : soldOrders 513 + // const targetOrders = viewMode.value === 'buy' ? boughtOrders : soldOrders
514 - targetOrders.value = [mockOrder] 514 + // targetOrders.value = [mockOrder]
515 - } 515 + // }
516 516
517 const response = await getOrderListAPI({ 517 const response = await getOrderListAPI({
518 type, 518 type,
...@@ -1191,7 +1191,7 @@ const handleConfirmShip = async (order) => { ...@@ -1191,7 +1191,7 @@ const handleConfirmShip = async (order) => {
1191 pendingShipOrderId.value = order.id 1191 pendingShipOrderId.value = order.id
1192 showShipConfirmModal.value = true 1192 showShipConfirmModal.value = true
1193 } catch (error) { 1193 } catch (error) {
1194 - console.error('确认发货失败:', error) 1194 + // 确认发货失败处理
1195 } 1195 }
1196 } 1196 }
1197 1197
...@@ -1207,11 +1207,8 @@ const performConfirmShip = async (orderId) => { ...@@ -1207,11 +1207,8 @@ const performConfirmShip = async (orderId) => {
1207 shippingOrderId.value = orderId 1207 shippingOrderId.value = orderId
1208 1208
1209 try { 1209 try {
1210 - // TODO: 调用确认发货API(暂时使用mock) 1210 + // 调用确认发货API
1211 - // const response = await confirmShipAPI({ id: orderId }) 1211 + const response = await shipOrderAPI({ order_id: orderId })
1212 -
1213 - // Mock API响应
1214 - const response = { code: true, msg: '发货成功' }
1215 1212
1216 if (response.code) { 1213 if (response.code) {
1217 // API发货成功后的处理 1214 // API发货成功后的处理
...@@ -1232,7 +1229,7 @@ const performConfirmShip = async (orderId) => { ...@@ -1232,7 +1229,7 @@ const performConfirmShip = async (orderId) => {
1232 throw new Error(response.msg || '发货失败') 1229 throw new Error(response.msg || '发货失败')
1233 } 1230 }
1234 } catch (error) { 1231 } catch (error) {
1235 - console.error('确认发货失败:', error) 1232 + // 确认发货失败处理
1236 Taro.showToast({ 1233 Taro.showToast({
1237 title: error.msg || '确认发货失败,请重试', 1234 title: error.msg || '确认发货失败,请重试',
1238 icon: 'error', 1235 icon: 'error',
...@@ -1299,12 +1296,32 @@ const performDeleteOrder = async (orderId) => { ...@@ -1299,12 +1296,32 @@ const performDeleteOrder = async (orderId) => {
1299 * 处理确认收货成功事件 1296 * 处理确认收货成功事件
1300 * @param {Object} data - 事件数据 1297 * @param {Object} data - 事件数据
1301 */ 1298 */
1302 -const handleConfirmReceiveSuccess = ({ merchantId, transactionId, merchantTradeNo }) => { 1299 +const handleConfirmReceiveSuccess = async ({ merchantId, transactionId, merchantTradeNo }) => {
1303 const orders = boughtOrders.value 1300 const orders = boughtOrders.value
1304 const order = orders.find(o => o.id === merchantTradeNo) 1301 const order = orders.find(o => o.id === merchantTradeNo)
1305 1302
1306 if (order) { 1303 if (order) {
1304 + try {
1305 + // 调用买家查询收货状态接口
1306 + const response = await receiptOrderStatusAPI({ id: merchantTradeNo })
1307 +
1308 + if (response.code && response.data && response.data.status === 11) {
1309 + // 接口返回状态为11,确认收货成功
1307 order.status = 11 // 更新为已完成状态 1310 order.status = 11 // 更新为已完成状态
1311 +
1312 + Taro.showToast({
1313 + title: '确认收货成功',
1314 + icon: 'success',
1315 + duration: 2000
1316 + })
1317 + } else {
1318 + // 状态不是11,可能还在处理中
1319 + // 可以根据需要添加其他处理逻辑
1320 + }
1321 + } catch (error) {
1322 + // 查询收货状态失败,即使接口调用失败,也更新本地状态
1323 + order.status = 11
1324 + }
1308 } 1325 }
1309 } 1326 }
1310 1327
......