diff --git a/pages/cabinet/index.vue b/pages/cabinet/index.vue
index 9d00b43..1c5dabf 100755
--- a/pages/cabinet/index.vue
+++ b/pages/cabinet/index.vue
@@ -91,7 +91,7 @@
{{ getStatusText(item.status) }}
- 撤销发货
+ 撤销发货
@@ -411,7 +411,7 @@ async function loadShipments(uid) {
const products = s.products || []
let productImages = []
let productNames = []
-
+
// 从 products 数组中提取图片和名称
products.forEach(product => {
if (product) {
@@ -422,13 +422,16 @@ async function loadShipments(uid) {
productNames.push(product.name || product.title || '商品')
}
})
-
+
// 如果没有获取到任何图片,使用默认图片
if (productImages.length === 0) {
productImages = ['/static/logo.png']
productNames = ['未知商品']
}
-
+
+ // 判断是否可以撤销(48小时内且状态为待发货)
+ const canCancel = checkCanCancel(s.status, s.created_at)
+
return {
batch_no: s.batch_no || '',
count: s.count ?? (Array.isArray(s.inventory_ids) ? s.inventory_ids.length : 0),
@@ -440,7 +443,8 @@ async function loadShipments(uid) {
created_at: s.created_at || '',
shipped_at: s.shipped_at || '',
received_at: s.received_at || '',
- status: s.status || 1
+ status: s.status || 1,
+ can_cancel: canCancel
}
})
@@ -692,10 +696,39 @@ async function onShip() {
})
}
+// 检查是否可以撤销发货(48小时内)
+function checkCanCancel(status, createdAt) {
+ // 只有待发货状态(status=1)才能撤销
+ if (Number(status) !== 1) {
+ return false
+ }
+ // 没有创建时间,默认允许撤销(兼容旧数据)
+ if (!createdAt) {
+ return true
+ }
+ const created = new Date(createdAt).getTime()
+ const now = Date.now()
+ const diffHours = (now - created) / (1000 * 60 * 60)
+ // 48小时内可以撤销
+ return diffHours <= 48
+}
+
function onCancelShipping(shipment) {
const user_id = uni.getStorageSync('user_id')
const batchNo = shipment && shipment.batch_no
if (!user_id || !batchNo) return
+
+ // 前端再次检查48小时限制
+ if (!checkCanCancel(shipment.status, shipment.created_at)) {
+ uni.showModal({
+ title: '提示',
+ content: '发货申请超过48小时,不允许撤销,需要撤销发货请联系客服',
+ showCancel: false,
+ confirmText: '知道了'
+ })
+ return
+ }
+
uni.showModal({
title: '撤销发货',
content: `确认不再发货,并撤销发货单 ${batchNo} 吗?`,
@@ -711,7 +744,9 @@ function onCancelShipping(shipment) {
shippedList.value = []
await loadShipments(user_id)
} catch (e) {
- uni.showToast({ title: e?.message || '取消失败', icon: 'none' })
+ // 后端返回的错误信息可能包含"联系客服"提示
+ const msg = e?.message || '取消失败'
+ uni.showToast({ title: msg, icon: 'none' })
} finally {
}
}