"use strict";
const common_vendor = require("../../../../common/vendor.js");
const common_js_net_mainUrl = require("../../../../common/js/net/mainUrl.js");
const common_js_conver = require("../../../../common/js/conver.js");
const _sfc_main = {
  setup() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      imgAssets: this.globalData.imgAssetsUrl,
      imgPrefix: common_js_net_mainUrl.previewUrl,
      detailBean: null,
      msgType: "info",
      msgHint: ""
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "详情"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#F0F0F0",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    const beanStr = options.bean;
    let bean = JSON.parse(beanStr);
    if (bean != null && bean.invoiceFile != "") {
      bean = this.parseFile(bean);
    }
    this.detailBean = bean;
  },
  methods: {
    invoiceStatusColor: common_js_conver.invoiceStatusColor,
    invoiceStatus: common_js_conver.invoiceStatus,
    moneyTxt: common_js_conver.moneyTxt,
    parseFile(bean) {
      const prefix = this.imgPrefix;
      const splits = bean.invoiceFile.split(",");
      bean.imgFileList = [];
      splits.map((item) => {
        const img = common_js_net_mainUrl.operatorPlug + prefix + item;
        bean.imgFileList.push(img);
      });
      return bean;
    },
    downloadInvoice(e) {
      const url = e.currentTarget.dataset.value;
      const _self = this;
      common_vendor.index.showLoading({
        title: "下载中..."
      });
      common_vendor.index.downloadFile({
        url,
        success: (res) => {
          common_vendor.index.__f__("log", "at pages/mine/mineAccount/invoiceDetail/invoiceDetail.vue:180", res);
          common_vendor.index.hideLoading();
          if (res.statusCode == 200) {
            _self.msgHint = "下载成功";
            _self.msgType = "success";
            _self.$refs.msg.open();
            _self.openDoc(res);
          } else {
            _self.msgHint = "下载失败,请稍后重试";
            _self.msgType = "error";
            _self.$refs.msg.open();
          }
        },
        fail: (err) => {
          common_vendor.index.hideLoading();
          _self.msgHint = err.msg ? err.msg : "下载失败,请稍后重试";
          _self.msgType = "error";
          _self.$refs.msg.open();
        }
      });
    },
    openDoc(res) {
      const canOpen = this.canOpenFile(res.tempFilePath);
      if (canOpen) {
        common_vendor.index.openDocument({
          filePath: res.tempFilePath,
          fail: (err) => {
            this.msgHint = "当前文件类型暂不支持手机查看，建议通过电脑端访问获取更好体验";
            this.msgType = "error";
            this.$refs.msg.open();
          }
        });
      } else {
        this.msgHint = "当前文件类型暂不支持手机查看，建议通过电脑端访问获取更好体验";
        this.msgType = "error";
        this.$refs.msg.open();
      }
    },
    getFileExtension(filename) {
      const ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
      return ext;
    },
    canOpenFile(filename) {
      const ext = this.getFileExtension(filename);
      return ["doc", "xls", "ppt", "pdf", "docx", "xlsx", "pptx"].includes(ext);
    }
  }
};
if (!Array) {
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_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 common_vendor.e({
    a: $data.imgAssets + "/banner_1.png",
    b: $data.imgAssets + "/banner_2.png",
    c: $data.detailBean != null
  }, $data.detailBean != null ? {
    d: common_vendor.t($options.invoiceStatus($data.detailBean.invoiceStatus)),
    e: common_vendor.n($options.invoiceStatusColor($data.detailBean.invoiceStatus))
  } : {}, {
    f: $data.detailBean != null
  }, $data.detailBean != null ? {
    g: common_vendor.t($data.detailBean.invoiceName),
    h: common_vendor.t($data.detailBean.invoiceNumber),
    i: common_vendor.t($data.detailBean.invoiceOrgaddress),
    j: common_vendor.t($data.detailBean.invoiceOrgtel),
    k: common_vendor.t($data.detailBean.invoiceBank),
    l: common_vendor.t($data.detailBean.invoiceBanknumber),
    m: common_vendor.t($data.detailBean.invoicePurpose),
    n: common_vendor.t($data.detailBean.invoiceTaxrate),
    o: common_vendor.t($data.detailBean.invoiceClassify)
  } : {}, {
    p: $data.detailBean != null
  }, $data.detailBean != null ? common_vendor.e({
    q: $options.moneyTxt(10, 14, $data.detailBean.invoiceRechargeMoney),
    r: common_vendor.t($data.detailBean.invoiceRecord),
    s: $data.detailBean != null && $data.detailBean.invoiceFile != ""
  }, $data.detailBean != null && $data.detailBean.invoiceFile != "" ? {
    t: common_vendor.f($data.detailBean.imgFileList, (item, index, i0) => {
      return {
        a: index,
        b: item
      };
    }),
    v: common_vendor.o((...args) => $options.downloadInvoice && $options.downloadInvoice(...args))
  } : {}, {
    w: $data.detailBean != null && $data.detailBean.invoiceStatus == "0"
  }, $data.detailBean != null && $data.detailBean.invoiceStatus == "0" ? {
    x: common_vendor.t($data.detailBean.invoiceFinalRecord)
  } : {}) : {}, {
    y: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    z: common_vendor.sr("msg", "74aec7b5-0"),
    A: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-74aec7b5"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-baidu/pages/mine/mineAccount/invoiceDetail/invoiceDetail.js.map
