| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_assets = require("../../common/assets.js");
- const api_order = require("../../api/order.js");
- const api_message = require("../../api/message.js");
- const _sfc_main = {
- __name: "orders",
- setup(__props) {
- const activeTab = common_vendor.ref("all");
- const tabs = [
- { name: "全部", key: "all" },
- { name: "待支付", key: "unpaid" },
- { name: "已支付", key: "paid" }
- ];
- const loading = common_vendor.ref(false);
- const orders = common_vendor.ref([]);
- const showPayModal = common_vendor.ref(false);
- const currentOrder = common_vendor.ref(null);
- const payLoading = common_vendor.ref(false);
- common_vendor.onMounted(() => {
- fetchOrders();
- });
- common_vendor.onPullDownRefresh(async () => {
- await fetchOrders();
- common_vendor.index.stopPullDownRefresh();
- });
- const fetchOrders = async () => {
- loading.value = true;
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (!userInfo || !userInfo.studentId) {
- common_vendor.index.showToast({ title: "请先登录", icon: "none" });
- return;
- }
- const res = await api_order.listOrder({
- buyerId: userInfo.studentId,
- buyerType: 2
- });
- if (res && res.rows) {
- orders.value = res.rows.map((item) => {
- const statusInfo = resolveOrderStatus(item.orderStatus, item.payStatus);
- return {
- ...item,
- id: item.id,
- orderNo: item.orderNo,
- statusKey: statusInfo.key,
- statusText: statusInfo.text,
- jobName: item.productName || item.remark || "测评服务",
- company: item.sellerName || "审计之家",
- price: item.totalAmount || "0.00",
- isDeposit: item.orderType === 2,
- createTime: formatTime(item.createTime)
- };
- });
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/my/orders.vue:148", "获取订单列表失败:", err);
- common_vendor.index.showToast({ title: "获取订单失败", icon: "none" });
- } finally {
- loading.value = false;
- }
- };
- const resolveOrderStatus = (orderStatus, payStatus) => {
- if (orderStatus === 4)
- return { key: "refunded", text: "已退款" };
- if (orderStatus === 2)
- return { key: "partial_refund", text: "部分退款" };
- if (payStatus === 1 || payStatus === 2) {
- if (orderStatus === 1)
- return { key: "paid", text: "已完成" };
- return { key: "paid", text: "已支付" };
- }
- if (orderStatus === 0 && (payStatus === 0 || payStatus === null)) {
- return { key: "unpaid", text: "待支付" };
- }
- return { key: "unknown", text: "未知状态" };
- };
- const filteredOrders = common_vendor.computed(() => {
- if (activeTab.value === "all")
- return orders.value;
- return orders.value.filter((o) => o.statusKey === activeTab.value);
- });
- const formatTime = (time) => {
- if (!time)
- return "--";
- const d = new Date(time);
- const year = d.getFullYear();
- const month = String(d.getMonth() + 1).padStart(2, "0");
- const day = String(d.getDate()).padStart(2, "0");
- const hour = String(d.getHours()).padStart(2, "0");
- const minute = String(d.getMinutes()).padStart(2, "0");
- return `${year}-${month}-${day} ${hour}:${minute}`;
- };
- const handlePay = (order) => {
- currentOrder.value = order;
- showPayModal.value = true;
- };
- const confirmPay = async () => {
- if (!currentOrder.value || payLoading.value)
- return;
- payLoading.value = true;
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
- const userId = userInfo.studentId;
- if (!userId) {
- common_vendor.index.showToast({ title: "请先登录", icon: "none" });
- return;
- }
- const businessId = currentOrder.value.businessId;
- if (!businessId) {
- common_vendor.index.showToast({ title: "该订单暂不支持在线支付", icon: "none" });
- return;
- }
- const payRes = await api_message.createWxPayOrder(businessId, userId);
- if (!(payRes.code === 200 || payRes.code === 0)) {
- common_vendor.index.showToast({ title: payRes.msg || "创建支付订单失败", icon: "none" });
- return;
- }
- showPayModal.value = false;
- if (payRes.data && payRes.data.wechatPayParams) {
- const wxPayParams = payRes.data.wechatPayParams;
- common_vendor.index.showLoading({ title: "发起微信支付..." });
- common_vendor.index.requestPayment({
- provider: "wxpay",
- timeStamp: wxPayParams.timeStamp,
- nonceStr: wxPayParams.nonceStr,
- package: wxPayParams.package,
- signType: wxPayParams.signType || "RSA",
- paySign: wxPayParams.paySign,
- success: (res) => {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "支付成功", icon: "success" });
- setTimeout(() => {
- fetchOrders();
- }, 1e3);
- },
- fail: (err) => {
- common_vendor.index.hideLoading();
- if (err.errMsg && err.errMsg.includes("cancel")) {
- common_vendor.index.showToast({ title: "已取消支付", icon: "none" });
- } else {
- common_vendor.index.showToast({ title: "支付失败,请重试", icon: "none" });
- }
- }
- });
- } else {
- common_vendor.index.showToast({ title: "支付参数异常", icon: "none" });
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/my/orders.vue:263", "支付异常:", err);
- common_vendor.index.showToast({ title: "支付异常,请重试", icon: "none" });
- } finally {
- payLoading.value = false;
- }
- };
- return (_ctx, _cache) => {
- var _a, _b;
- return common_vendor.e({
- a: common_vendor.f(tabs, (tab, k0, i0) => {
- return {
- a: common_vendor.t(tab.name),
- b: tab.key,
- c: common_vendor.n(activeTab.value === tab.key ? "active" : ""),
- d: common_vendor.o(($event) => activeTab.value = tab.key, tab.key)
- };
- }),
- b: common_vendor.f(filteredOrders.value, (order, index, i0) => {
- return common_vendor.e({
- a: common_vendor.t(order.orderNo),
- b: common_vendor.t(order.statusText),
- c: common_vendor.n(order.statusKey),
- d: common_vendor.t(order.jobName),
- e: common_vendor.t(order.company),
- f: common_vendor.t(order.price),
- g: common_vendor.t(order.createTime),
- h: order.isDeposit
- }, order.isDeposit ? {} : {}, {
- i: order.statusKey === "unpaid"
- }, order.statusKey === "unpaid" ? {
- j: common_vendor.o(($event) => handlePay(order), index)
- } : order.statusKey === "paid" ? {} : {}, {
- k: order.statusKey === "paid",
- l: index
- });
- }),
- c: filteredOrders.value.length === 0 && !loading.value
- }, filteredOrders.value.length === 0 && !loading.value ? {
- d: common_assets._imports_0$1
- } : {}, {
- e: filteredOrders.value.length > 0
- }, filteredOrders.value.length > 0 ? {} : {}, {
- f: showPayModal.value
- }, showPayModal.value ? {
- g: common_vendor.t((_a = currentOrder.value) == null ? void 0 : _a.jobName),
- h: common_vendor.t((_b = currentOrder.value) == null ? void 0 : _b.price),
- i: common_vendor.o(($event) => showPayModal.value = false),
- j: common_vendor.o(confirmPay),
- k: payLoading.value,
- l: common_vendor.o(() => {
- })
- } : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-09724fb8"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/orders.js.map
|