"use strict";
const common_vendor = require("../../common/vendor.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const common_libraries_tools = require("../../common/libraries/tools.js");
const gen_Apis = require("../../gen/Apis.js");
require("../../common/libraries/request.js");
require("../../common/store/useWeAppAuthStore.js");
require("../../common/store/useWatermarkStore.js");
require("../../common/store/useWorkStore.js");
if (!Array) {
  const _easycom_hs_cell2 = common_vendor.resolveComponent("hs-cell");
  const _easycom_up_tabs2 = common_vendor.resolveComponent("up-tabs");
  const _easycom_hs_empty2 = common_vendor.resolveComponent("hs-empty");
  const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  const _easycom_hs_popup2 = common_vendor.resolveComponent("hs-popup");
  (_easycom_hs_cell2 + _easycom_up_tabs2 + _easycom_hs_empty2 + _easycom_uni_icons2 + _easycom_hs_popup2)();
}
const _easycom_hs_cell = () => "../hs-cell/hs-cell.js";
const _easycom_up_tabs = () => "../../node-modules/uview-plus/components/u-tabs/u-tabs.js";
const _easycom_hs_empty = () => "../hs-empty/hs-empty.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_hs_popup = () => "../hs-popup/hs-popup.js";
if (!Math) {
  (_easycom_hs_cell + _easycom_up_tabs + _easycom_hs_empty + _easycom_uni_icons + _easycom_hs_popup)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "hs-popup-project-houer",
  props: ["title", "defaultValueName"],
  emits: ["close", "change"],
  setup(__props, { emit }) {
    const props = __props;
    let keywordStore = "";
    const formData = common_vendor.ref({ page: 1 });
    const searchValue = common_vendor.ref("");
    const selectEd = common_vendor.ref({ name: "", id: 0 });
    const pickerList = common_vendor.ref([]);
    const pickerListProject = common_vendor.ref([]);
    const pickerListBuilding = common_vendor.ref([]);
    const pickerListUnit = common_vendor.ref([]);
    const pickerListHouse = common_vendor.ref([]);
    const showProjectName = common_vendor.ref("");
    const popupShow = common_vendor.ref(false);
    const currentValue = common_vendor.ref(0);
    const itemsList = common_vendor.ref([{ name: "小区" }]);
    const selectValueEd = common_vendor.ref([]);
    common_vendor.watch(
      () => props == null ? void 0 : props.defaultValueName,
      () => {
        showProjectName.value = props == null ? void 0 : props.defaultValueName;
      }
    );
    const handleSearch = common_libraries_tools.debounce((e) => {
      if (e === keywordStore) {
        return;
      }
      keywordStore = e;
      formData.value.page = 1;
      pickerListProject.value = [];
      handleTransfer(currentValue.value);
    }, 500);
    const onPopupShow = () => {
      popupShow.value = !popupShow.value;
      if (popupShow.value) {
        setTimeout(() => {
          currentValue.value = 0;
          pickerListProject.value = [];
          getPickerList();
        }, 300);
      }
    };
    const handleSwitchClick = (e) => {
      searchValue.value = "";
      currentValue.value = e == null ? void 0 : e.index;
      console.log(e, "eee");
    };
    common_vendor.watch(
      () => currentValue.value,
      (e) => {
        handleTransfer(e);
      }
    );
    const handleTransfer = (idx) => {
      if (idx === 0) {
        getPickerList();
      }
      if (idx === 1) {
        handleGetBuilding(selectValueEd.value[0]);
      }
      if (idx === 2) {
        handleGetUnit(selectValueEd.value[1]);
      }
      if (idx === 3) {
        handleGetHouse(selectValueEd.value[2]);
      }
    };
    const getPickerList = () => {
      common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Asset.AssetHouses.SelectProject, {
        name: searchValue.value,
        ...formData.value
      }).then((res) => {
        pickerListProject.value = res == null ? void 0 : res.data;
        pickerList.value = res == null ? void 0 : res.data;
        console.log(res);
      });
    };
    const onSelectMerchant = (i) => {
      searchValue.value = "";
      currentValue.value = 1;
      itemsList.value = [{ name: "小区" }, { name: "楼栋" }];
      selectValueEd.value[0] = i;
    };
    const handleGetBuilding = (data) => {
      common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Asset.AssetHouses.SelectBuilding, {
        asset_projects_id: data == null ? void 0 : data.id,
        name: searchValue.value,
        ...formData.value
      }).then((res) => {
        pickerListBuilding.value = res == null ? void 0 : res.data;
        pickerList.value = res == null ? void 0 : res.data;
        console.log(res);
      });
    };
    const onSelectBuildingt = (i) => {
      searchValue.value = "";
      currentValue.value = 2;
      itemsList.value = [{ name: "小区" }, { name: "楼栋" }, { name: "单元" }];
      selectValueEd.value[1] = i;
    };
    const handleGetUnit = (data) => {
      var _a;
      common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Asset.AssetHouses.SelectUnit, {
        asset_projects_id: (_a = selectValueEd.value[0]) == null ? void 0 : _a.id,
        asset_buildings_id: data == null ? void 0 : data.id,
        name: searchValue.value,
        ...formData.value
      }).then((res) => {
        pickerListUnit.value = res == null ? void 0 : res.data;
        pickerList.value = res == null ? void 0 : res.data;
        console.log(res);
      });
    };
    const onSelectUnit = (i) => {
      searchValue.value = "";
      currentValue.value = 3;
      itemsList.value = [{ name: "小区" }, { name: "楼栋" }, { name: "单元" }, { name: "房屋" }];
      selectValueEd.value[2] = i;
    };
    const handleGetHouse = (data) => {
      var _a, _b;
      common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Asset.AssetHouses.SelectHouse, {
        asset_projects_id: (_a = selectValueEd.value[0]) == null ? void 0 : _a.id,
        asset_buildings_id: (_b = selectValueEd.value[1]) == null ? void 0 : _b.id,
        asset_units_id: data == null ? void 0 : data.id,
        name: searchValue.value,
        ...formData.value
      }).then((res) => {
        pickerListHouse.value = res == null ? void 0 : res.data;
        pickerList.value = res == null ? void 0 : res.data;
        console.log(res);
      });
    };
    const onSelectHouse = (i) => {
      searchValue.value = "";
      selectValueEd.value[3] = i;
      showProjectName.value = selectValueEd == null ? void 0 : selectValueEd.value.map((res) => res == null ? void 0 : res.name).join("");
      emit("change", selectValueEd.value);
      onPopupShow();
    };
    return (_ctx, _cache) => {
      var _a, _b;
      return common_vendor.e({
        a: common_vendor.o(onPopupShow),
        b: common_vendor.p({
          title: props == null ? void 0 : props.title,
          isLink: true,
          isPlaceholder: true,
          required: true,
          borderTop: true,
          value: showProjectName.value
        }),
        c: common_vendor.o([
          ($event) => searchValue.value = $event.detail.value,
          //@ts-ignore
          (...args) => common_vendor.unref(handleSearch) && common_vendor.unref(handleSearch)(...args)
        ]),
        d: common_vendor.o(
          //@ts-ignore
          (...args) => common_vendor.unref(handleSearch) && common_vendor.unref(handleSearch)(...args)
        ),
        e: searchValue.value,
        f: popupShow.value
      }, popupShow.value ? {
        g: common_vendor.o(handleSwitchClick),
        h: common_vendor.p({
          list: itemsList.value,
          current: currentValue.value || 0
        })
      } : {}, {
        i: !((_a = pickerList.value) == null ? void 0 : _a.length)
      }, !((_b = pickerList.value) == null ? void 0 : _b.length) ? {} : {}, {
        j: currentValue.value === 0
      }, currentValue.value === 0 ? {
        k: common_vendor.f(pickerListProject.value, (i, index, i0) => {
          var _a2, _b2;
          return common_vendor.e({
            a: common_vendor.t(i == null ? void 0 : i.name),
            b: ((_a2 = selectEd.value) == null ? void 0 : _a2.id) === (i == null ? void 0 : i.id)
          }, ((_b2 = selectEd.value) == null ? void 0 : _b2.id) === (i == null ? void 0 : i.id) ? {
            c: "da3aad6e-4-" + i0 + ",da3aad6e-1",
            d: common_vendor.p({
              type: "checkmarkempty",
              size: "20",
              color: "#FBA60D"
            })
          } : {}, {
            e: `key_${index}`,
            f: common_vendor.o(($event) => onSelectMerchant(i), `key_${index}`)
          });
        })
      } : {}, {
        l: currentValue.value === 1
      }, currentValue.value === 1 ? {
        m: common_vendor.f(pickerListBuilding.value, (i, index, i0) => {
          var _a2, _b2;
          return common_vendor.e({
            a: common_vendor.t(i == null ? void 0 : i.name),
            b: ((_a2 = selectEd.value) == null ? void 0 : _a2.id) === (i == null ? void 0 : i.id)
          }, ((_b2 = selectEd.value) == null ? void 0 : _b2.id) === (i == null ? void 0 : i.id) ? {
            c: "da3aad6e-5-" + i0 + ",da3aad6e-1",
            d: common_vendor.p({
              type: "checkmarkempty",
              size: "20",
              color: "#FBA60D"
            })
          } : {}, {
            e: `key_${index}`,
            f: common_vendor.o(($event) => onSelectBuildingt(i), `key_${index}`)
          });
        })
      } : {}, {
        n: currentValue.value === 2
      }, currentValue.value === 2 ? {
        o: common_vendor.f(pickerListUnit.value, (i, index, i0) => {
          var _a2, _b2;
          return common_vendor.e({
            a: common_vendor.t(i == null ? void 0 : i.name),
            b: ((_a2 = selectEd.value) == null ? void 0 : _a2.id) === (i == null ? void 0 : i.id)
          }, ((_b2 = selectEd.value) == null ? void 0 : _b2.id) === (i == null ? void 0 : i.id) ? {
            c: "da3aad6e-6-" + i0 + ",da3aad6e-1",
            d: common_vendor.p({
              type: "checkmarkempty",
              size: "20",
              color: "#FBA60D"
            })
          } : {}, {
            e: `key_${index}`,
            f: common_vendor.o(($event) => onSelectUnit(i), `key_${index}`)
          });
        })
      } : {}, {
        p: currentValue.value === 3
      }, currentValue.value === 3 ? {
        q: common_vendor.f(pickerListHouse.value, (i, index, i0) => {
          var _a2, _b2;
          return common_vendor.e({
            a: common_vendor.t(i == null ? void 0 : i.name),
            b: ((_a2 = selectEd.value) == null ? void 0 : _a2.id) === (i == null ? void 0 : i.id)
          }, ((_b2 = selectEd.value) == null ? void 0 : _b2.id) === (i == null ? void 0 : i.id) ? {
            c: "da3aad6e-7-" + i0 + ",da3aad6e-1",
            d: common_vendor.p({
              type: "checkmarkempty",
              size: "20",
              color: "#FBA60D"
            })
          } : {}, {
            e: `key_${index}`,
            f: common_vendor.o(($event) => onSelectHouse(i), `key_${index}`)
          });
        })
      } : {}, {
        r: common_vendor.o(onPopupShow),
        s: common_vendor.p({
          show: popupShow.value,
          mode: "bottom",
          closeable: true,
          round: 20
        })
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-da3aad6e"], ["__file", "/Users/zsq/Sources/github/2025property-pay/pay-employee/src/components/hs-popup-project-houer/hs-popup-project-houer.vue"]]);
wx.createComponent(Component);
