"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_auth = require("../../utils/auth.js"); const utils_api = require("../../utils/api.js"); const _sfc_main = { __name: "order", setup(__props) { const orders = common_vendor.ref([]); const loading = common_vendor.ref(false); const isLoggedIn = common_vendor.ref(false); let refreshTimer = null; const startAutoRefresh = () => { stopAutoRefresh(); if (!isLoggedIn.value) return; refreshTimer = setInterval(() => { if (isLoggedIn.value) { loadOrders(); } }, 3e4); }; const stopAutoRefresh = () => { if (refreshTimer) { clearInterval(refreshTimer); refreshTimer = null; } }; const checkLogin = () => { isLoggedIn.value = utils_auth.isLoggedIn(); }; const handleBack = () => { const pages = getCurrentPages(); pages.length > 1 ? common_vendor.index.navigateBack() : common_vendor.index.switchTab({ url: "/pages/mine/mine" }); }; const loadOrders = async () => { if (!isLoggedIn.value) return; loading.value = true; try { const res = await utils_api.getUserOrders(); if (res.code === 200) { orders.value = res.data || []; } } catch (e) { console.error("加载订单记录失败:", e); } finally { loading.value = false; } }; const pollOrderStatus = async (orderNo, maxRetries = 5, interval = 1e3) => { for (let i = 0; i < maxRetries; i++) { try { const res = await utils_api.queryOrder(orderNo); if (res.code === 200 && res.data && res.data.orderStatus === 1) { return true; } } catch (e) { console.log("查询订单状态失败:", e); } if (i < maxRetries - 1) { await new Promise((r) => setTimeout(r, interval)); } } return false; }; const handlePay = async (order) => { try { common_vendor.index.showLoading({ title: "正在支付..." }); const res = await utils_api.repayOrder(order.orderNo); if (res.code !== 200) { throw new Error(res.message || "获取支付参数失败"); } await utils_api.wxPay(res.data); common_vendor.index.showLoading({ title: "确认支付结果..." }); const confirmed = await pollOrderStatus(order.orderNo); if (confirmed) { common_vendor.index.showToast({ title: "支付成功", icon: "success" }); } else { common_vendor.index.showToast({ title: "支付处理中,请稍后查看", icon: "none" }); } setTimeout(() => loadOrders(), 1500); } catch (e) { common_vendor.index.showToast({ title: e.message || "支付失败", icon: "none" }); } finally { common_vendor.index.hideLoading(); } }; const getStatusClass = (status) => { switch (status) { case 0: return "status-pending"; case 1: return "status-paid"; case 2: return "status-cancelled"; default: return "status-closed"; } }; common_vendor.onLoad(() => checkLogin()); common_vendor.onMounted(() => { if (isLoggedIn.value) loadOrders(); }); common_vendor.onShow(() => { checkLogin(); if (isLoggedIn.value) loadOrders(); startAutoRefresh(); }); common_vendor.onHide(() => { stopAutoRefresh(); }); common_vendor.onUnmounted(() => { stopAutoRefresh(); }); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.o(handleBack), b: loading.value }, loading.value ? {} : orders.value.length === 0 ? {} : { d: common_vendor.f(orders.value, (order, index, i0) => { return common_vendor.e({ a: common_vendor.t(order.poolType === 1 ? "⚡" : "📈"), b: common_vendor.t(order.poolName || (order.poolType === 1 ? "超短池" : "强势池")), c: common_vendor.n(order.poolType === 1 ? "tag-orange" : "tag-purple"), d: common_vendor.t(order.orderStatusName), e: common_vendor.n(getStatusClass(order.orderStatus)), f: common_vendor.t(order.orderNo), g: common_vendor.t(order.amount), h: order.expireTime }, order.expireTime ? { i: common_vendor.t(order.expireTime) } : {}, { j: common_vendor.t(order.createTime), k: order.orderStatus === 0 }, order.orderStatus === 0 ? { l: common_vendor.o(($event) => handlePay(order), order.orderNo) } : {}, { m: order.orderNo, n: index === orders.value.length - 1 ? 1 : "" }); }) }, { c: orders.value.length === 0 }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-88bf5328"], ["__file", "D:/program/gupiao/gupiao-wx/src/pages/order/order.vue"]]); wx.createPage(MiniProgramPage);