"use strict";
const common_vendor = require("../../common/vendor.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const gen_Apis = require("../../gen/Apis.js");
const INDEX_asset_houses_model = require("./model.js");
const common_libraries_naviHelper = require("../../common/libraries/naviHelper.js");
require("../../common/libraries/request.js");
const common_store_useWeAppAuthStore = require("../../common/store/useWeAppAuthStore.js");
const common_store_useWorkStore = require("../../common/store/useWorkStore.js");
const common_libraries_userUserLogin = require("../../common/libraries/userUserLogin.js");
const work = common_store_useWorkStore.useWorkStore();
const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
const getHouseList = () => {
  var _a, _b, _c;
  if (!((_a = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _a.getLoginStatus()))
    return;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseOccupants.List, (_c = (_b = INDEX_asset_houses_model.useModel) == null ? void 0 : _b.formData) == null ? void 0 : _c.value).then((res) => {
    INDEX_asset_houses_model.useModel.dataList.value = [...INDEX_asset_houses_model.useModel.dataList.value, ...res == null ? void 0 : res.data];
    INDEX_asset_houses_model.useModel.meta.value = res == null ? void 0 : res.meta;
    console.log(res);
  });
};
const getHouseRegistersList = () => {
  var _a, _b, _c;
  if (!((_a = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _a.getLoginStatus()))
    return;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseRegisters.List, {
    ...(_c = (_b = INDEX_asset_houses_model.useModel) == null ? void 0 : _b.formData) == null ? void 0 : _c.value,
    status: "Pending"
  }).then((res) => {
    INDEX_asset_houses_model.useModel.dataList.value = [...INDEX_asset_houses_model.useModel.dataList.value, ...res == null ? void 0 : res.data];
    INDEX_asset_houses_model.useModel.meta.value = res == null ? void 0 : res.meta;
    console.log(res);
  });
};
const method = {
  getHouseList,
  getHouseRegistersList,
  handleLoadMore(page) {
    INDEX_asset_houses_model.useModel.formData.value.page = page;
    if (INDEX_asset_houses_model.useModel.currentTabs.value === 0) {
      getHouseList();
    }
    if (INDEX_asset_houses_model.useModel.currentTabs.value === 1) {
      getHouseRegistersList();
    }
  },
  handleSelectedHouse(e) {
    var _a, _b, _c;
    if (((_b = (_a = INDEX_asset_houses_model.useModel) == null ? void 0 : _a.selectType) == null ? void 0 : _b.value) === "work_add") {
      work.selectWorkHouse = e;
      common_libraries_naviHelper.showToastBack("选择成功！", 1, true);
      return;
    }
    if ((e == null ? void 0 : e.asset_houses_id) === ((_c = INDEX_asset_houses_model.useModel.selectedHouseEd.value) == null ? void 0 : _c.id)) {
      common_libraries_naviHelper.showToast("已是该房屋！");
      return;
    }
    INDEX_asset_houses_model.useModel.selectedHouseEd.value = { id: e == null ? void 0 : e.asset_houses_id };
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseOccupants.UpdateSelectedHouse, {
      asset_houses_id: e == null ? void 0 : e.asset_houses_id
    }).then((res) => {
      auth == null ? void 0 : auth.me(() => {
        common_libraries_naviHelper.showToastBack("选择成功！", 1, true);
      });
      console.log(res);
    });
  },
  hadnleNewBindingHouse() {
    var _a;
    common_vendor.index.navigateTo({
      url: ((_a = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _a.getLoginStatus()) ? "/INDEX/binding/index" : "/pages/login"
    });
  },
  handleQueryHouseArchives(e) {
    common_vendor.index.navigateTo({
      url: `/INDEX/archive_houses/index?id=${e == null ? void 0 : e.asset_houses_id}`
    });
  }
};
exports.method = method;
