Merge pull request 'fix(shop): wire order drawer ship/after-sale to live REST' (#56) from worktree-shop-ops-contract into main
Reviewed-on: CYL/wordpress-theme-aksrt#56
This commit is contained in:
@@ -244,7 +244,7 @@ const afterSaleLoading = ref(false)
|
||||
const afterSaleForm = ref({ type: 'refund', refund_amount: 0, reason: '' })
|
||||
const afterSaleTypes = [
|
||||
{ label: '仅退款', value: 'refund' },
|
||||
{ label: '退货退款', value: 'return_refund' },
|
||||
{ label: '退货退款', value: 'refund_return' },
|
||||
{ label: '换货', value: 'exchange' },
|
||||
{ label: '维修', value: 'repair' },
|
||||
]
|
||||
@@ -276,15 +276,7 @@ async function loadOrder() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await api.request(`/shop/orders/${props.orderNumber}`)
|
||||
if (res?.data) {
|
||||
order.value = res.data
|
||||
buyer.value = res.buyer || {}
|
||||
address.value = res.address || null
|
||||
shipping.value = res.shipping || null
|
||||
afterSale.value = res.after_sale || null
|
||||
timeline.value = res.timeline || []
|
||||
refundAmount.value = res.data.amount || 0
|
||||
}
|
||||
applyOrderResponse(res)
|
||||
} catch {
|
||||
message.error('加载订单详情失败')
|
||||
} finally {
|
||||
@@ -292,6 +284,52 @@ async function loadOrder() {
|
||||
}
|
||||
}
|
||||
|
||||
function applyOrderResponse(res) {
|
||||
if (!res) return
|
||||
order.value = res.data || {}
|
||||
const ctx = res.context || {}
|
||||
buyer.value = ctx.buyer || {}
|
||||
const addr = ctx.address || null
|
||||
if (addr && !addr.full_address) {
|
||||
addr.full_address = addr.full_text || [addr.province, addr.city, addr.district, addr.address].filter(Boolean).join(' ')
|
||||
}
|
||||
address.value = addr && Object.keys(addr).length ? addr : null
|
||||
|
||||
const shipLatest = ctx.shipping?.latest || null
|
||||
if (shipLatest && Object.keys(shipLatest).length) {
|
||||
shipping.value = {
|
||||
company: shipLatest.carrier_label || shipLatest.carrier || '',
|
||||
tracking_number: shipLatest.tracking_no || '',
|
||||
shipped_at: shipLatest.created_at || '',
|
||||
status: shipLatest.status || '',
|
||||
status_label: shipLatest.status_label || '',
|
||||
tracking_detail: shipLatest.tracking_detail || [],
|
||||
}
|
||||
} else {
|
||||
shipping.value = null
|
||||
}
|
||||
|
||||
const asLatest = ctx.after_sale?.latest || null
|
||||
if (asLatest && Object.keys(asLatest).length) {
|
||||
afterSale.value = {
|
||||
type: asLatest.type || '',
|
||||
type_label: asLatest.type_label || '',
|
||||
status: asLatest.status || '',
|
||||
status_label: asLatest.status_label || '',
|
||||
refund_amount: asLatest.amount ?? asLatest.refund_amount ?? 0,
|
||||
created_at: asLatest.created_at || '',
|
||||
reason: asLatest.reason || '',
|
||||
}
|
||||
} else {
|
||||
afterSale.value = null
|
||||
}
|
||||
|
||||
timeline.value = res.timeline || []
|
||||
if (order.value.amount != null) {
|
||||
refundAmount.value = order.value.amount || 0
|
||||
}
|
||||
}
|
||||
|
||||
function resetState() {
|
||||
order.value = {}
|
||||
buyer.value = {}
|
||||
@@ -307,14 +345,7 @@ function resetState() {
|
||||
async function refreshOrder() {
|
||||
try {
|
||||
const res = await api.request(`/shop/orders/${props.orderNumber}`)
|
||||
if (res?.data) {
|
||||
order.value = res.data
|
||||
buyer.value = res.buyer || {}
|
||||
address.value = res.address || null
|
||||
shipping.value = res.shipping || null
|
||||
afterSale.value = res.after_sale || null
|
||||
timeline.value = res.timeline || []
|
||||
}
|
||||
applyOrderResponse(res)
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
@@ -333,14 +364,18 @@ async function updateStatus(status) {
|
||||
}
|
||||
|
||||
async function submitShip() {
|
||||
if (!shipForm.value.company || !shipForm.value.tracking_number) {
|
||||
message.warning('请填写物流公司和物流单号')
|
||||
return
|
||||
}
|
||||
shipLoading.value = true
|
||||
try {
|
||||
await api.request('/shop/orders/ship', {
|
||||
await api.request('/shop/shipping', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
order_number: props.orderNumber,
|
||||
company: shipForm.value.company,
|
||||
tracking_number: shipForm.value.tracking_number,
|
||||
carrier: shipForm.value.company,
|
||||
tracking_no: shipForm.value.tracking_number,
|
||||
note: shipForm.value.note,
|
||||
},
|
||||
})
|
||||
@@ -381,14 +416,18 @@ async function submitRefund() {
|
||||
}
|
||||
|
||||
async function submitAfterSale() {
|
||||
if (!afterSaleForm.value.reason) {
|
||||
message.warning('请填写售后原因')
|
||||
return
|
||||
}
|
||||
afterSaleLoading.value = true
|
||||
try {
|
||||
await api.request('/shop/orders/after-sale', {
|
||||
await api.request('/shop/after-sale', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
order_number: props.orderNumber,
|
||||
type: afterSaleForm.value.type,
|
||||
refund_amount: afterSaleForm.value.refund_amount,
|
||||
amount: afterSaleForm.value.refund_amount,
|
||||
reason: afterSaleForm.value.reason,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -491,6 +491,7 @@ class AKSRT_After_Sale {
|
||||
'status_label' => (string) ($record['status_label'] ?? ''),
|
||||
'stage' => is_array($record['stage'] ?? null) ? $record['stage'] : [],
|
||||
'amount' => (float) ($record['amount'] ?? 0),
|
||||
'reason' => (string) ($record['reason'] ?? ''),
|
||||
'created_at' => (string) ($record['created_at'] ?? ''),
|
||||
'updated_at' => (string) ($record['updated_at'] ?? ''),
|
||||
'resolved_at' => (string) ($record['resolved_at'] ?? ''),
|
||||
|
||||
Reference in New Issue
Block a user