feat: 已实现订单基本逻辑,到完成,却订单售后

This commit is contained in:
2026-07-30 15:55:36 +08:00
parent fb178d304f
commit dcc32b3d8f
34 changed files with 2534 additions and 149 deletions
@@ -11,7 +11,7 @@
color="#ff5b20"
title-active-color="#ff5b20"
>
<van-tab v-for="tab in tabs" :key="tab.label" :title="tab.label" />
<van-tab v-for="tab in tabs" :key="tab.label" :title="tab.label" :badge="tabBadge(tab)" />
</van-tabs>
<van-pull-refresh v-model="refreshing" class="order-list" @refresh="onRefresh">
@@ -89,6 +89,7 @@ import { mapActions, mapState } from 'pinia'
import { Dialog, Toast } from 'vant'
import { postFunction } from '@/api/supplied-service'
import { useUserStore } from '@/store/user'
import { savePaymentInfo } from '../../order/payment/payment-data'
import JoyfulSelectionOrdersSkeleton from '@/skeleton-view/joyful-selection/profile/orders/index.vue'
const ORDER_STATE = {
@@ -142,8 +143,7 @@ export default {
{ label: '待发货', type: 'sub-state', state: ORDER_STATE.FINISH_PAY },
{ label: '待收货', type: 'sub-state', state: ORDER_STATE.IN_PROGRESS },
{ label: '已取消', type: 'cancelled' },
{ label: '已完成', type: 'sub-state', state: ORDER_STATE.COMPLETED },
{ label: '售后', type: 'after-sale' }
{ label: '已完成', type: 'sub-state', state: ORDER_STATE.COMPLETED }
],
orderItems: [],
loading: false,
@@ -184,10 +184,24 @@ export default {
}
},
created() {
this.applyRouteTab()
this.loadOrders()
},
methods: {
...mapActions(useUserStore, ['fetchBridgeToken']),
applyRouteTab() {
const tabIndexMap = {
'pending-pay': 1,
'pending-ship': 2,
'pending-receive': 3,
completed: 5
}
const nextActive = tabIndexMap[this.$route.query.tab]
if (nextActive !== undefined) {
this.active = nextActive
}
},
previewProducts(products = []) {
return products.slice(0, 3)
},
@@ -212,7 +226,7 @@ export default {
return color || size ? [color, size].filter(Boolean).join(' | ') : '-'
},
showLogistics(order) {
return ![ORDER_STATE.CANCELLED, ORDER_STATE.COMPLETED].includes(Number(order.orderState))
return ![ORDER_STATE.PENDING_PAY, ORDER_STATE.CANCELLED, ORDER_STATE.COMPLETED].includes(Number(order.orderState))
},
actionKey(type, orderId) {
return `${type}-${orderId}`
@@ -220,13 +234,23 @@ export default {
isOperating(type, orderId) {
return this.operationKey === this.actionKey(type, orderId)
},
tabBadge(tab) {
if (tab.type !== 'pending-main') {
return undefined
}
const count = this.orderItems.filter(order => {
return order.displayType === 'main' && Number(order.orderState) === ORDER_STATE.PENDING_PAY
}).length
return count > 0 ? count : undefined
},
subActions(subOrder) {
const state = Number(subOrder.orderState)
const actions = []
if ([ORDER_STATE.IN_PROGRESS, ORDER_STATE.COMPLETED].includes(state)) {
actions.push({ orderType: ORDER_EVENT_TYPE.RETURN_ORDER, text: '退货', buttonClass: 'dark-action' })
actions.push({ orderType: ORDER_EVENT_TYPE.EXCHANGE_ORDER, text: '换货', buttonClass: 'dark-action' })
if ([ORDER_STATE.FINISH_PAY, ORDER_STATE.IN_PROGRESS, ORDER_STATE.COMPLETED].includes(state)) {
actions.push({ orderType: ORDER_EVENT_TYPE.RETURN_ORDER, text: '申请售后', buttonClass: 'dark-action' })
}
if (state === ORDER_STATE.IN_PROGRESS) {
@@ -289,13 +313,16 @@ export default {
orderActions(order) {
if (order.displayType === 'main') {
return Number(order.orderState) === ORDER_STATE.PENDING_PAY
? [{ key: 'cancel-main', orderId: order.mainOrderId, text: '取消订单', buttonClass: 'dark-action' }]
? [
{ key: 'cancel-main', orderId: order.mainOrderId, text: '取消订单', buttonClass: 'dark-action' },
{ key: 'pay-main', orderId: order.mainOrderId, text: '去支付', buttonClass: 'primary-action' }
]
: []
}
return this.subActions(order).map(action => ({
...action,
key: action.orderType,
key: action.key || action.orderType,
orderId: order.orderId
}))
},
@@ -305,12 +332,40 @@ export default {
return
}
if (action.key === 'ship-order') {
this.shipOrder(order)
return
}
if (action.key === 'pay-main') {
this.goPay(order)
return
}
if ([ORDER_EVENT_TYPE.RETURN_ORDER, ORDER_EVENT_TYPE.EXCHANGE_ORDER].includes(action.orderType)) {
this.submitAfterSale(order, action)
return
}
this.submitSubOrderEvent(
{ mainOrderId: order.mainOrderId },
order,
action
)
},
goPay(order) {
const firstProduct = this.firstProduct(order)
savePaymentInfo({
orderNo: order.mainOrderId || order.orderId,
orderNumberId: order.orderNumberId || '',
amount: Math.round(Number(order.amount || 0) * 100),
receiverName: order.receiverName || '',
receiverTel: order.receiverMobile || '',
goods: order.products || (firstProduct.id ? [firstProduct] : [])
})
this.$router.push('/joyful-selection/payment')
},
async cancelMainOrder(order) {
try {
await Dialog.confirm({
@@ -346,6 +401,81 @@ export default {
this.operationKey = ''
}
},
async shipOrder(order) {
try {
await Dialog.confirm({
title: '发货',
message: '确定将该订单更新为已发货吗?'
})
} catch (error) {
return
}
this.operationKey = this.actionKey('ship-order', order.orderId)
try {
await this.fetchBridgeToken()
if (!this.supplierId || !this.userId || !order.orderId) {
Toast('订单信息不完整,请稍后再试')
return
}
await postFunction('order-ship', {
supplierId: this.supplierId,
userId: this.userId,
orderId: order.orderId,
mainOrderId: order.mainOrderId,
deliveryStatus: 1
})
Toast('发货成功')
await this.loadOrders()
} catch (error) {
Toast(error.message || '发货失败,请稍后再试')
} finally {
this.operationKey = ''
}
},
async submitAfterSale(order, action) {
try {
await Dialog.confirm({
title: action.text,
message: `确定申请${action.text}吗?提交后将进入商家待审核。`
})
} catch (error) {
return
}
this.operationKey = this.actionKey(action.orderType, order.orderId)
try {
await this.fetchBridgeToken()
if (!this.supplierId || !this.userId || !order.mainOrderId || !order.orderId) {
Toast('订单信息不完整,请稍后再试')
return
}
await postFunction('after-sale-apply', {
supplierId: this.supplierId,
userId: this.userId,
serviceType: action.orderType,
orderId: order.orderId,
subOrderId: order.orderId,
mainOrderId: order.mainOrderId,
amount: Number(order.amount || 0),
reason: action.text
})
Toast(`${action.text}申请已提交,等待商家审核`)
await this.loadOrders()
} catch (error) {
Toast(error.message || `${action.text}申请失败,请稍后再试`)
} finally {
this.operationKey = ''
}
},
async submitSubOrderEvent(order, subOrder, action) {
try {
await Dialog.confirm({