"use strict";
const common_vendor = require("../../../common/vendor.js");
require("../../../common/libraries/request.js");
require("../../../common/store/useWatermarkStore.js");
require("../../../common/store/useWeAppAuthStore.js");
const common_store_useWorkStore = require("../../../common/store/useWorkStore.js");
const common_libraries_apiLoading = require("../../../common/libraries/apiLoading.js");
const common_libraries_naviHelper = require("../../../common/libraries/naviHelper.js");
const common_libraries_userUserLogin = require("../../../common/libraries/userUserLogin.js");
const gen_Apis = require("../../../gen/Apis.js");
const pages_public_select_project_model = require("./model.js");
const work = common_store_useWorkStore.useWorkStore();
const getProjectList = () => {
  var _a, _b, _c;
  if (!((_a = common_libraries_userUserLogin.getUser) == null ? void 0 : _a.getLoginStatus()))
    return;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Asset.AssetHouses.SelectProject, (_c = (_b = pages_public_select_project_model.useModel) == null ? void 0 : _b.formData) == null ? void 0 : _c.value).then((res) => {
    var _a2, _b2;
    pages_public_select_project_model.useModel.dataList.value = [...(_b2 = (_a2 = pages_public_select_project_model.useModel) == null ? void 0 : _a2.dataList) == null ? void 0 : _b2.value, ...res == null ? void 0 : res.data];
    pages_public_select_project_model.useModel.metaData.value = res == null ? void 0 : res.meta;
    console.log(res);
  });
};
const getPermission = (data) => {
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Emergency.EmergencyEventTeams.GetPermission, {
    asset_projects_id: data == null ? void 0 : data.id
  }).then((res) => {
    var _a;
    if ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.permission) {
      pages_public_select_project_model.useModel.selectedHouseEd.value = data;
      work.selectWorkProject = data;
      common_libraries_naviHelper.showToastBack("选择成功！", 1, true);
    } else {
      common_vendor.index.navigateTo({
        url: `/pages/public/select_project/pages/permission_show?id=${data == null ? void 0 : data.id}`
      });
    }
    console.log(res);
  });
};
const method = {
  getProjectList,
  // getHouseRegistersList,
  handleLoadMore(params) {
    console.log(params);
    pages_public_select_project_model.useModel.formData.value.page = params.page;
    getProjectList();
  },
  handleSelectedProject(e) {
    var _a, _b;
    if (((_b = (_a = pages_public_select_project_model.useModel) == null ? void 0 : _a.source) == null ? void 0 : _b.value) === "emergency_add") {
      getPermission(e);
    } else {
      pages_public_select_project_model.useModel.selectedHouseEd.value = e;
      work.selectWorkProject = e;
      common_libraries_naviHelper.showToastBack("选择成功！", 1, true);
    }
  },
  hadnleNewBindingHouse() {
    var _a;
    common_vendor.index.navigateTo({
      url: ((_a = common_libraries_userUserLogin.getUser) == 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;
