"use strict"; var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; const common_vendor = require("../../../common/vendor.js"); const sheep_index = require("../../../sheep/index.js"); const sheep_api_pay_order = require("../../../sheep/api/pay/order.js"); const sheep_hooks_useGoods = require("../../../sheep/hooks/useGoods.js"); const sheep_api_trade_order = require("../../../sheep/api/trade/order.js"); const sheep_util_const = require("../../../sheep/util/const.js"); if (!Array) { const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout"); const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni"); (_easycom_s_layout2 + _component_layout_default_uni)(); } const _easycom_s_layout = () => "../../../sheep/components/s-layout/s-layout.js"; if (!Math) { _easycom_s_layout(); } const SUBSCRIBE_BTN_STATUS_STORAGE_KEY = "subscribe_btn_status"; const _sfc_main = { __name: "result", setup(__props) { const state = common_vendor.reactive({ id: 0, // 支付单号 orderType: "goods", // 订单类型 result: "unpaid", // 支付状态 orderInfo: {}, // 支付订单信息 tradeOrder: {}, // 商品订单信息,只有在 orderType 为 goods 才会请求。目的:【我的拼团】按钮的展示 counter: 0 // 获取结果次数 }); const payResult = common_vendor.computed(() => { if (state.result === "unpaid") { return "waiting"; } if (state.result === "paid") { return "success"; } if (state.result === "failed") { return "failed"; } if (state.result === "closed") { return "closed"; } }); function getOrderInfo(id) { return __async(this, null, function* () { state.counter++; const { data, code } = yield sheep_api_pay_order.PayOrderApi.getOrder(id); if (code === 0) { state.orderInfo = data; if (!state.orderInfo || state.orderInfo.status === 30) { state.result = "closed"; return; } if (state.orderInfo.status !== 0) { state.result = "paid"; common_vendor.index.showModal({ title: "支付结果", showCancel: false, // 不要取消按钮 content: "支付成功", success: () => { autoSubscribeMessage(); } }); if (state.orderType === "goods") { const { data: data2, code: code2 } = yield sheep_api_trade_order.OrderApi.getOrder(state.orderInfo.merchantOrderId); if (code2 === 0) { state.tradeOrder = data2; } } return; } } if (state.counter < 3 && state.result === "unpaid") { setTimeout(() => { getOrderInfo(id); }, 1500); } if (state.counter >= 3) { state.result = "failed"; } }); } function onOrder() { if (state.orderType === "recharge") { sheep_index.sheep.$router.redirect("/modules/mall/pay/recharge-log"); } else { sheep_index.sheep.$router.redirect("/modules/mall/order/list"); } } const showSubscribeBtn = common_vendor.ref(false); function subscribeMessage() { if (state.orderType !== "goods") { return; } const event = [sheep_util_const.WxaSubscribeTemplate.TRADE_ORDER_DELIVERY]; if (state.tradeOrder.type === 3) { event.push(sheep_util_const.WxaSubscribeTemplate.PROMOTION_COMBINATION_SUCCESS); } sheep_index.sheep.$platform.useProvider("wechat").subscribeMessage(event, () => { common_vendor.index.removeStorageSync(SUBSCRIBE_BTN_STATUS_STORAGE_KEY); common_vendor.index.setStorageSync(SUBSCRIBE_BTN_STATUS_STORAGE_KEY, "已订阅"); showSubscribeBtn.value = false; }); } function autoSubscribeMessage() { return __async(this, null, function* () { const subscribeBtnStatus = common_vendor.index.getStorageSync(SUBSCRIBE_BTN_STATUS_STORAGE_KEY); if (!subscribeBtnStatus) { showSubscribeBtn.value = true; return; } subscribeMessage(); }); } common_vendor.onLoad((options) => __async(this, null, function* () { if (options.id) { state.id = options.id; } if (options.orderType) { state.orderType = options.orderType; } if (options.payState === "fail") { state.result = "failed"; } else { yield getOrderInfo(state.id); } })); common_vendor.onShow(() => { if (common_vendor.isEmpty(state.orderInfo)) { return; } getOrderInfo(state.id); }); common_vendor.onHide(() => { state.result = "unpaid"; state.counter = 0; }); return (_ctx, _cache) => { return common_vendor.e({ a: payResult.value === "waiting" }, payResult.value === "waiting" ? {} : {}, { b: payResult.value === "success" }, payResult.value === "success" ? { c: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/order/order_pay_success.gif") } : {}, { d: ["failed", "closed"].includes(payResult.value) }, ["failed", "closed"].includes(payResult.value) ? { e: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/order/order_paty_fail.gif") } : {}, { f: payResult.value === "success" }, payResult.value === "success" ? {} : {}, { g: payResult.value === "failed" }, payResult.value === "failed" ? {} : {}, { h: payResult.value === "closed" }, payResult.value === "closed" ? {} : {}, { i: payResult.value === "waiting" }, payResult.value === "waiting" ? {} : {}, { j: payResult.value === "success" }, payResult.value === "success" ? { k: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price)) } : {}, { l: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/modules/mall/index/index")), m: payResult.value === "failed" }, payResult.value === "failed" ? { n: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.redirect("/modules/mall/pay/index", { id: state.id, orderType: state.orderType })) } : {}, { o: payResult.value === "success" }, payResult.value === "success" ? { p: common_vendor.o(onOrder) } : {}, { q: payResult.value === "success" && state.tradeOrder.type === 3 }, payResult.value === "success" && state.tradeOrder.type === 3 ? { r: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.redirect("/modules/mall/activity/groupon/order")) } : {}, { s: showSubscribeBtn.value && state.orderType === "goods" }, showSubscribeBtn.value && state.orderType === "goods" ? { t: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/order/cargo.png"), v: common_vendor.o(subscribeMessage) } : {}, { w: common_vendor.p({ title: "支付结果", bgStyle: { color: "#FFF" } }) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b4b07c54"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=result.js.map