"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_libraries_sendWxWork = require("../../../common/libraries/sendWxWork.js");
const gen_Apis = require("../../../gen/Apis.js");
const BILL_outstanding_fee_index_model = require("./model.js");
require("../../../common/libraries/request.js");
require("../../../common/store/useWatermarkStore.js");
const common_store_useWeAppAuthStore = require("../../../common/store/useWeAppAuthStore.js");
require("../../../common/store/useWorkStore.js");
const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
const getList = () => {
  var _a, _b;
  gen_Apis.Apis.Bill.HouseBills.HouseList((_b = (_a = BILL_outstanding_fee_index_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    var _a2;
    (_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.map((item) => {
      item.is_select = BILL_outstanding_fee_index_model.useModel.allSelectStatus.value;
    });
    BILL_outstanding_fee_index_model.useModel.dataList.value = [...BILL_outstanding_fee_index_model.useModel.dataList.value, ...res == null ? void 0 : res.data];
    BILL_outstanding_fee_index_model.useModel.meta.value = res == null ? void 0 : res.meta;
    console.log("登录", res == null ? void 0 : res.data);
  });
};
const method = {
  init() {
    BILL_outstanding_fee_index_model.useModel.headTabsList.value = [
      { name: "全部欠费", value: [] },
      { name: "欠费1个月以内", value: [0, 1] },
      { name: "欠费1-3个月", value: [1, 3] },
      { name: "欠费4-6个月", value: [4, 6] },
      { name: "欠费6-9个月", value: [6, 9] },
      { name: "欠费9个月以上", value: [9, 30] }
    ];
  },
  getList,
  handleSearch() {
    BILL_outstanding_fee_index_model.useModel.formData.value.page = 1;
    BILL_outstanding_fee_index_model.useModel.dataList.value = [];
    getList();
  },
  handleLoad(page) {
    BILL_outstanding_fee_index_model.useModel.formData.value.page = page;
    getList();
  },
  handleListTabsChange(e) {
    var _a, _b, _c;
    BILL_outstanding_fee_index_model.useModel.formData.value.page = 1;
    BILL_outstanding_fee_index_model.useModel.formData.value.overdue_months_range = (e == null ? void 0 : e.index) ? (_c = (_b = (_a = BILL_outstanding_fee_index_model.useModel) == null ? void 0 : _a.headTabsList) == null ? void 0 : _b.value[e == null ? void 0 : e.index]) == null ? void 0 : _c.value : void 0;
    BILL_outstanding_fee_index_model.useModel.dataList.value = [];
    getList();
    console.log("e", e);
  },
  handleSelect(idx) {
    var _a;
    let isAll = true;
    let is = BILL_outstanding_fee_index_model.useModel.dataList.value[idx].is_select;
    BILL_outstanding_fee_index_model.useModel.dataList.value[idx].is_select = !is;
    (_a = BILL_outstanding_fee_index_model.useModel.dataList.value) == null ? void 0 : _a.map((res) => {
      if (!res.is_select) {
        isAll = false;
      }
    });
    BILL_outstanding_fee_index_model.useModel.allSelectStatus.value = isAll;
  },
  handleAllSelect() {
    var _a, _b, _c;
    BILL_outstanding_fee_index_model.useModel.allSelectStatus.value = !((_b = (_a = BILL_outstanding_fee_index_model.useModel) == null ? void 0 : _a.allSelectStatus) == null ? void 0 : _b.value);
    (_c = BILL_outstanding_fee_index_model.useModel.dataList.value) == null ? void 0 : _c.map((res) => {
      res.is_select = BILL_outstanding_fee_index_model.useModel.allSelectStatus.value;
    });
  },
  toInformationTemplate() {
    var _a, _b, _c;
    let arr = [];
    (_c = (_b = (_a = BILL_outstanding_fee_index_model.useModel) == null ? void 0 : _a.dataList) == null ? void 0 : _b.value) == null ? void 0 : _c.map((res) => {
      if (res == null ? void 0 : res.is_select) {
        arr.push({
          asset_houses_id: res == null ? void 0 : res.id,
          total_unpaid_amount: parseFloat((res == null ? void 0 : res.total_overdue_amount) || 0)
        });
      }
    });
    if (!(arr == null ? void 0 : arr.length)) {
      common_vendor.index.showToast({
        title: "请至少选择一个！",
        icon: "none"
      });
      return;
    }
    common_vendor.index.navigateTo({
      url: `/BILL/information_template/index?data=${JSON.stringify(arr)}`
    });
  },
  toDetail(e) {
    common_vendor.index.navigateTo({
      url: `/BILL/outstanding_fee/show/index?id=${e == null ? void 0 : e.id}`
    });
  },
  toMassSending() {
    var _a;
    if (((_a = auth == null ? void 0 : auth.data) == null ? void 0 : _a.environment) === "wxwork") {
      common_libraries_sendWxWork.shareToExternalContact({
        externalUserIds: [],
        page: `/INDEX/bill/list/index`,
        title: `分享给您物业账单`,
        imgUrl: "https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01K5B5RY2TQQAJ1GT2RZSK426V.jpg"
      });
    } else {
      common_libraries_sendWxWork.navigateToMiniProgram({
        path: "/pages/forward/index?source=OutstandingFeeList",
        envVersion: "develop",
        extraData: { source: "OutstandingFeeList" }
      });
    }
  }
};
exports.method = method;
