"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 ME_instrument_list_model = require("./model.js");
const getList = () => {
  var _a, _b;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Meter.HouseMeters.List, (_b = (_a = ME_instrument_list_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    ME_instrument_list_model.useModel.listData.value = [...ME_instrument_list_model.useModel.listData.value, ...res == null ? void 0 : res.data];
    ME_instrument_list_model.useModel.metaData.value = res == null ? void 0 : res.meta;
  });
};
const getMenuList = () => {
  var _a, _b;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Asset.AssetHouses.SelectPermissionUnit, (_b = (_a = ME_instrument_list_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    var _a2, _b2, _c, _d, _e;
    ME_instrument_list_model.useModel.listMenuData.value = res == null ? void 0 : res.data;
    if ((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.length) {
      if (!((_c = (_b2 = ME_instrument_list_model.useModel) == null ? void 0 : _b2.currentTabs) == null ? void 0 : _c.value)) {
        ME_instrument_list_model.useModel.formData.value.asset_units_id = (_e = (_d = res == null ? void 0 : res.data) == null ? void 0 : _d[0]) == null ? void 0 : _e.id;
      }
      handleTabSearch();
    }
  });
};
const handleTabSearch = () => {
  ME_instrument_list_model.useModel.formData.value.page = 1;
  ME_instrument_list_model.useModel.listData.value = [];
  getList();
};
const method = {
  getList,
  getMenuList,
  handleSearch() {
    handleTabSearch();
  },
  handleChangeUsageTypeFilter(e) {
    ME_instrument_list_model.useModel.formData.value.usage_type = (e == null ? void 0 : e.value) || void 0;
    handleTabSearch();
    console.log("e", e);
  },
  handleChangeOverdueDaysFilter(e) {
    var _a, _b, _c;
    if (((_c = (_b = (_a = ME_instrument_list_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value) == null ? void 0 : _c.overdue_days) === (e == null ? void 0 : e.value)) {
      ME_instrument_list_model.useModel.formData.value.overdue_days = void 0;
      ME_instrument_list_model.useModel.activeColor.value = "";
    } else {
      ME_instrument_list_model.useModel.formData.value.overdue_days = e == null ? void 0 : e.value;
      ME_instrument_list_model.useModel.activeColor.value = e == null ? void 0 : e.color;
    }
    handleTabSearch();
  },
  handleChangeFilter(e) {
    ME_instrument_list_model.useModel.formData.value = {
      ...ME_instrument_list_model.useModel.formData.value,
      ...e,
      page: 1
    };
    ME_instrument_list_model.useModel.listData.value = [];
    getList();
  },
  handleChangeFilterReadingStatus(e) {
    ME_instrument_list_model.useModel.formData.value = {
      ...ME_instrument_list_model.useModel.formData.value,
      reading_status: (e == null ? void 0 : e.value) || void 0
    };
    ME_instrument_list_model.useModel.listData.value = [];
    getList();
  },
  handleChangeTabs(idx, e) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
    ME_instrument_list_model.useModel.currentTabs.value = idx;
    if (idx) {
      ME_instrument_list_model.useModel.formData.value = {
        meter_type: e == null ? void 0 : e.value,
        asset_projects_id: (_c = (_b = (_a = ME_instrument_list_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value) == null ? void 0 : _c.asset_projects_id
      };
    } else {
      ME_instrument_list_model.useModel.formData.value = {
        meter_type: e == null ? void 0 : e.value,
        asset_projects_id: (_f = (_e = (_d = ME_instrument_list_model.useModel) == null ? void 0 : _d.formData) == null ? void 0 : _e.value) == null ? void 0 : _f.asset_projects_id,
        asset_units_id: (_j = (_i = (_h = (_g = ME_instrument_list_model.useModel) == null ? void 0 : _g.listMenuData) == null ? void 0 : _h.value) == null ? void 0 : _i[0]) == null ? void 0 : _j.id
      };
    }
    handleTabSearch();
  },
  handleLoad(res) {
    ME_instrument_list_model.useModel.formData.value.page = res == null ? void 0 : res.page;
    getList();
  },
  handleToAdd(i) {
    common_vendor.index.navigateTo({
      url: `/ME/instrument/add/index?id=${i == null ? void 0 : i.id}`
    });
  },
  handleToLog() {
    common_vendor.index.navigateTo({
      url: `/ME/instrument/log/index?id=`
    });
  }
};
exports.method = method;
