"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_archive_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");
common_store_useWorkStore.useWorkStore();
const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
const getList = () => {
  var _a, _b, _c;
  if (!((_a = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _a.getLoginStatus()))
    return;
  console.log("getList", auth == null ? void 0 : auth.data);
  let OwnerArr = [];
  let NoOwnerArr = [];
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseOccupants.GetHouseOccupants, {
    ...(_c = (_b = INDEX_archive_houses_model.useModel) == null ? void 0 : _b.formData) == null ? void 0 : _c.value
  }).then((res) => {
    var _a2, _b2;
    INDEX_archive_houses_model.useModel.showData.value = res == null ? void 0 : res.data;
    (_b2 = (_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.list) == null ? void 0 : _b2.map((i) => {
      if ((i == null ? void 0 : i.house_relation) === "Owner") {
        OwnerArr == null ? void 0 : OwnerArr.push(i);
      }
      if ((i == null ? void 0 : i.house_relation) === "NonOwner") {
        NoOwnerArr == null ? void 0 : NoOwnerArr.push(i);
      }
    });
    INDEX_archive_houses_model.useModel.listData.value = [
      { label: "产权人", list: OwnerArr || [] },
      { label: "非产权人", list: NoOwnerArr || [] }
    ];
    console.log(res);
  });
};
const handleSearch = () => {
  var _a, _b, _c;
  INDEX_archive_houses_model.useModel.showData.value = {};
  INDEX_archive_houses_model.useModel.formData.value.page = 1;
  if (!((_c = (_b = (_a = INDEX_archive_houses_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value) == null ? void 0 : _c.asset_houses_id))
    return;
  getList();
};
const method = {
  getList,
  handleSearch,
  handleLoadMore(page) {
    INDEX_archive_houses_model.useModel.formData.value.page = page;
    getList();
  },
  handleUnbind() {
    var _a, _b, _c, _d;
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseOccupants.Unbind, {
      asset_houses_id: (_d = (_c = (_b = (_a = INDEX_archive_houses_model.useModel) == null ? void 0 : _a.showData) == null ? void 0 : _b.value) == null ? void 0 : _c.house_relation) == null ? void 0 : _d.asset_houses_id
    }).then((res) => {
      common_libraries_naviHelper.showToast("解绑成功！");
      common_vendor.index.switchTab({
        url: "/pages/index/index"
      });
      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"
    });
  },
  handleRemove(e) {
    common_vendor.index.showModal({
      title: "提示",
      content: "确定要移除当前人员!",
      confirmColor: "#2A7EFB",
      success: function(res) {
        var _a, _b, _c, _d;
        if (res.confirm) {
          common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseOccupants.DeleteOccupant, {
            asset_houses_id: (_d = (_c = (_b = (_a = INDEX_archive_houses_model.useModel) == null ? void 0 : _a.showData) == null ? void 0 : _b.value) == null ? void 0 : _c.house_relation) == null ? void 0 : _d.asset_houses_id,
            house_occupants_id: e == null ? void 0 : e.id
          }).then((res2) => {
            getList();
            common_libraries_naviHelper.showToast("移除成功！");
            console.log(res2);
          });
          console.log("用户点击确定");
        } else if (res.cancel) {
          console.log("用户点击取消");
        }
      }
    });
  }
};
exports.method = method;
