"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_cache_storage = require("../../../common/js/cache/storage.js");
const common_js_net_payApi = require("../../../common/js/net/payApi.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.js");
const common_assets = require("../../../common/assets.js");
const _sfc_main = {
  data() {
    return {
      uploadImgUrl: common_js_net_mainUrl.uploadImgUrl,
      incomeEnterprise: {},
      showError: false,
      errorHint: "",
      dateTimeArray: null,
      dateTime: null,
      selectTime: "",
      startYear: 2010,
      endYear: 2050,
      files: [],
      companyName: "",
      //公司名称
      companyBank: "",
      //开户行
      companyBankNum: "",
      //账户号码
      packageId: "",
      //套餐ID
      payMoney: 0,
      //金额
      packageName: "",
      //套餐名称
      accountRechargeId: "",
      //订单ID
      msgType: "info",
      msgTxt: "",
      imageStyles: {
        width: 72,
        height: 72,
        border: {
          color: "#F5F5F5",
          width: 1,
          style: "solid",
          radius: "2px"
        }
      }
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "对公转账"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        // 可选项
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:143", options);
    common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:145", typeof options.packageId);
    this.packageId = options.packageId && options.packageId != "undefined" ? options.packageId : "";
    this.packageName = options.name;
    this.payMoney = options.money;
    this.getEnterpriseAccountInfo();
    common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:151", this.packageId);
    this.doGetOrder();
  },
  methods: {
    //公司名称
    inputCompanyName(e) {
      this.companyName = e.detail.value;
    },
    //公司名称
    inputCompanyBank(e) {
      this.companyBank = e.detail.value;
    },
    //账号
    inputCompanyNum(e) {
      this.companyBankNum = e.detail.value;
    },
    //选中时间
    changeDateTime(e) {
      this.selectTime = e;
      common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:170", "选中时间", this.selectTime);
    },
    //获取订单编号
    doGetOrder() {
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const _self = this;
      const data = {
        packageInfoId: _self.packageId ? _self.packageId : "",
        rechargeMoney: _self.payMoney,
        thirdParty: "对公转账"
      };
      common_js_net_payApi.PayApi.doGetOrder(data).then((res) => {
        common_vendor.index.hideLoading();
        if (res.accountRechargeId && res.accountRechargeId != "") {
          _self.accountRechargeId = res.accountRechargeId;
        } else {
          _self.msgTxt = "获取订单失败,请稍后重试";
          _self.msgType = "error";
          _self.$refs.msg.open();
          setTimeout(() => {
            common_vendor.index.navigateBack();
          }, 1500);
        }
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = "获取订单失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
        setTimeout(() => {
          common_vendor.index.navigateBack();
        }, 1500);
      });
    },
    //获取收款方信息
    getEnterpriseAccountInfo() {
      const _self = this;
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      common_js_net_payApi.PayApi.doGetEnterpriseAccountInfo().then((res) => {
        common_vendor.index.hideLoading();
        _self.incomeEnterprise = res;
      }, (err) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = err.msg ? err.msg : "网络错误,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    },
    //删除图片
    delImgs() {
      this.files = [];
      this.$refs.imgPicker.clearFiles();
    },
    //上传图片
    uploadImgToNet(e) {
      common_vendor.index.showLoading({
        title: "上传中..."
      });
      const tempFilePaths = e.tempFilePaths;
      const token = common_js_cache_storage.get("token");
      const header = {};
      if (token) {
        header.Auth = `Bearer ${token}`;
      }
      var that = this;
      for (let i = 0; i < tempFilePaths.length; i++) {
        common_vendor.index.uploadFile({
          url: that.uploadImgUrl,
          header,
          filePath: tempFilePaths[i],
          name: "image",
          success(res) {
            common_vendor.index.hideLoading();
            common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:249", res);
            if (res.statusCode == 200) {
              let result = res.data;
              if (typeof res.data == "string") {
                result = JSON.parse(res.data);
              } else {
                result = res.data;
              }
              result.data.url = common_js_net_mainUrl.previewUrl + result.data.fileId;
              result.data.name = result.data.fileName;
              let lastDot = result.data.fileName.lastIndexOf(".");
              result.data.extname = result.data.fileName.substring(lastDot + 1);
              that.files = that.files.concat(result.data);
              common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:262", that.files);
            } else {
              that.msgTxt = "凭证上传失败,请稍后重试";
              that.msgType = "error";
              that.$refs.msg.open();
              that.$refs.imgPicker.clearFiles();
            }
          },
          fail(err) {
            common_vendor.index.hideLoading();
            common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:272", "错误", err);
            that.$refs.imgPicker.clearFiles();
          }
        });
      }
    },
    //完成充值
    checkParams() {
      const _self = this;
      if (_self.companyName == "") {
        _self.msgTxt = "请输入公司名称";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return false;
      }
      if (_self.companyBank == "") {
        _self.msgTxt = "请输入开户银行";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return false;
      }
      if (_self.companyBankNum == "") {
        _self.msgTxt = "请输入银行账号";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return false;
      }
      if (_self.files.length <= 0) {
        _self.msgTxt = "请上传打款凭证";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return false;
      }
      return true;
    },
    //提交
    completePay() {
      const _self = this;
      var isLegal = _self.checkParams();
      if (!isLegal) {
        return;
      }
      common_vendor.index.showLoading({
        title: "提交中..."
      });
      const fileIdStr = _self.files.map((file) => file.fileId).join(",");
      const data = {
        orgBank: _self.companyBank,
        orgName: _self.companyName,
        orgNumber: _self.companyBankNum,
        packageInfoId: _self.packageId ? _self.packageId : "",
        rechargeFinalTime: _self.selectTime,
        rechargeMoney: _self.payMoney,
        rechargeRemark: "",
        rechargeVoucher: fileIdStr,
        thirdParty: "对公转账"
      };
      common_js_net_payApi.PayApi.doCompleteEnterprisePay(_self.accountRechargeId, data).then((res) => {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("log", "at pages/pay/publicPay/publicPay.vue:332", res);
        common_vendor.index.redirectTo({
          url: "/pages/pay/payState/payState?type=1"
        });
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgType = "error";
        _self.msgTxt = err.msg ? err.msg : "网络错误,请稍后重试";
        _self.$refs.msg.open();
      });
    }
  }
};
if (!Array) {
  const _easycom_uni_datetime_picker2 = common_vendor.resolveComponent("uni-datetime-picker");
  const _easycom_uni_file_picker2 = common_vendor.resolveComponent("uni-file-picker");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_datetime_picker2 + _easycom_uni_file_picker2 + _easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
const _easycom_uni_datetime_picker = () => "../../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.js";
const _easycom_uni_file_picker = () => "../../../uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.js";
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_datetime_picker + _easycom_uni_file_picker + _easycom_uni_popup_message + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_assets._imports_0$2,
    b: common_assets._imports_1,
    c: $data.companyName,
    d: common_vendor.o((...args) => $options.inputCompanyName && $options.inputCompanyName(...args)),
    e: $data.companyBank,
    f: common_vendor.o((...args) => $options.inputCompanyBank && $options.inputCompanyBank(...args)),
    g: $data.companyBankNum,
    h: common_vendor.o((...args) => $options.inputCompanyNum && $options.inputCompanyNum(...args)),
    i: $data.selectTime == "" ? "$text-gray-hint-color" : "$text-color !important",
    j: common_vendor.j({
      "change": common_vendor.o($options.changeDateTime),
      "updateModelValue": common_vendor.o(($event) => $data.selectTime = $event)
    }),
    k: common_vendor.p({
      type: "datetime",
      border: false,
      modelValue: $data.selectTime
    }),
    l: common_vendor.sr("imgPicker", "7c5c527f-1"),
    m: common_vendor.j({
      "delete": common_vendor.o($options.delImgs),
      "select": common_vendor.o($options.uploadImgToNet)
    }),
    n: common_vendor.p({
      value: $data.files,
      ["del-icon"]: true,
      limit: "1",
      fileMediatype: "image",
      ["auto-upload"]: false,
      ["image-styles"]: $data.imageStyles
    }),
    o: common_vendor.t($data.incomeEnterprise.bankAccountName),
    p: common_vendor.t($data.incomeEnterprise.bankName),
    q: common_vendor.t($data.incomeEnterprise.bankNumber),
    r: common_vendor.t($data.incomeEnterprise.bankUnionpayNumber),
    s: common_vendor.t($data.incomeEnterprise.bankRemark),
    t: common_vendor.t($data.payMoney),
    v: $data.packageId
  }, $data.packageId ? {
    w: common_vendor.t($data.packageName)
  } : {}, {
    x: common_vendor.o((...args) => $options.completePay && $options.completePay(...args)),
    y: common_vendor.p({
      type: $data.msgType,
      message: $data.msgTxt,
      duration: 2e3
    }),
    z: common_vendor.sr("msg", "7c5c527f-2"),
    A: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/pay/publicPay/publicPay.js.map
