2026-05-14 15:49:07 +08:00
|
|
|
function mapOrderStatus(status) {
|
|
|
|
|
const statusMap = {
|
|
|
|
|
pending_approve: "待审批",
|
|
|
|
|
cancel_pending: "待取消审批",
|
|
|
|
|
approved: "已审批",
|
|
|
|
|
rejected: "已驳回",
|
|
|
|
|
canceled: "已取消",
|
|
|
|
|
};
|
|
|
|
|
return statusMap[status] || status || "-";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
taskId: null,
|
|
|
|
|
loading: true,
|
|
|
|
|
actionLoading: false,
|
|
|
|
|
message: "",
|
|
|
|
|
approveOpinion: "",
|
|
|
|
|
orderInfo: null,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async onLoad(options) {
|
|
|
|
|
this.setData({
|
|
|
|
|
taskId: Number(options.id || 0),
|
|
|
|
|
});
|
|
|
|
|
await this.loadDetail();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async loadDetail() {
|
|
|
|
|
const app = getApp();
|
|
|
|
|
this.setData({ loading: true, message: "" });
|
|
|
|
|
try {
|
|
|
|
|
const data = await app.request({
|
|
|
|
|
url: `/api/orders/${this.data.taskId}`,
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
|
|
|
|
this.setData({
|
|
|
|
|
orderInfo: {
|
|
|
|
|
...data,
|
|
|
|
|
statusText: mapOrderStatus(data.order_status),
|
|
|
|
|
salePriceTotalText: Number(data.sale_price_total || 0).toFixed(2),
|
|
|
|
|
costPriceTotalText: Number(data.cost_price_total || 0).toFixed(2),
|
|
|
|
|
rebateTotalText: Number(data.rebate_total || 0).toFixed(2),
|
|
|
|
|
freightTotalText: Number(data.freight_total || 0).toFixed(2),
|
|
|
|
|
profitTotalText: Number(data.profit_total || 0).toFixed(2),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.setData({
|
|
|
|
|
message: error.message || "加载审批详情失败",
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({ loading: false });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleOpinionInput(event) {
|
|
|
|
|
this.setData({
|
|
|
|
|
approveOpinion: event.detail.value,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleApprove(event) {
|
|
|
|
|
const { result } = event.currentTarget.dataset;
|
|
|
|
|
const app = getApp();
|
|
|
|
|
const orderInfo = this.data.orderInfo;
|
|
|
|
|
if (!orderInfo) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const targetUrl = orderInfo.order_status === "cancel_pending"
|
|
|
|
|
? `/api/orders/${orderInfo.order_id}/cancel-approve`
|
|
|
|
|
: `/api/orders/${orderInfo.order_id}/approve`;
|
|
|
|
|
|
|
|
|
|
this.setData({ actionLoading: true, message: "" });
|
|
|
|
|
try {
|
|
|
|
|
await app.request({
|
|
|
|
|
url: targetUrl,
|
|
|
|
|
method: "POST",
|
|
|
|
|
data: {
|
|
|
|
|
approve_result: result,
|
|
|
|
|
approve_opinion: this.data.approveOpinion || (result === "pass" ? "同意" : "退回"),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
await this.loadDetail();
|
|
|
|
|
this.setData({
|
|
|
|
|
message: result === "pass" ? "审批处理成功" : "已完成退回处理",
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.setData({
|
|
|
|
|
message: error.message || "审批处理失败",
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({ actionLoading: false });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|