"use strict";
const common_vendor = require("../../../../common/vendor.js");
const common_js_net_InvoiceApi = require("../../../../common/js/net/InvoiceApi.js");
const common_js_validator = require("../../../../common/js/validator.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,
      localAssets: this.globalData.localAssets,
      keywords: "",
      pageData: {
        page: 1,
        rows: 10,
        keywords: ""
      },
      msgHint: "",
      msgType: "error",
      loadingState: "loading",
      listRefreshTrig: false,
      isLoadMore: false,
      hasMore: "more",
      createDialog: false,
      title: "开票信息",
      isCreate: true,
      //区别是创建 or 编辑
      companyName: "",
      //公司名称
      companyAddress: "",
      //公司地址
      companyPhone: "",
      //公司电话
      companyBank: "",
      //公司开户行
      companyBankNum: "",
      //开户行账号
      companyTinNum: "",
      //纳税人识别号
      btnTxt: "提交",
      invoiceInfoList: [],
      //开票信息列表
      tempItem: null
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "发票抬头"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#F0F0F0",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doRefreshList();
  },
  onPullDownRefresh() {
    this.doRefreshList();
  },
  methods: {
    closeDialog() {
      this.companyName = "";
      this.companyAddress = "";
      this.companyPhone = "";
      this.companyBank = "";
      this.companyBankNum = "";
      this.companyTinNum = "";
      this.tempItem = null;
      this.$refs.operateDialog.close();
    },
    showEdit(e) {
      this.tempItem = e.currentTarget.dataset.value;
      this.isCreate = false;
      this.companyName = this.tempItem.invoiceName;
      this.companyAddress = this.tempItem.invoiceOrgaddress;
      this.companyPhone = this.tempItem.invoiceOrgtel;
      this.companyBank = this.tempItem.invoiceBank;
      this.companyBankNum = this.tempItem.invoiceBanknumber;
      this.companyTinNum = this.tempItem.invoiceNumber;
      this.$refs.operateDialog.open();
    },
    showDel(e) {
      const item = e.currentTarget.dataset.value;
      const _self = this;
      common_vendor.index.showModal({
        title: "警告",
        content: "您确定要删除该开票信息吗?",
        success(res) {
          if (res.confirm) {
            _self.doDel(item);
          }
        }
      });
    },
    showCreate() {
      this.companyName = "";
      this.companyAddress = "";
      this.companyPhone = "";
      this.companyBank = "";
      this.companyBankNum = "";
      this.companyTinNum = "";
      this.tempItem = null;
      this.isCreate = true;
      this.$refs.operateDialog.open();
    },
    inputCompanyName(e) {
      this.companyName = e.detail.value;
    },
    inputCompanyAddress(e) {
      this.companyAddress = e.detail.value;
    },
    inputCompanyPhone(e) {
      this.companyPhone = e.detail.value;
    },
    inputCompanyBank(e) {
      this.companyBank = e.detail.value;
    },
    inputCompanyBankNum(e) {
      this.companyBankNum = e.detail.value;
    },
    inputCompanyTinNum(e) {
      this.companyTinNum = e.detail.value;
    },
    inputKeywords(e) {
      this.keywords = e.detail.value;
    },
    doSearchKeyWord() {
      this.doRefreshList();
    },
    clearSearch() {
      this.keywords = "";
      this.doRefreshList();
    },
    doRefreshList() {
      common_vendor.index.__f__("log", "at pages/mine/mineAccount/invoiceInfo/invoiceInfo.vue:253", "正在刷新...");
      const _self = this;
      _self.loadingState = "loading";
      _self.hasMore = "more";
      _self.pageData.page = 1;
      _self.pageData.keywords = _self.keywords;
      _self.isLoadMore = false;
      _self.doGetInvoiceInfoList(true);
    },
    doLoadMore() {
      const _self = this;
      if (_self.data.isLoadMore || _self.hasMore == "noMore") {
        return;
      }
      _self.isLoadMore = true;
      _self.hasMore = "loading";
      _self.pageData.page = ++_self.pageData.page;
      _self.pageData.keywords = _self.keywords;
      _self.doGetInvoiceInfoList(false);
    },
    doGetInvoiceInfoList(isRefresh) {
      const _self = this;
      _self.invoiceInfoList = isRefresh ? [] : _self.invoiceInfoList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_InvoiceApi.InvoiceApi.doGetMineInvoiceList(_self.pageData).then((res) => {
        common_vendor.index.stopPullDownRefresh();
        common_vendor.index.__f__("log", "at pages/mine/mineAccount/invoiceInfo/invoiceInfo.vue:281", res);
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.invoiceInfoList = _self.invoiceInfoList.concat(res.rows);
        _self.isLoadMore = false;
        _self.hasMore = _self.invoiceInfoList.length < res.total ? "more" : "noMore";
      }).catch((err) => {
        common_vendor.index.stopPullDownRefresh();
        _self.loadingState = "error";
        _self.isLoadMore = false;
        _self.hasMore = "more";
      });
    },
    //新增提交
    doAdd() {
      const isLegal = this.checkParams();
      if (isLegal) {
        const _self = this;
        common_vendor.index.showLoading({
          title: "提交中..."
        });
        const data = _self.buildParams();
        common_js_net_InvoiceApi.InvoiceApi.doSaveMineInvoiceInfo(data).then((res) => {
          common_vendor.index.hideLoading();
          _self.$refs.operateDialog.close();
          _self.msgType = "success";
          _self.msgHint = "新增开票信息成功";
          _self.$refs.msg.open();
          _self.companyAddress = "";
          _self.companyBank = "";
          _self.companyBankNum = "";
          _self.companyName = "";
          _self.companyPhone = "";
          _self.companyTinNum = "";
          _self.isCreate = true;
          _self.doRefreshList();
        }).catch((err) => {
          common_vendor.index.hideLoading();
          _self.msgType = "error";
          _self.msgHint = err.msg ? err.msg : "新增开票信息失败,请稍后重试";
          _self.$refs.msg.open();
        });
      }
    },
    //编辑提交
    doEdit() {
      const isLegal = this.checkParams();
      if (isLegal) {
        const _self = this;
        common_vendor.index.showLoading({
          title: "修改中..."
        });
        const data = _self.buildParams();
        common_js_net_InvoiceApi.InvoiceApi.doUpdateMineInvoiceInfo(_self.tempItem.invoiceId, data).then((res) => {
          common_vendor.index.hideLoading();
          _self.$refs.operateDialog.close();
          _self.msgType = "success";
          _self.msgHint = "修改开票信息成功";
          _self.$refs.msg.open();
          _self.companyAddress = "";
          _self.companyBank = "";
          _self.companyBankNum = "";
          _self.companyName = "";
          _self.companyPhone = "";
          _self.companyTinNum = "";
          _self.tempItem = null;
          _self.isCreate = true;
          _self.doRefreshList();
        }).catch((err) => {
          common_vendor.index.hideLoading();
          _self.msgType = "error";
          _self.msgHint = err.msg ? err.msg : "修改开票信息失败,请稍后重试";
          _self.$refs.msg.open();
        });
      }
    },
    //删除
    doDel(item) {
      const _self = this;
      common_vendor.index.showLoading({
        title: "删除中..."
      });
      common_js_net_InvoiceApi.InvoiceApi.doDelMineInvoiceInfo(item.invoiceId).then((res) => {
        common_vendor.index.hideLoading();
        _self.msgHint = "删除成功";
        _self.msgType = "success";
        _self.$refs.msg.open();
        _self.doRefreshList();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgHint = err.msg ? err.msg : "删除失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    },
    buildParams() {
      const _self = this;
      const data = {
        invoiceType: "企业",
        invoiceName: _self.companyName,
        invoiceNumber: _self.companyTinNum,
        invoiceOrgaddress: _self.companyAddress,
        invoiceOrgtel: _self.companyPhone,
        invoiceBank: _self.companyBank,
        invoiceBanknumber: _self.companyBankNum
      };
      return data;
    },
    checkParams() {
      if (this.companyName == "") {
        this.msgHint = "请输入公司名称";
        this.msgType = "error";
        this.$refs.msg.open();
        return false;
      }
      if (this.companyTinNum == "") {
        this.msgHint = "请输入纳税人识别号";
        this.msgType = "error";
        this.$refs.msg.open();
        return false;
      }
      if (this.companyPhone != "") {
        if (!common_js_validator.isValidPhone(this.companyPhone)) {
          this.msgHint = "请输入正确公司电话";
          this.msgType = "error";
          this.$refs.msg.open();
          return false;
        }
      }
      return true;
    }
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  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");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _easycom_uni_popup2 + _easycom_uni_popup_message2)();
}
const _easycom_uni_load_more = () => "../../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
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_load_more + _easycom_uni_popup + _easycom_uni_popup_message)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.keywords,
    b: common_vendor.o((...args) => $options.inputKeywords && $options.inputKeywords(...args)),
    c: common_vendor.o((...args) => $options.doSearchKeyWord && $options.doSearchKeyWord(...args)),
    d: $data.keywords != ""
  }, $data.keywords != "" ? {
    e: common_vendor.o((...args) => $options.clearSearch && $options.clearSearch(...args))
  } : {}, {
    f: common_vendor.o((...args) => $options.showCreate && $options.showCreate(...args)),
    g: common_vendor.f($data.invoiceInfoList, (item, index, i0) => {
      return common_vendor.e({
        a: index,
        b: common_vendor.t(item.invoiceName),
        c: item,
        d: item,
        e: common_vendor.t(item.invoiceNumber),
        f: item.invoiceOrgtel != ""
      }, item.invoiceOrgtel != "" ? {
        g: common_vendor.t(item.invoiceOrgtel)
      } : {}, {
        h: item.invoiceOrgaddress != ""
      }, item.invoiceOrgaddress != "" ? {
        i: common_vendor.t(item.invoiceOrgaddress)
      } : {});
    }),
    h: common_vendor.o((...args) => $options.showEdit && $options.showEdit(...args)),
    i: common_vendor.o((...args) => $options.showDel && $options.showDel(...args)),
    j: common_vendor.p({
      status: $data.hasMore
    }),
    k: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    l: common_vendor.j({
      "refresh": common_vendor.o($options.doRefreshList)
    }),
    m: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    n: common_vendor.o((...args) => $options.closeDialog && $options.closeDialog(...args)),
    o: common_vendor.t($data.isCreate ? "新增" : "编辑"),
    p: $data.companyName,
    q: common_vendor.o((...args) => $options.inputCompanyName && $options.inputCompanyName(...args)),
    r: $data.companyTinNum,
    s: common_vendor.o((...args) => $options.inputCompanyTinNum && $options.inputCompanyTinNum(...args)),
    t: $data.companyAddress,
    v: common_vendor.o((...args) => $options.inputCompanyAddress && $options.inputCompanyAddress(...args)),
    w: $data.companyPhone,
    x: common_vendor.o((...args) => $options.inputCompanyPhone && $options.inputCompanyPhone(...args)),
    y: $data.companyBank,
    z: common_vendor.o((...args) => $options.inputCompanyBank && $options.inputCompanyBank(...args)),
    A: $data.companyBankNum,
    B: common_vendor.o((...args) => $options.inputCompanyBankNum && $options.inputCompanyBankNum(...args)),
    C: $data.isCreate
  }, $data.isCreate ? {
    D: common_vendor.o((...args) => $options.doAdd && $options.doAdd(...args))
  } : {}, {
    E: !$data.isCreate
  }, !$data.isCreate ? {
    F: common_vendor.o((...args) => $options.doEdit && $options.doEdit(...args))
  } : {}, {
    G: common_vendor.sr("operateDialog", "4de0c8b6-2"),
    H: common_vendor.p({
      type: "bottom",
      ["background-color"]: "#fff",
      ["border-radius"]: "15rpx 15rpx 0rpx 0rpx"
    }),
    I: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    J: common_vendor.sr("msg", "4de0c8b6-3"),
    K: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-4de0c8b6"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-baidu/pages/mine/mineAccount/invoiceInfo/invoiceInfo.js.map
