"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() {
  },
  data() {
    return {
      currentStatus: "not",
      //可否开具发票tab not可以开  yes 已开
      loadingState: "loading",
      isLoadMore: false,
      listRefreshTrig: false,
      orderList: [],
      //订单列表
      pageData: {
        page: 1,
        rows: 10,
        startTime: "",
        endTime: "",
        thirdParty: ""
        //充值方式  微信  支付宝  对公转账
      },
      hasMore: "more",
      startTime: "",
      endTime: "",
      checkList: [],
      //选中的可以开票的集合
      money: 0,
      //开票金额
      msgHint: "",
      msgType: "error",
      msgShow: false
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "开发票"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#F0F0F0",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doRefreshList();
  },
  methods: {
    payWay: common_js_conver.payWay,
    moneyTxt: common_js_conver.moneyTxt,
    //下拉刷新
    doRefreshList() {
      const _self = this;
      _self.loadingState = "loading";
      _self.hasMore = "more";
      _self.pageData.page = 1;
      _self.pageData.startTime = _self.startTime;
      _self.pageData.endTime = _self.endTime;
      _self.doGetMineInvoiceOrderList(true);
    },
    //加载更多
    doLoadMore() {
      const _self = this;
      if (_self.isLoadMore || _self.hasMore == "noMore") {
        return;
      }
      _self.hasMore = "loading";
      _self.pageData.page = ++_self.pageData.page;
      _self.pageData.startTime = _self.startTime;
      _self.pageData.endTime = _self.endTime;
      _self.doGetMineInvoiceOrderList(false);
    },
    //获取我的优惠卷
    doGetMineInvoiceOrderList(isRefresh) {
      const _self = this;
      _self.orderList = isRefresh ? [] : _self.orderList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_InvoiceApi.InvoiceApi.doGetMineInvoiceOrderList(_self.pageData, _self.currentStatus).then((res) => {
        var status = "success";
        res.rows.map((item) => {
          item.checked = _self.checkList.find((value) => item.accountRechargeId == value.accountRechargeId);
          return item;
        });
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.orderList = _self.orderList.concat(res.rows);
        _self.hasMore = _self.orderList.length < res.total ? "more" : "noMore";
        _self.isLoadMore = false;
      }).catch((err) => {
        _self.loadingState = "error";
        _self.hasMore = "more";
        _self.isLoadMore = false;
      });
    },
    //选中list
    checkItem(e) {
      if (this.currentStatus == "yes")
        return;
      const value = e.currentTarget.dataset.value;
      const checkListIndex = this.checkList.findIndex((item) => item.accountRechargeId === value.accountRechargeId);
      const isHas = checkListIndex !== -1;
      const newOrderList = this.orderList.map((item) => {
        item.checked = item.accountRechargeId === value.accountRechargeId ? !isHas : item.checked;
        return item;
      });
      var newCheckList = [...this.checkList];
      if (isHas) {
        newCheckList.splice(checkListIndex, 1);
      } else {
        newCheckList.push(value);
      }
      this.checkList = newCheckList;
      this.orderList = newOrderList;
      this.money = newCheckList.length > 0 ? newCheckList.reduce((accumulator, item) => {
        return accumulator + Number(item.rechargeMoney);
      }, 0) : 0;
    },
    //去开票
    goMakeInvoice() {
      if (this.money <= 0) {
        this.msgHint = "请先选择要开票的充值记录";
        this.msgType = "error";
        this.$refs.msg.open();
      } else {
        const idArray = this.checkList.map((item) => item.accountRechargeId);
        const ids = idArray.join(",");
        common_vendor.index.redirectTo({
          url: `/pages/mine/mineAccount/mineMakeInvoice/mineMakeInvoice?money=${this.money}&ids=${ids}`
        });
      }
    }
  },
  onPullDownRefresh() {
    this.doRefreshList();
    common_vendor.index.stopPullDownRefresh();
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  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");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
const _easycom_uni_load_more = () => "../../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.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_load_more + _easycom_uni_popup_message + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.f($data.orderList, (item, index, i0) => {
      return common_vendor.e($data.currentStatus == "not" ? {
        a: item.checked
      } : {}, {
        b: common_vendor.t(item.reconciliationTime),
        c: common_vendor.n($options.payWay(item.thirdParty)),
        d: common_vendor.t(item.rechargeFinalTime),
        e: $options.moneyTxt(10, 14, item.rechargeMoney),
        f: item,
        g: index
      });
    }),
    b: $data.currentStatus == "not",
    c: common_vendor.o((...args) => $options.checkItem && $options.checkItem(...args)),
    d: common_vendor.p({
      status: $data.hasMore
    }),
    e: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    f: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    g: common_vendor.t($data.money),
    h: common_vendor.o((...args) => $options.goMakeInvoice && $options.goMakeInvoice(...args)),
    i: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    j: common_vendor.sr("msg", "01c33c28-2"),
    k: common_vendor.p({
      type: "message"
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-01c33c28"]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-toutiao/pages/mine/mineAccount/minePayOrder/minePayOrder.js.map
