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 afterSaleForm = ref({ type: 'refund', refund_amount: 0, reason: '' })
|
||||||
const afterSaleTypes = [
|
const afterSaleTypes = [
|
||||||
{ label: '仅退款', value: 'refund' },
|
{ label: '仅退款', value: 'refund' },
|
||||||
{ label: '退货退款', value: 'return_refund' },
|
{ label: '退货退款', value: 'refund_return' },
|
||||||
{ label: '换货', value: 'exchange' },
|
{ label: '换货', value: 'exchange' },
|
||||||
{ label: '维修', value: 'repair' },
|
{ label: '维修', value: 'repair' },
|
||||||
]
|
]
|
||||||
@@ -276,15 +276,7 @@ async function loadOrder() {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await api.request(`/shop/orders/${props.orderNumber}`)
|
const res = await api.request(`/shop/orders/${props.orderNumber}`)
|
||||||
if (res?.data) {
|
applyOrderResponse(res)
|
||||||
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
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
message.error('加载订单详情失败')
|
message.error('加载订单详情失败')
|
||||||
} finally {
|
} 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() {
|
function resetState() {
|
||||||
order.value = {}
|
order.value = {}
|
||||||
buyer.value = {}
|
buyer.value = {}
|
||||||
@@ -307,14 +345,7 @@ function resetState() {
|
|||||||
async function refreshOrder() {
|
async function refreshOrder() {
|
||||||
try {
|
try {
|
||||||
const res = await api.request(`/shop/orders/${props.orderNumber}`)
|
const res = await api.request(`/shop/orders/${props.orderNumber}`)
|
||||||
if (res?.data) {
|
applyOrderResponse(res)
|
||||||
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 || []
|
|
||||||
}
|
|
||||||
} catch { /* silent */ }
|
} catch { /* silent */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,14 +364,18 @@ async function updateStatus(status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function submitShip() {
|
async function submitShip() {
|
||||||
|
if (!shipForm.value.company || !shipForm.value.tracking_number) {
|
||||||
|
message.warning('请填写物流公司和物流单号')
|
||||||
|
return
|
||||||
|
}
|
||||||
shipLoading.value = true
|
shipLoading.value = true
|
||||||
try {
|
try {
|
||||||
await api.request('/shop/orders/ship', {
|
await api.request('/shop/shipping', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
order_number: props.orderNumber,
|
order_number: props.orderNumber,
|
||||||
company: shipForm.value.company,
|
carrier: shipForm.value.company,
|
||||||
tracking_number: shipForm.value.tracking_number,
|
tracking_no: shipForm.value.tracking_number,
|
||||||
note: shipForm.value.note,
|
note: shipForm.value.note,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -381,14 +416,18 @@ async function submitRefund() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function submitAfterSale() {
|
async function submitAfterSale() {
|
||||||
|
if (!afterSaleForm.value.reason) {
|
||||||
|
message.warning('请填写售后原因')
|
||||||
|
return
|
||||||
|
}
|
||||||
afterSaleLoading.value = true
|
afterSaleLoading.value = true
|
||||||
try {
|
try {
|
||||||
await api.request('/shop/orders/after-sale', {
|
await api.request('/shop/after-sale', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
order_number: props.orderNumber,
|
order_number: props.orderNumber,
|
||||||
type: afterSaleForm.value.type,
|
type: afterSaleForm.value.type,
|
||||||
refund_amount: afterSaleForm.value.refund_amount,
|
amount: afterSaleForm.value.refund_amount,
|
||||||
reason: afterSaleForm.value.reason,
|
reason: afterSaleForm.value.reason,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -491,6 +491,7 @@ class AKSRT_After_Sale {
|
|||||||
'status_label' => (string) ($record['status_label'] ?? ''),
|
'status_label' => (string) ($record['status_label'] ?? ''),
|
||||||
'stage' => is_array($record['stage'] ?? null) ? $record['stage'] : [],
|
'stage' => is_array($record['stage'] ?? null) ? $record['stage'] : [],
|
||||||
'amount' => (float) ($record['amount'] ?? 0),
|
'amount' => (float) ($record['amount'] ?? 0),
|
||||||
|
'reason' => (string) ($record['reason'] ?? ''),
|
||||||
'created_at' => (string) ($record['created_at'] ?? ''),
|
'created_at' => (string) ($record['created_at'] ?? ''),
|
||||||
'updated_at' => (string) ($record['updated_at'] ?? ''),
|
'updated_at' => (string) ($record['updated_at'] ?? ''),
|
||||||
'resolved_at' => (string) ($record['resolved_at'] ?? ''),
|
'resolved_at' => (string) ($record['resolved_at'] ?? ''),
|
||||||
|
|||||||
Reference in New Issue
Block a user