118 lines
4.4 KiB
JavaScript
118 lines
4.4 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const api_order = require("../../api/order.js");
|
|
const store_order = require("../../store/order.js");
|
|
if (!Math) {
|
|
CustomerServiceBtn();
|
|
}
|
|
const CustomerServiceBtn = () => "../../components/CustomerServiceBtn.js";
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
__name: "detail",
|
|
setup(__props) {
|
|
const orderStore = store_order.useOrderStore();
|
|
const order = common_vendor.ref(null);
|
|
const orderItems = common_vendor.ref([]);
|
|
const showQrCode = common_vendor.ref(false);
|
|
const orderId = common_vendor.ref(0);
|
|
const STATUS_MAP = {
|
|
pending: "待支付",
|
|
paid: "已支付",
|
|
shipped: "已发货",
|
|
cancelled: "已取消"
|
|
};
|
|
const statusLabel = common_vendor.computed(() => order.value ? STATUS_MAP[order.value.status] || order.value.status : "");
|
|
common_vendor.onMounted(() => {
|
|
var _a;
|
|
const pages = getCurrentPages();
|
|
const currentPage = pages[pages.length - 1];
|
|
orderId.value = Number((_a = currentPage.options) == null ? void 0 : _a.id);
|
|
if (orderId.value) {
|
|
loadOrder(orderId.value);
|
|
}
|
|
});
|
|
common_vendor.onShow(() => {
|
|
if (orderId.value) {
|
|
loadOrder(orderId.value);
|
|
}
|
|
});
|
|
async function loadOrder(id) {
|
|
try {
|
|
const data = await api_order.getOrderDetail(id);
|
|
order.value = data;
|
|
orderItems.value = data.items || [];
|
|
orderStore.setCurrentOrder(data);
|
|
} catch {
|
|
common_vendor.index.showToast({ title: "加载订单失败", icon: "none" });
|
|
}
|
|
}
|
|
async function handleCancel() {
|
|
if (!order.value)
|
|
return;
|
|
common_vendor.index.showModal({
|
|
title: "提示",
|
|
content: "确定要取消该订单吗?",
|
|
success: async (res) => {
|
|
if (res.confirm && order.value) {
|
|
try {
|
|
await api_order.cancelOrder(order.value.id);
|
|
order.value.status = "cancelled";
|
|
orderStore.updateOrderStatus(order.value.id, "cancelled");
|
|
common_vendor.index.showToast({ title: "订单已取消", icon: "success" });
|
|
} catch {
|
|
common_vendor.index.showToast({ title: "取消订单失败", icon: "none" });
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: order.value
|
|
}, order.value ? common_vendor.e({
|
|
b: common_vendor.t(statusLabel.value),
|
|
c: common_vendor.n(`status-bar--${order.value.status}`),
|
|
d: common_vendor.f(orderItems.value, (item, k0, i0) => {
|
|
return {
|
|
a: item.product.bannerImages[0] || "",
|
|
b: common_vendor.t(item.product.name),
|
|
c: common_vendor.t(item.specData.modelName),
|
|
d: common_vendor.t(item.specData.fineness),
|
|
e: common_vendor.t(item.unitPrice),
|
|
f: common_vendor.t(item.quantity),
|
|
g: item.id
|
|
};
|
|
}),
|
|
e: common_vendor.t(order.value.orderNo),
|
|
f: common_vendor.t(order.value.totalPrice),
|
|
g: common_vendor.t(order.value.createdAt),
|
|
h: order.value.status === "paid" || order.value.status === "shipped"
|
|
}, order.value.status === "paid" || order.value.status === "shipped" ? {
|
|
i: common_vendor.t(order.value.paymentTime || "-")
|
|
} : {}, {
|
|
j: order.value.status === "shipped"
|
|
}, order.value.status === "shipped" ? {
|
|
k: common_vendor.t(order.value.shippingCompany || "-"),
|
|
l: common_vendor.t(order.value.shippingNo || "-")
|
|
} : {}, {
|
|
m: common_vendor.t(order.value.receiverName),
|
|
n: common_vendor.t(order.value.receiverPhone),
|
|
o: common_vendor.t(order.value.receiverAddress),
|
|
p: order.value.status === "pending"
|
|
}, order.value.status === "pending" ? {
|
|
q: common_vendor.o(handleCancel)
|
|
} : {}, {
|
|
r: common_vendor.o(($event) => showQrCode.value = true),
|
|
s: showQrCode.value
|
|
}, showQrCode.value ? {
|
|
t: common_vendor.o(($event) => showQrCode.value = false),
|
|
v: common_vendor.p({
|
|
mode: "qrcode"
|
|
})
|
|
} : {}) : {});
|
|
};
|
|
}
|
|
});
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6b23c96c"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/detail.js.map
|