feat(shipping): 前端添加48小时撤销限制

- 添加checkCanCancel函数判断是否在48小时内
- 超过48小时不显示撤销发货按钮
- 点击撤销时如超过48小时提示'需要撤销发货请联系客服'
This commit is contained in:
Zuncle 2026-03-17 18:11:05 +08:00
parent be915a1507
commit bcbe7a9b29

View File

@ -91,7 +91,7 @@
<view class="shipment-status" :class="getStatusClass(item.status)">
{{ getStatusText(item.status) }}
</view>
<text class="shipment-cancel" v-if="Number(item.status) === 1 && item.batch_no" @tap="onCancelShipping(item)">撤销发货</text>
<text class="shipment-cancel" v-if="Number(item.status) === 1 && item.batch_no && item.can_cancel" @tap="onCancelShipping(item)">撤销发货</text>
</view>
</view>
@ -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 {
}
}