149 lines
5.5 KiB
JavaScript
149 lines
5.5 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const api_order = require("../../api/order.js");
|
|
const store_order = require("../../store/order.js");
|
|
const utils_request = require("../../utils/request.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 orderId = common_vendor.ref(0);
|
|
const statusBarHeight = common_vendor.ref(20);
|
|
const navBarHeight = common_vendor.ref(44);
|
|
try {
|
|
const sysInfo = common_vendor.index.getSystemInfoSync();
|
|
statusBarHeight.value = sysInfo.statusBarHeight || 20;
|
|
const menuBtn = common_vendor.index.getMenuButtonBoundingClientRect();
|
|
navBarHeight.value = (menuBtn.top - (sysInfo.statusBarHeight || 20)) * 2 + menuBtn.height;
|
|
} catch {
|
|
}
|
|
function goBack() {
|
|
common_vendor.index.navigateBack({ delta: 1 });
|
|
}
|
|
function fullUrl(path) {
|
|
if (!path)
|
|
return "";
|
|
if (path.startsWith("http"))
|
|
return path;
|
|
return utils_request.BASE_URL + path;
|
|
}
|
|
function getItemImage(item) {
|
|
var _a, _b;
|
|
const imgs = (_a = item.product) == null ? void 0 : _a.bannerImages;
|
|
if (imgs && imgs.length > 0)
|
|
return fullUrl(imgs[0]);
|
|
const thumb = (_b = item.product) == null ? void 0 : _b.thumb;
|
|
if (thumb)
|
|
return fullUrl(thumb);
|
|
return "";
|
|
}
|
|
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_assets._imports_0$2,
|
|
c: common_vendor.o(goBack),
|
|
d: navBarHeight.value + "px",
|
|
e: statusBarHeight.value + "px",
|
|
f: statusBarHeight.value + navBarHeight.value + "px",
|
|
g: common_vendor.f(orderItems.value, (item, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: getItemImage(item),
|
|
b: common_vendor.t(item.product.name),
|
|
c: item.specData.modelName
|
|
}, item.specData.modelName ? {
|
|
d: common_vendor.t(item.specData.modelName)
|
|
} : {}, {
|
|
e: item.specData.fineness
|
|
}, item.specData.fineness ? {
|
|
f: common_vendor.t(item.specData.fineness)
|
|
} : {}, {
|
|
g: item.specData.mainStone
|
|
}, item.specData.mainStone ? {
|
|
h: common_vendor.t(item.specData.mainStone)
|
|
} : {}, {
|
|
i: item.specData.ringSize
|
|
}, item.specData.ringSize ? {
|
|
j: common_vendor.t(item.specData.ringSize)
|
|
} : {}, {
|
|
k: item.specData.goldTotalWeight
|
|
}, item.specData.goldTotalWeight ? {
|
|
l: common_vendor.t(item.specData.goldTotalWeight)
|
|
} : {}, {
|
|
m: item.specData.goldNetWeight
|
|
}, item.specData.goldNetWeight ? {
|
|
n: common_vendor.t(item.specData.goldNetWeight)
|
|
} : {}, {
|
|
o: common_vendor.t(item.unitPrice),
|
|
p: common_vendor.t(item.quantity),
|
|
q: item.id
|
|
});
|
|
}),
|
|
h: common_vendor.t(order.value.orderNo),
|
|
i: common_vendor.t(order.value.totalPrice),
|
|
j: order.value.status === "pending"
|
|
}, order.value.status === "pending" ? {
|
|
k: common_vendor.o(handleCancel)
|
|
} : {}, {
|
|
l: common_assets._imports_1$1,
|
|
m: common_vendor.t(order.value.receiverAddress || "我的地址"),
|
|
n: common_assets._imports_2$3,
|
|
o: common_vendor.t(order.value.receiverPhone || "我的手机号"),
|
|
p: common_vendor.t(order.value.totalPrice),
|
|
q: common_vendor.o(
|
|
//@ts-ignore
|
|
(...args) => _ctx.contactService && _ctx.contactService(...args)
|
|
)
|
|
}) : {});
|
|
};
|
|
}
|
|
});
|
|
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
|