"use strict";
const common_vendor = require("../../common/vendor.js");
const gen_Apis = require("../../gen/Apis.js");
const WORKORDER_pay_model = require("./model.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const common_libraries_pay = require("../../common/libraries/pay.js");
const getShow = (timer) => {
  var _a, _b, _c;
  gen_Apis.Apis.WorkOrder.HouseWorkOrders.Show({ id: (_c = (_b = (_a = WORKORDER_pay_model.useModel) == null ? void 0 : _a.OrderInfo) == null ? void 0 : _b.value) == null ? void 0 : _c.id }).then((res) => {
    var _a2;
    WORKORDER_pay_model.useModel.loadingShowNumber.value += 1;
    WORKORDER_pay_model.useModel.orderShow.value = res == null ? void 0 : res.data;
    if (((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.payment_status) === "Paid") {
      WORKORDER_pay_model.useModel.payDisabled.value = false;
      clearInterval(timer);
      WORKORDER_pay_model.useModel.loadingLabel.value = "";
      common_vendor.index.hideLoading();
      common_vendor.index.redirectTo({
        url: "/INDEX/pay/success"
      });
    }
    console.log("orderShow", res == null ? void 0 : res.data);
  });
};
const loadShow = () => {
  WORKORDER_pay_model.useModel.loadingLabel.value = "正在更新...";
  WORKORDER_pay_model.useModel.timer.value = setInterval(() => {
    var _a, _b, _c, _d, _e;
    if (((_b = (_a = WORKORDER_pay_model.useModel) == null ? void 0 : _a.loadingShowNumber) == null ? void 0 : _b.value) > 5 && ((_e = (_d = (_c = WORKORDER_pay_model.useModel) == null ? void 0 : _c.orderShow) == null ? void 0 : _d.value) == null ? void 0 : _e.payment_status) === "Pending") {
      WORKORDER_pay_model.useModel.loading.value = false;
      WORKORDER_pay_model.useModel.payDisabled.value = false;
      WORKORDER_pay_model.useModel.loadingShowNumber.value = 0;
      WORKORDER_pay_model.useModel.loadingLabel.value = "";
      common_vendor.index.hideLoading();
      clearInterval(WORKORDER_pay_model.useModel.timer.value);
      return;
    }
    if (WORKORDER_pay_model.useModel.loadingShowNumber.value <= 5) {
      getShow(WORKORDER_pay_model.useModel.timer.value);
    }
  }, 1e3);
};
const method = {
  onPay() {
    var _a, _b, _c, _d, _e;
    WORKORDER_pay_model.useModel.loading.value = true;
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.WorkOrder.HouseWorkOrders.WorkOrderPayment, {
      id: (_c = (_b = (_a = WORKORDER_pay_model.useModel) == null ? void 0 : _a.OrderInfo) == null ? void 0 : _b.value) == null ? void 0 : _c.id,
      amount: (_e = (_d = WORKORDER_pay_model.useModel) == null ? void 0 : _d.orderShow.value) == null ? void 0 : _e.amount
    }).then((res) => {
      console.log("onPay", res == null ? void 0 : res.data);
      WORKORDER_pay_model.useModel.loading.value = false;
      WORKORDER_pay_model.useModel.payDisabled.value = true;
      common_libraries_pay.tongLianPay(
        res == null ? void 0 : res.data,
        () => {
        },
        () => {
          WORKORDER_pay_model.useModel.loading.value = false;
          WORKORDER_pay_model.useModel.payDisabled.value = false;
        }
      );
    });
  },
  loadShow,
  getShow
};
exports.method = method;
