feat: 订单模块基本完成
This commit is contained in:
68
src/utils/orderActions.ts
Normal file
68
src/utils/orderActions.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { OrderStatus, CancelType } from "@/services/orderService";
|
||||
|
||||
export function getOrderStatus(orderData) {
|
||||
const { order_status, cancel_type } = orderData
|
||||
const unPay = order_status === OrderStatus.PENDING && cancel_type === CancelType.NONE;
|
||||
const expired =
|
||||
order_status === OrderStatus.FINISHED ||
|
||||
[CancelType.TIMEOUT, CancelType.USER].includes(cancel_type);
|
||||
|
||||
return unPay ? 'unpay' : expired ? 'expired' : 'progress'
|
||||
}
|
||||
|
||||
// scene: list、detail
|
||||
export function generateOrderActions(orderData, actions, scene) {
|
||||
|
||||
|
||||
const { handleDeleteOrder, handleCancelOrder, handleQuit, handlePayNow, handleViewGame } = actions
|
||||
|
||||
const deleteOrder = {
|
||||
text: '删除订单',
|
||||
className: 'cancelOrder',
|
||||
action: handleDeleteOrder.bind(null, orderData),
|
||||
}
|
||||
|
||||
const cancelOrder = {
|
||||
text: '取消订单',
|
||||
className: 'cancelOrder',
|
||||
action: handleCancelOrder.bind(null, orderData),
|
||||
}
|
||||
|
||||
const quitGame = {
|
||||
text: '退出活动',
|
||||
className: 'cancelOrder',
|
||||
action: handleQuit.bind(null, orderData),
|
||||
}
|
||||
|
||||
const payNow = {
|
||||
text: '立即支付',
|
||||
className: 'payNow',
|
||||
action: handlePayNow.bind(null, orderData),
|
||||
}
|
||||
|
||||
const gameDetail = {
|
||||
text: '球局详情',
|
||||
className: 'gameDetail',
|
||||
action: handleViewGame.bind(null, orderData.game_info.id),
|
||||
}
|
||||
|
||||
const key = getOrderStatus(orderData)
|
||||
|
||||
if (scene === 'list') {
|
||||
const actionMap = new Map([
|
||||
['expired', [deleteOrder, gameDetail]],
|
||||
['progress', [quitGame, gameDetail]],
|
||||
['unpay', [cancelOrder, payNow]]
|
||||
])
|
||||
return actionMap.get(key)
|
||||
}
|
||||
|
||||
if (scene === 'detail') {
|
||||
const actionMap = new Map([
|
||||
['expired', [gameDetail, deleteOrder]],
|
||||
['progress', [gameDetail, quitGame]],
|
||||
['unpay', [cancelOrder]]
|
||||
])
|
||||
return actionMap.get(key)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user