"use strict";
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_hooks_useModal = require("../../sheep/hooks/useModal.js");
require("../../sheep/api/index.js");
require("../../sheep/api/distri/score.js");
require("../../sheep/request/index.js");
require("../../sheep/config/index.js");
require("../../sheep/store/index.js");
require("../../sheep/store/app.js");
require("../../sheep/api/promotion/diy.js");
require("../../sheep/platform/index.js");
require("../../sheep/platform/provider/wechat/index.js");
require("../../sheep/platform/provider/wechat/miniProgram.js");
require("../../sheep/api/member/auth.js");
require("../../sheep/api/member/social.js");
require("../../sheep/api/member/user.js");
require("../../sheep/platform/provider/apple/index.js");
require("../../sheep/platform/share.js");
require("../../sheep/router/index.js");
require("../../sheep/helper/throttle.js");
require("../../sheep/url/index.js");
require("../../sheep/platform/pay.js");
require("../../sheep/helper/index.js");
require("../../sheep/helper/test.js");
require("../../sheep/helper/digit.js");
require("../../sheep/store/user.js");
require("../../sheep/store/cart.js");
require("../../sheep/api/trade/cart.js");
require("../../sheep/api/pay/wallet.js");
require("../../sheep/api/promotion/coupon.js");
require("../../sheep/store/sys.js");
require("../../sheep/store/modal.js");
require("../../sheep/api/distri/share.js");
require("../../sheep/api/distri/team.js");
require("../../sheep/api/infra/file.js");
require("../../sheep/api/member/address.js");
require("../../sheep/api/member/point.js");
require("../../sheep/api/member/signin.js");
require("../../sheep/api/migration/app.js");
require("../../sheep/api/migration/chat.js");
require("../../sheep/api/migration/index.js");
require("../../sheep/api/migration/third.js");
require("../../sheep/api/pay/channel.js");
require("../../sheep/api/product/category.js");
require("../../sheep/api/product/comment.js");
require("../../sheep/api/product/favorite.js");
require("../../sheep/api/product/history.js");
require("../../sheep/api/product/spu.js");
require("../../sheep/api/promotion/activity.js");
require("../../sheep/api/promotion/article.js");
require("../../sheep/api/promotion/bargain.js");
require("../../sheep/api/promotion/combination.js");
require("../../sheep/api/promotion/rewardActivity.js");
require("../../sheep/api/promotion/seckill.js");
require("../../sheep/api/system/area.js");
require("../../sheep/api/system/voice.js");
require("../../sheep/api/trade/afterSale.js");
require("../../sheep/api/trade/brokerage.js");
require("../../sheep/api/trade/config.js");
require("../../sheep/api/trade/delivery.js");
require("../../sheep/config/zIndex.js");
require("../../sheep/util/index.js");
if (!Array) {
  const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  _easycom_s_layout2();
}
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
if (!Math) {
  _easycom_s_layout();
}
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";
      }
    });
    common_vendor.watchEffect(() => {
      if (payResult.value == "success") {
        sheep_hooks_useModal.showWalletModal({ points: state.orderInfo.jf, socialStatus: state.orderInfo.sj });
      }
    });
    async function getOrderInfo(id) {
      state.counter++;
      const {
        data,
        code
      } = await sheep_api_pay_order.PayOrderApi.getByStatus(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";
          subscribeMessage();
          if (state.orderType === "goods") {
            const {
              data: data2,
              code: code2
            } = await sheep_api_trade_order.OrderApi.getByStatus(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("/pages/pay/recharge-log");
      } else {
        sheep_index.sheep.$router.redirect("/pages/order/list");
      }
    }
    function subscribeMessage() {
      let event = ["order_dispatched"];
      if (state.tradeOrder.type === 3) {
        event.push("groupon_finish");
        event.push("groupon_fail");
      }
      sheep_index.sheep.$platform.useProvider("wechat").subscribeMessage(event);
    }
    common_vendor.onLoad(async (options) => {
      if (options.id) {
        state.id = options.id;
      }
      if (options.orderType) {
        state.orderType = options.orderType;
      }
      await getOrderInfo(state.id);
    });
    common_vendor.onShow(() => {
      if (common_vendor.lodashExports.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/images/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/images/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("/pages/index/index")),
        m: payResult.value === "failed"
      }, payResult.value === "failed" ? {
        n: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.redirect("/pages/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("/pages/activity/groupon/order"))
      } : {}, {
        s: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/cargo.png"),
        t: common_vendor.o(subscribeMessage),
        v: common_vendor.p({
          title: "支付结果",
          bgStyle: {
            color: "#FFF"
          }
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-42b1ec48"], ["__file", "D:/zx/mall-front-app/pages/pay/result.vue"]]);
wx.createPage(MiniProgramPage);
