forked from gxwebsoft/mp-10550
Compare commits
2 Commits
68d5848d3d
...
8b5609255a
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b5609255a | |||
| 31d47f0a0b |
@@ -132,61 +132,72 @@ function OrderList(props: OrderListProps) {
|
||||
const [orderToConfirmReceive, setOrderToConfirmReceive] = useState<ShopOrder | null>(null)
|
||||
const isReadOnly = props.readOnly || props.mode === 'store' || props.mode === 'rider'
|
||||
|
||||
const isOrderCompleted = (order: ShopOrder) => Number(order.orderStatus) === 1 || order.formId === 10074;
|
||||
const toNum = (v: any): number | undefined => {
|
||||
if (v === null || v === undefined || v === '') return undefined;
|
||||
const n = Number(v);
|
||||
return Number.isFinite(n) ? n : undefined;
|
||||
};
|
||||
|
||||
// “已完成”应以订单状态为准;不要用商品ID等字段推断完成态,否则会造成 Tab(待发货/待收货) 与状态文案不同步
|
||||
const isOrderCompleted = (order: ShopOrder) => toNum(order.orderStatus) === 1;
|
||||
|
||||
// 获取订单状态文本
|
||||
const getOrderStatusText = (order: ShopOrder) => {
|
||||
const orderStatus = toNum(order.orderStatus);
|
||||
const deliveryStatus = toNum(order.deliveryStatus);
|
||||
|
||||
// 优先检查订单状态
|
||||
if (order.orderStatus === 2) return '已取消';
|
||||
if (order.orderStatus === 4) return '退款申请中';
|
||||
if (order.orderStatus === 5) return '退款被拒绝';
|
||||
if (order.orderStatus === 6) return '退款成功';
|
||||
if (order.orderStatus === 7) return '客户端申请退款';
|
||||
if (orderStatus === 2) return '已取消';
|
||||
if (orderStatus === 4) return '退款申请中';
|
||||
if (orderStatus === 5) return '退款被拒绝';
|
||||
if (orderStatus === 6) return '退款成功';
|
||||
if (orderStatus === 7) return '客户端申请退款';
|
||||
if (isOrderCompleted(order)) return '已完成';
|
||||
|
||||
// 检查支付状态 (payStatus为boolean类型,false/0表示未付款,true/1表示已付款)
|
||||
if (!order.payStatus) return '等待买家付款';
|
||||
|
||||
// 已付款后检查发货状态
|
||||
if (order.deliveryStatus === 10) return '待发货';
|
||||
if (order.deliveryStatus === 20) {
|
||||
if (deliveryStatus === 10) return '待发货';
|
||||
if (deliveryStatus === 20) {
|
||||
// 若订单没有配送员,沿用原“待收货”语义
|
||||
if (!order.riderId || Number(order.riderId) === 0) return '待收货';
|
||||
// 配送员确认送达后(sendEndTime有值),才进入“待确认收货”
|
||||
if (order.sendEndTime && !isOrderCompleted(order)) return '待确认收货';
|
||||
return '配送中';
|
||||
}
|
||||
if (order.deliveryStatus === 30) return '部分发货';
|
||||
if (deliveryStatus === 30) return '部分发货';
|
||||
|
||||
if (order.orderStatus === 0) return '未使用';
|
||||
if (orderStatus === 0) return '未使用';
|
||||
|
||||
return '未知状态';
|
||||
};
|
||||
|
||||
// 获取订单状态颜色
|
||||
const getOrderStatusColor = (order: ShopOrder) => {
|
||||
const orderStatus = toNum(order.orderStatus);
|
||||
const deliveryStatus = toNum(order.deliveryStatus);
|
||||
// 优先检查订单状态
|
||||
if (order.orderStatus === 2) return 'text-gray-500'; // 已取消
|
||||
if (order.orderStatus === 4) return 'text-orange-500'; // 退款申请中
|
||||
if (order.orderStatus === 5) return 'text-red-500'; // 退款被拒绝
|
||||
if (order.orderStatus === 6) return 'text-green-500'; // 退款成功
|
||||
if (order.orderStatus === 7) return 'text-orange-500'; // 客户端申请退款
|
||||
if (orderStatus === 2) return 'text-gray-500'; // 已取消
|
||||
if (orderStatus === 4) return 'text-orange-500'; // 退款申请中
|
||||
if (orderStatus === 5) return 'text-red-500'; // 退款被拒绝
|
||||
if (orderStatus === 6) return 'text-green-500'; // 退款成功
|
||||
if (orderStatus === 7) return 'text-orange-500'; // 客户端申请退款
|
||||
if (isOrderCompleted(order)) return 'text-green-600'; // 已完成
|
||||
|
||||
// 检查支付状态
|
||||
if (!order.payStatus) return 'text-orange-500'; // 等待买家付款
|
||||
|
||||
// 已付款后检查发货状态
|
||||
if (order.deliveryStatus === 10) return 'text-blue-500'; // 待发货
|
||||
if (order.deliveryStatus === 20) {
|
||||
if (deliveryStatus === 10) return 'text-blue-500'; // 待发货
|
||||
if (deliveryStatus === 20) {
|
||||
if (!order.riderId || Number(order.riderId) === 0) return 'text-purple-500'; // 待收货
|
||||
if (order.sendEndTime && !isOrderCompleted(order)) return 'text-purple-500'; // 待确认收货
|
||||
return 'text-blue-500'; // 配送中
|
||||
}
|
||||
if (order.deliveryStatus === 30) return 'text-blue-500'; // 部分发货
|
||||
if (deliveryStatus === 30) return 'text-blue-500'; // 部分发货
|
||||
|
||||
if (order.orderStatus === 0) return 'text-gray-500'; // 未使用
|
||||
if (orderStatus === 0) return 'text-gray-500'; // 未使用
|
||||
|
||||
return 'text-gray-600'; // 默认颜色
|
||||
};
|
||||
@@ -712,17 +723,20 @@ function OrderList(props: OrderListProps) {
|
||||
{/* 订单列表 */}
|
||||
{list.length > 0 && list
|
||||
?.filter((item) => {
|
||||
const orderStatus = toNum(item.orderStatus);
|
||||
// “待收货”不展示退款中的/已退款订单,这些订单统一放到“退货/售后”
|
||||
if (tapIndex === 3 && (item.orderStatus === 4 || item.orderStatus === 6)) {
|
||||
if (tapIndex === 3 && (orderStatus === 4 || orderStatus === 6)) {
|
||||
return false;
|
||||
}
|
||||
// “退货/售后”只展示售后相关状态
|
||||
if (tapIndex === 5) {
|
||||
return item.orderStatus === 4 || item.orderStatus === 5 || item.orderStatus === 6 || item.orderStatus === 7;
|
||||
return orderStatus === 4 || orderStatus === 5 || orderStatus === 6 || orderStatus === 7;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
?.map((item, index) => {
|
||||
const orderStatus = toNum(item.orderStatus);
|
||||
const deliveryStatus = toNum(item.deliveryStatus);
|
||||
return (
|
||||
<Cell key={item.orderId ?? item.orderNo ?? index} style={{padding: '16px'}}
|
||||
onClick={() => Taro.navigateTo({url: `/shop/orderDetail/index?orderId=${item.orderId}`})}>
|
||||
@@ -737,7 +751,7 @@ function OrderList(props: OrderListProps) {
|
||||
</View>
|
||||
{/* 右侧显示合并的状态和倒计时 */}
|
||||
<View className={`${getOrderStatusColor(item)} font-medium`}>
|
||||
{!item.payStatus && item.orderStatus !== 2 ? (
|
||||
{!item.payStatus && orderStatus !== 2 ? (
|
||||
<PaymentCountdown
|
||||
expirationTime={item.expirationTime}
|
||||
createTime={item.createTime}
|
||||
@@ -801,7 +815,7 @@ function OrderList(props: OrderListProps) {
|
||||
{!isReadOnly && (
|
||||
<Space className={'btn flex justify-end'}>
|
||||
{/* 待付款状态:显示取消订单和立即支付 */}
|
||||
{(!item.payStatus) && item.orderStatus !== 2 && (
|
||||
{(!item.payStatus) && orderStatus !== 2 && (
|
||||
<Space>
|
||||
<Button size={'small'} onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
@@ -817,7 +831,7 @@ function OrderList(props: OrderListProps) {
|
||||
)}
|
||||
|
||||
{/* 待发货状态:显示申请退款 */}
|
||||
{item.payStatus && isWithinRefundWindow(item.payTime, 60) && item.deliveryStatus === 10 && item.orderStatus !== 2 && item.orderStatus !== 4 && item.orderStatus !== 6 && item.orderStatus !== 7 && !isOrderCompleted(item) && (
|
||||
{item.payStatus && isWithinRefundWindow(item.payTime, 60) && deliveryStatus === 10 && orderStatus !== 2 && orderStatus !== 4 && orderStatus !== 6 && orderStatus !== 7 && !isOrderCompleted(item) && (
|
||||
<Button size={'small'} onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
applyRefund(item);
|
||||
@@ -825,7 +839,7 @@ function OrderList(props: OrderListProps) {
|
||||
)}
|
||||
|
||||
{/* 待收货状态:显示查看物流和确认收货 */}
|
||||
{item.deliveryStatus === 20 && (!item.riderId || Number(item.riderId) === 0 || !!item.sendEndTime) && item.orderStatus !== 2 && item.orderStatus !== 6 && !isOrderCompleted(item) && (
|
||||
{deliveryStatus === 20 && (!item.riderId || Number(item.riderId) === 0 || !!item.sendEndTime) && orderStatus !== 2 && orderStatus !== 6 && !isOrderCompleted(item) && (
|
||||
<Space>
|
||||
{/*<Button size={'small'} onClick={(e) => {*/}
|
||||
{/* e.stopPropagation();*/}
|
||||
@@ -839,7 +853,7 @@ function OrderList(props: OrderListProps) {
|
||||
)}
|
||||
|
||||
{/* 退款/售后状态:显示查看进度和撤销申请 */}
|
||||
{(item.orderStatus === 4 || item.orderStatus === 7) && (
|
||||
{(orderStatus === 4 || orderStatus === 7) && (
|
||||
<Space>
|
||||
{/*<Button size={'small'} onClick={(e) => {*/}
|
||||
{/* e.stopPropagation();*/}
|
||||
|
||||
@@ -81,6 +81,8 @@ const OrderConfirm = () => {
|
||||
const [deliveryRangeChecking, setDeliveryRangeChecking] = useState(false)
|
||||
const deliveryRangeCheckingRef = useRef(false)
|
||||
const [inDeliveryRange, setInDeliveryRange] = useState<boolean | undefined>(undefined)
|
||||
// Prevent using stale `inDeliveryRange` from a previous address when user switches addresses.
|
||||
const [deliveryRangeCheckedAddressId, setDeliveryRangeCheckedAddressId] = useState<number | undefined>(undefined)
|
||||
|
||||
const router = Taro.getCurrentInstance().router;
|
||||
const goodsId = router?.params?.goodsId;
|
||||
@@ -249,12 +251,11 @@ const OrderConfirm = () => {
|
||||
}
|
||||
|
||||
const getCheckPoint = async (): Promise<{ lng: number; lat: number }> => {
|
||||
// Prefer address coords (delivery location). Fallback to current GPS if address doesn't have coords.
|
||||
// Immediate water delivery must validate by the delivery address coordinates.
|
||||
// Falling back to current GPS may allow ordering with an out-of-fence address.
|
||||
const byAddress = parseLngLatFromText(`${address?.lng || ''},${address?.lat || ''}`)
|
||||
if (byAddress) return byAddress
|
||||
|
||||
const loc = await Taro.getLocation({ type: 'gcj02' })
|
||||
return { lng: loc.longitude, lat: loc.latitude }
|
||||
throw new Error('该收货地址缺少经纬度,请在地址里选择地图定位后重试')
|
||||
}
|
||||
|
||||
const ensureInDeliveryRange = async (): Promise<boolean> => {
|
||||
@@ -265,6 +266,7 @@ const OrderConfirm = () => {
|
||||
const p = await getCheckPoint()
|
||||
const ok = await isPointInFence(p)
|
||||
setInDeliveryRange(ok)
|
||||
setDeliveryRangeCheckedAddressId(address?.id)
|
||||
if (!ok) {
|
||||
Taro.showToast({ title: '不在配送范围内,暂不支持下单', icon: 'none' })
|
||||
}
|
||||
@@ -272,30 +274,8 @@ const OrderConfirm = () => {
|
||||
} catch (e: any) {
|
||||
console.error('配送范围校验失败:', e)
|
||||
setInDeliveryRange(undefined)
|
||||
|
||||
const msg = String(e?.errMsg || e?.message || '')
|
||||
const denied =
|
||||
msg.includes('auth deny') ||
|
||||
msg.includes('authorize') ||
|
||||
msg.includes('permission') ||
|
||||
msg.includes('denied') ||
|
||||
msg.includes('scope.userLocation')
|
||||
|
||||
if (denied) {
|
||||
const r = await Taro.showModal({
|
||||
title: '需要定位权限',
|
||||
content: '下单前需要校验是否在配送范围内,请在设置中开启定位权限后重试。',
|
||||
confirmText: '去设置'
|
||||
})
|
||||
if (r.confirm) {
|
||||
try {
|
||||
await Taro.openSetting()
|
||||
} catch (_e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
// Note: we validate by address coords only; no GPS permission prompt here.
|
||||
|
||||
Taro.showToast({ title: e?.message || '配送范围校验失败,请稍后重试', icon: 'none' })
|
||||
return false
|
||||
@@ -504,6 +484,10 @@ const OrderConfirm = () => {
|
||||
Taro.showToast({ title: '请选择收货地址', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!addressHasCoords) {
|
||||
Taro.showToast({ title: '该收货地址缺少经纬度,请在地址里选择地图定位后重试', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure ticket list is loaded.
|
||||
if (ticketLoading) {
|
||||
@@ -655,6 +639,11 @@ const OrderConfirm = () => {
|
||||
loadAllData({ silent: hasInitialLoadedRef.current })
|
||||
})
|
||||
|
||||
const addressHasCoords = useMemo(() => {
|
||||
if (!address?.id) return false
|
||||
return !!parseLngLatFromText(`${address?.lng || ''},${address?.lat || ''}`)
|
||||
}, [address?.id, address?.lng, address?.lat])
|
||||
|
||||
// Auto-pick nearest store by delivery address (best-effort, won't override manual selection).
|
||||
useEffect(() => {
|
||||
if (!address?.id) return
|
||||
@@ -667,17 +656,35 @@ const OrderConfirm = () => {
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
if (!address?.id) {
|
||||
setInDeliveryRange(undefined)
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
return
|
||||
}
|
||||
const p = parseLngLatFromText(`${address?.lng || ''},${address?.lat || ''}`)
|
||||
if (!p) return
|
||||
if (!p) {
|
||||
// Cannot validate without address coords -> treat as out of range to block ordering.
|
||||
setInDeliveryRange(false)
|
||||
setDeliveryRangeCheckedAddressId(address.id)
|
||||
return
|
||||
}
|
||||
// Avoid keeping stale state from previous address while we validate this one.
|
||||
setInDeliveryRange(undefined)
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
let ok = true
|
||||
try {
|
||||
ok = await isPointInFence(p)
|
||||
} catch (_e) {
|
||||
// Pre-check is best-effort; don't block UI here.
|
||||
if (!cancelled) {
|
||||
setInDeliveryRange(undefined)
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (cancelled) return
|
||||
setInDeliveryRange(ok)
|
||||
setDeliveryRangeCheckedAddressId(address.id)
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
@@ -685,6 +692,18 @@ const OrderConfirm = () => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [address?.id, address?.lng, address?.lat])
|
||||
|
||||
// When user changes the delivery address to an out-of-fence one, prompt immediately (once per address).
|
||||
const outOfRangePromptedAddressIdRef = useRef<number | undefined>(undefined)
|
||||
useEffect(() => {
|
||||
const id = address?.id
|
||||
if (!id) return
|
||||
if (deliveryRangeCheckedAddressId !== id) return
|
||||
if (inDeliveryRange !== false) return
|
||||
if (outOfRangePromptedAddressIdRef.current === id) return
|
||||
outOfRangePromptedAddressIdRef.current = id
|
||||
Taro.showToast({ title: addressHasCoords ? '该地址不在配送范围,请更换围栏内地址' : '该地址缺少定位,请在地址里选择地图定位后重试', icon: 'none' })
|
||||
}, [address?.id, addressHasCoords, deliveryRangeCheckedAddressId, inDeliveryRange])
|
||||
|
||||
// When tickets/stock change, clamp quantity into [0..maxQuantity].
|
||||
useEffect(() => {
|
||||
setQuantity(prev => {
|
||||
@@ -761,7 +780,10 @@ const OrderConfirm = () => {
|
||||
<CellGroup>
|
||||
{
|
||||
address && (
|
||||
<Cell className={'address-bottom-line'}>
|
||||
<Cell
|
||||
className={'address-bottom-line'}
|
||||
onClick={() => Taro.navigateTo({ url: '/user/address/index' })}
|
||||
>
|
||||
<Space>
|
||||
<Location className={'text-gray-500'}/>
|
||||
<View className={'flex flex-col w-full justify-between items-start'}>
|
||||
@@ -1037,7 +1059,9 @@ const OrderConfirm = () => {
|
||||
loading={submitLoading || deliveryRangeChecking}
|
||||
disabled={
|
||||
deliveryRangeChecking ||
|
||||
inDeliveryRange === false ||
|
||||
!address?.id ||
|
||||
!addressHasCoords ||
|
||||
(deliveryRangeCheckedAddressId === address?.id && inDeliveryRange === false) ||
|
||||
availableTicketTotal <= 0 ||
|
||||
!canStartOrder
|
||||
}
|
||||
@@ -1045,7 +1069,16 @@ const OrderConfirm = () => {
|
||||
>
|
||||
{deliveryRangeChecking
|
||||
? '校验配送范围...'
|
||||
: (inDeliveryRange === false ? '不在配送范围' : (submitLoading ? '提交中...' : '立即提交'))
|
||||
: (!address?.id
|
||||
? '请选择地址'
|
||||
: (!addressHasCoords
|
||||
? '地址缺少定位'
|
||||
: ((deliveryRangeCheckedAddressId === address?.id && inDeliveryRange === false)
|
||||
? '不在配送范围'
|
||||
: (submitLoading ? '提交中...' : '立即提交')
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user