"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_net_payApi = require("../../../common/js/net/payApi.js");
const common_js_conver = require("../../../common/js/conver.js");
const common_assets = require("../../../common/assets.js");
const ContainerLoading = () => "../../../components/container-loading.js";
const _sfc_main = {
  components: {
    ContainerLoading
  },
  setup() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      paySumOptions: [100, 300, 500, 1e3, 2e3, 5e3],
      currentTab: 0,
      //充值金额选项
      payMoney: 100,
      //支付金额
      currentBagTab: "MATERIAL",
      //当前套餐包tab
      bagList: [],
      //套餐包列表
      payWay: 1,
      //支付方式  1微信   2对公
      showError: false,
      errorHint: "",
      showSuccess: false,
      successHint: "",
      listLoading: "loading",
      selectBag: {},
      //选中的套餐包
      msgType: "info",
      msgTxt: "",
      primaryColor: this.globalData.primaryColor
    };
  },
  onLoad() {
    const _self = this;
    common_vendor.index.setNavigationBarTitle({
      title: "AI喵著"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        // 可选项
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    _self.doGetPackageList(_self.currentBagTab);
  },
  methods: {
    moneyTxt: common_js_conver.moneyTxt,
    doRefreshList() {
      this.doGetPackageList(this.currentBagTab);
    },
    //获取可以购买的套餐包
    doGetPackageList(path) {
      const _self = this;
      _self.listLoading = "loading";
      const data = {
        page: 1,
        rows: 20
      };
      common_js_net_payApi.PayApi.doGetBuyPackageList(path, data).then((res) => {
        common_vendor.index.__f__("log", "at pages/pay/payment/payment.vue:155", res);
        _self.listLoading = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.bagList = res.rows;
      }).catch((err2) => {
        common_vendor.index.__f__("log", "at pages/pay/payment/payment.vue:160", err2);
        _self.listLoading = "error";
        _self.msgType = "error";
        _self.msgTxt = "不好意思，没能获取到套餐数据。请您再试一次，相信马上就能看到啦。";
        _self.$refs.msg.open();
      });
    },
    //监听充值金额选项
    doChangePayMoney(e) {
      this.payMoney = e.currentTarget.dataset.value;
      this.selectBag = {};
      this.currentTab = e.currentTarget.dataset.index;
    },
    //监听充值金额变化
    obMoney(e) {
      var _self = this;
      const inputValue = e.detail.value;
      const regex = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
      if (inputValue != "") {
        if (regex.test(inputValue)) {
          _self.payMoney = e.detail.value;
          _self.selectBag = {};
          _self.currentTab = -1;
        } else {
          _self.msgTxt = "请输入数字";
          _self.msgType = "error";
          _self.$refs.msg.open();
          setTimeout(() => {
            _self.payMoney = 100;
            _self.selectBag = {};
          }, 1e3);
        }
      }
    },
    //切换套餐包
    doChangeBagTab(e) {
      this.currentBagTab = e.currentTarget.dataset.value;
      this.doGetPackageList(this.currentBagTab);
    },
    //切换支付方式
    doChangePayWay(e) {
      this.payWay = e.currentTarget.dataset.value;
    },
    //选中套餐包
    chooseBag(e) {
      const _self = this;
      const selItem = e.currentTarget.dataset.value;
      _self.payMoney = selItem.packageMoney / 100;
      _self.currentTab = -1;
      _self.selectBag = selItem;
      common_vendor.index.pageScrollTo({
        scrollTop: 0,
        duration: 300
      });
    },
    //调用微信支付
    toWeChatPay() {
      const _self = this;
      ({
        rechargeMoney: _self.payMoney,
        packageInfoId: _self.selectBag.packageInfoId ? _self.selectBag.packageInfoId : ""
      });
    },
    doPayBd(data) {
      const _self = this;
      common_vendor.index.showLoading({
        title: "支付中..."
      });
      common_js_net_payApi.PayApi.doGetBdPayParams(data).then((res) => {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("log", "at pages/pay/payment/payment.vue:235", "获取支付参数成功", res);
        if (res && res.tpOrderId) {
          const orderInfoRes = {
            dealId: res.dealId,
            appKey: res.appKey,
            totalAmount: res.totalAmount,
            tpOrderId: res.tpOrderId,
            dealTitle: res.dealTitle,
            signFieldsRange: res.signFieldsRange,
            rsaSign: res.rsaSign,
            notifyUrl: res.notifyUrl
          };
          common_vendor.index.requestPayment({
            provider: "baidu",
            orderInfo: orderInfoRes,
            success: (succRes) => {
              common_vendor.index.__f__("log", "at pages/pay/payment/payment.vue:251", "支付成功", succRes);
              _self.msgTxt = "恭喜，您的充值已成功到账！";
              _self.msgType = "success";
              _self.$refs.msg.open();
              setTimeout(() => {
                common_vendor.index.navigateBack();
              }, 1800);
            },
            fail: (failErr) => {
              common_vendor.index.__f__("log", "at pages/pay/payment/payment.vue:260", "调用支付函数失败", failErr);
              _self.msgTxt = failErr.errMsg ? failErr.errMsg : "很抱歉，本次充值失败，可能是网络不稳定或支付信息有误，请检查后重试。";
              _self.msgType = "error";
              _self.$refs.msg.open();
            }
          });
        } else {
          common_vendor.index.__f__("log", "at pages/pay/payment/payment.vue:269", "获取支付参数失败", res);
          _self.msgType = "error";
          _self.msgTxt = err.msg ? err.msg : "很抱歉，本次充值失败，可能是网络不稳定或支付信息有误，请检查后重试。";
          _self.$refs.msg.open();
        }
      }).catch((err2) => {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("log", "at pages/pay/payment/payment.vue:277", "获取支付参数失败Fail", err2);
        _self.msgType = "error";
        _self.msgTxt = err2.msg ? err2.msg : "很抱歉，本次充值失败，可能是网络不稳定或支付信息有误，请检查后重试。";
        _self.$refs.msg.open();
      });
    },
    //去支付
    doPay() {
      const _self = this;
      if (_self.payMoney > 0) {
        if (_self.payWay == "1") {
          _self.toWeChatPay();
        } else {
          const id = _self.selectBag.packageInfoId;
          const name = _self.selectBag.packageName;
          common_vendor.index.redirectTo({
            url: `/pages/pay/publicPay/publicPay?packageId=${id}&name=${name}&money=${_self.payMoney}`
          });
        }
      } else {
        _self.msgTxt = "请输入要充值的金额";
        _self.msgType = "error";
        _self.$refs.msg.open();
      }
    }
  }
};
if (!Array) {
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_component_ContainerLoading + _easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
const _easycom_uni_popup_message = () => "../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_popup_message + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_assets._imports_0$2,
    b: common_assets._imports_1,
    c: common_vendor.o((...args) => $options.obMoney && $options.obMoney(...args)),
    d: $data.payMoney,
    e: common_vendor.f($data.paySumOptions, (item, index, i0) => {
      return {
        a: common_vendor.t(item),
        b: common_vendor.n($data.currentTab == index ? "tab-select" : "tab-normal"),
        c: item,
        d: index,
        e: index
      };
    }),
    f: common_vendor.o((...args) => $options.doChangePayMoney && $options.doChangePayMoney(...args)),
    g: $data.payWay == 1,
    h: common_vendor.o((...args) => $options.doChangePayWay && $options.doChangePayWay(...args)),
    i: $data.payWay == 2,
    j: common_vendor.o((...args) => $options.doChangePayWay && $options.doChangePayWay(...args)),
    k: common_vendor.n($data.currentBagTab == "MATERIAL" ? "bag-select" : "bag-normal"),
    l: common_vendor.o((...args) => $options.doChangeBagTab && $options.doChangeBagTab(...args)),
    m: common_vendor.n($data.currentBagTab == "ALL" ? "bag-select" : "bag-normal"),
    n: common_vendor.o((...args) => $options.doChangeBagTab && $options.doChangeBagTab(...args)),
    o: common_vendor.f($data.bagList, (item, index, i0) => {
      return {
        a: common_vendor.t(item.packageName),
        b: common_vendor.t(item.packageDescription),
        c: $options.moneyTxt(10, 14, item.packageMoney / 100),
        d: item,
        e: index
      };
    }),
    p: common_vendor.o((...args) => $options.chooseBag && $options.chooseBag(...args)),
    q: common_vendor.o($options.doRefreshList),
    r: common_vendor.p({
      loadingVisible: $data.listLoading
    }),
    s: common_vendor.o((...args) => $options.doPay && $options.doPay(...args)),
    t: common_vendor.p({
      type: $data.msgType,
      message: $data.msgTxt,
      duration: 2e3
    }),
    v: common_vendor.sr("msg", "6e10c4e6-1"),
    w: common_vendor.p({
      type: "message"
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-toutiao/pages/pay/payment/payment.js.map
