"use strict";
const common_vendor = require("../../../../common/vendor.js");
const common_js_net_InvoiceApi = require("../../../../common/js/net/InvoiceApi.js");
const common_js_conver = require("../../../../common/js/conver.js");
const ContainerLoading = () => "../../../../components/container-loading.js";
const _sfc_main = {
  components: {
    ContainerLoading
  },
  setup() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      imgAssets: this.globalData.imgAssetsUrl,
      primaryColor: this.globalData.primaryColor,
      msgType: "error",
      msgHint: "",
      msgShow: false,
      typeList: [],
      //开票类型
      contentList: [],
      //开票内容
      rateList: [],
      //开票税率
      typeId: "",
      contentId: "",
      rateId: "",
      invoiceInfo: null,
      //开票信息
      invoiceMoney: 0,
      //开票金额
      showInvoiceInfo: false,
      invoiceInfoList: [],
      //开票信息
      payOrderIds: "",
      //开票记录id
      remark: "",
      //备注信息
      editBean: null,
      //编辑页面传递过来的
      loadingState: "loading"
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "开发票"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#F0F0F0",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    const ids = options.ids;
    if (ids) {
      this.invoiceMoney = Number(options.money);
      this.payOrderIds = options.ids;
    } else {
      const beanStr = options.bean;
      const bean = JSON.parse(beanStr);
      this.editBean = bean;
      this.rateId = bean.invoiceTaxrate, this.contentId = bean.invoicePurpose, this.typeId = bean.invoiceClassify, this.invoiceMoney = bean.invoiceRechargeMoney, this.payOrderIds = bean.invoiceRechargeIds, this.remark = bean.invoiceRecord, this.invoiceInfo = {
        invoiceId: bean.invoiceId,
        invoiceName: bean.invoiceName,
        invoiceNumber: bean.invoiceNumber,
        invoiceOrgaddress: bean.invoiceOrgaddress,
        invoiceOrgtel: bean.invoiceOrgtel
      };
    }
    this.getPageData();
  },
  methods: {
    moneyTxt: common_js_conver.moneyTxt,
    getPageData() {
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const pageData = {
        page: 1,
        rows: 100
      };
      const _self = this;
      const type = common_js_net_InvoiceApi.InvoiceApi.doGetDicListByPId(
        "e0251d55-cd52-4f57-be92-b2bef8a6dd62"
      );
      const content = common_js_net_InvoiceApi.InvoiceApi.doGetDicListByPId(
        "b67d5208-db1d-4d0e-99de-cc22d9d50041"
      );
      const rate = common_js_net_InvoiceApi.InvoiceApi.doGetDicListByPId(
        "e4808c45-64ee-42fa-a413-a470fbdc0aea"
      );
      const info = common_js_net_InvoiceApi.InvoiceApi.doGetMineInvoiceList(pageData);
      const list = [type, content, rate, info];
      Promise.all(list).then((res) => {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineMakeInvoice/mineMakeInvoice.vue:217", res);
        _self.contentList = res[0];
        _self.rateList = res[1];
        _self.typeList = res[2];
        _self.invoiceInfoList = res[3].rows;
        if (_self.editBean == null) {
          _self.contentId = res[0][0].dataName;
          _self.rateId = res[1][0].dataName;
          _self.typeId = res[2][0].dataName;
          _self.invoiceInfo = res[3].rows[0];
        }
      }).catch((err) => {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineMakeInvoice/mineMakeInvoice.vue:232", err);
        _self.msgHint = "数据有误,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
        setTimeout(() => {
          common_vendor.index.navigateBack();
        }, 1800);
      });
    },
    inputRemark(e) {
      this.remark = e.detail.value;
    },
    changeContent(e) {
      this.contentId = e.detail.value;
    },
    changeType(e) {
      this.typeId = e.detail.value;
    },
    changeRate(e) {
      this.rateId = e.detail.value;
    },
    changeInvoiceInfo(e) {
      common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineMakeInvoice/mineMakeInvoice.vue:254", "groupChange", e);
      const index = e.detail.value;
      const selectedItem = this.invoiceInfoList[index];
      this.invoiceInfo = selectedItem;
      this.$refs.infoDialog.close();
    },
    onInvoiceItemClick(e) {
      common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineMakeInvoice/mineMakeInvoice.vue:261", e);
      this.invoiceInfo = e.currentTarget.dataset.value;
      this.$refs.infoDialog.close();
    },
    openCreateInvoiceInfo() {
      this.$refs.infoDialog.close();
      common_vendor.index.navigateTo({
        url: "/pages/mine/mineAccount/invoiceInfo/invoiceInfo"
      });
    },
    //获取开票信息
    doGetInvoiceInfoList() {
      if (this.invoiceInfoList != null && this.invoiceInfoList.length > 0) {
        this.loadingState = "success";
      } else {
        this.loadingState = "empty";
      }
      this.$refs.infoDialog.open();
    },
    //构建提交参数
    buildParams() {
      const data = {
        invoiceId: this.invoiceInfo.invoiceId,
        invoiceTaxrate: this.rateId,
        invoicePurpose: this.contentId,
        invoiceClassify: this.typeId,
        invoiceRecord: this.remark,
        accountRechargeIds: this.payOrderIds
      };
      return data;
    },
    doSaveInfo() {
      const isLegal = this.checkParams();
      if (isLegal) {
        common_vendor.index.showLoading({
          title: "提交中..."
        });
        const _self = this;
        const data = _self.buildParams();
        common_js_net_InvoiceApi.InvoiceApi.doSaveInvoiceRecord(data).then((res) => {
          common_vendor.index.hideLoading();
          common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineMakeInvoice/mineMakeInvoice.vue:304", res);
          if (res.data && res.data != "") {
            _self.msgType = "success";
            _self.msgHint = "开票信息提交成功!我们会以最快速度完成开票，还请耐心等待!";
            _self.$refs.msg.open();
            setTimeout(() => {
              _self.backPageRefresh();
            }, 1e3);
          } else {
            _self.msgType = "error";
            _self.msgHint = "发票开取失败,请稍后重试";
            _self.$refs.msg.open();
          }
        }).catch((err) => {
          common_vendor.index.hideLoading();
          _self.msgType = "error";
          _self.msgHint = err.msg ? err.msg : "发票开取失败,请稍后重试";
          _self.$refs.msg.open();
        });
      }
    },
    //校验参数
    checkParams() {
      if (this.invoiceInfo == null) {
        this.msgType = "error";
        this.msgHint = "请选择开票信息";
        this.$refs.msg.open();
        return false;
      }
      if (this.typeId == "") {
        this.msgType = "error";
        this.msgHint = "请选择开票类型";
        this.$refs.msg.open();
        return false;
      }
      if (this.contentId == "") {
        this.msgType = "error";
        this.msgHint = "请选择开票内容";
        this.$refs.msg.open();
        return false;
      }
      if (this.rateId == "") {
        this.msgType = "error";
        this.msgHint = "请选择开票税率";
        this.$refs.msg.open();
        return false;
      }
      return true;
    },
    //提交
    confirmSubmit() {
      if (this.editBean != null && this.editBean.invoiceRechargeId != "") {
        this.doEditInfo();
      } else {
        this.doSaveInfo();
      }
    },
    //编辑
    doEditInfo() {
      const isLegal = this.checkParams();
      if (isLegal) {
        const data = this.buildParams();
        const _self = this;
        common_vendor.index.showLoading({
          title: "提交中..."
        });
        common_js_net_InvoiceApi.InvoiceApi.doUpdateInvoiceRecord(_self.editBean.invoiceRechargeId, data).then((res) => {
          common_vendor.index.hideLoading();
          if (res.data && res.data != "") {
            _self.msgType = "success";
            _self.msgHint = "开票信息编辑成功!我们会以最快速度完成开票，还请耐心等待!";
            _self.$refs.msg.open();
            setTimeout(() => {
              _self.backPageRefresh();
            }, 1e3);
          } else {
            _self.msgType = "error";
            _self.msgHint = "发票信息编辑失败,请稍后重试";
            _self.$refs.msg.open();
          }
        }).catch((err) => {
          common_vendor.index.hideLoading();
          _self.msgType = "error";
          _self.msgHint = err.msg ? err.msg : "发票信息编辑失败,请稍后重试";
          _self.$refs.msg.open();
        });
      }
    },
    backPageRefresh() {
      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2];
      prevPage.$vm.needRefresh = true;
      common_vendor.index.navigateBack();
    },
    closeDialog(e) {
      this.$refs.infoDialog.close();
    }
  }
};
if (!Array) {
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  (_component_ContainerLoading + _easycom_uni_popup2 + _easycom_uni_popup_message2)();
}
const _easycom_uni_popup = () => "../../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
const _easycom_uni_popup_message = () => "../../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
if (!Math) {
  (_easycom_uni_popup + _easycom_uni_popup_message)();
}
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: common_vendor.t($data.invoiceInfo == null ? "请选择开票信息" : $data.invoiceInfo.invoiceName),
    d: common_vendor.o((...args) => $options.doGetInvoiceInfoList && $options.doGetInvoiceInfoList(...args)),
    e: common_vendor.n($data.invoiceInfo == null ? "normal-value" : "select-value"),
    f: common_vendor.f($data.typeList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.t(item.dataName),
        c: $data.typeId == item.dataName,
        d: item.dataName
      };
    }),
    g: common_vendor.o((...args) => $options.changeType && $options.changeType(...args)),
    h: common_vendor.f($data.contentList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.t(item.dataName),
        c: $data.contentId == item.dataName,
        d: item.dataName
      };
    }),
    i: common_vendor.o((...args) => $options.changeContent && $options.changeContent(...args)),
    j: common_vendor.f($data.rateList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.t(item.dataName),
        c: $data.rateId == item.dataName,
        d: item.dataName
      };
    }),
    k: common_vendor.o((...args) => $options.changeRate && $options.changeRate(...args)),
    l: $options.moneyTxt(10, 14, $data.invoiceMoney),
    m: $data.remark,
    n: common_vendor.o((...args) => $options.inputRemark && $options.inputRemark(...args)),
    o: $data.editBean != null && $data.editBean.invoiceStatus == "0"
  }, $data.editBean != null && $data.editBean.invoiceStatus == "0" ? {
    p: common_vendor.t($data.editBean.invoiceFinalRecord)
  } : {}, {
    q: common_vendor.o((...args) => $options.confirmSubmit && $options.confirmSubmit(...args)),
    r: common_vendor.o((...args) => $options.closeDialog && $options.closeDialog(...args)),
    s: common_vendor.f($data.invoiceInfoList, (item, index, i0) => {
      return common_vendor.e({
        a: index,
        b: common_vendor.t(item.invoiceName),
        c: common_vendor.t(item.invoiceNumber),
        d: common_vendor.n($data.invoiceInfo && $data.invoiceInfo.invoiceId === item.invoiceId ? "invoice-sel-item-yellow" : "invoice-sel-item-gray"),
        e: $data.invoiceInfo != null && $data.invoiceInfo.invoiceId === item.invoiceId
      }, $data.invoiceInfo != null && $data.invoiceInfo.invoiceId === item.invoiceId ? {} : {}, {
        f: item
      });
    }),
    t: common_vendor.o((...args) => $options.onInvoiceItemClick && $options.onInvoiceItemClick(...args)),
    v: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    w: common_vendor.o((...args) => $options.openCreateInvoiceInfo && $options.openCreateInvoiceInfo(...args)),
    x: common_vendor.sr("infoDialog", "a34784c2-0"),
    y: common_vendor.p({
      type: "bottom",
      ["background-color"]: "#fff",
      ["border-radius"]: "15rpx 15rpx 0rpx 0rpx"
    }),
    z: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    A: common_vendor.sr("msg", "a34784c2-2"),
    B: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a34784c2"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-baidu/pages/mine/mineAccount/mineMakeInvoice/mineMakeInvoice.js.map
