"use strict";
const common_vendor = require("../../common/vendor.js");
require("../../common/libraries/request.js");
require("../../common/store/useWatermarkStore.js");
const common_store_useWeAppAuthStore = require("../../common/store/useWeAppAuthStore.js");
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_sendWxWork = require("../../common/libraries/sendWxWork.js");
const common_libraries_userUserLogin = require("../../common/libraries/userUserLogin.js");
const gen_Apis = require("../../gen/Apis.js");
const CUSTOMER_bind_house_model = require("./model.js");
const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
const method = {
  nextStep(type) {
    var _a, _b, _c;
    let data = (_b = (_a = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value;
    if ((_c = common_libraries_userUserLogin.getUser) == null ? void 0 : _c.toPageLogin())
      return;
    if (!(data == null ? void 0 : data.phone) || !(data == null ? void 0 : data.name)) {
      return common_libraries_naviHelper.showToast("请填写姓名/手机号");
    }
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseOccupants.GetCustomerHouse, { phone: data == null ? void 0 : data.phone }).then(
      (res) => {
        var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
        if (!((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.length)) {
          if (type === "phone") {
            common_vendor.index.redirectTo({
              url: `/CUSTOMER/house_select/index?phone=${(_d = (_c2 = (_b2 = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _b2.formData) == null ? void 0 : _c2.value) == null ? void 0 : _d.phone}&name=${(_g = (_f = (_e = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _e.formData) == null ? void 0 : _f.value) == null ? void 0 : _g.name}`
            });
          } else {
            common_vendor.index.navigateTo({
              url: `/CUSTOMER/house_select/index?phone=${(_j = (_i = (_h = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _h.formData) == null ? void 0 : _i.value) == null ? void 0 : _j.phone}&name=${(_m = (_l = (_k = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _k.formData) == null ? void 0 : _l.value) == null ? void 0 : _m.name}`
            });
          }
        } else {
          CUSTOMER_bind_house_model.useModel.bindHouseSelectPage.value = true;
          CUSTOMER_bind_house_model.useModel.bindHouseFormPage.value = false;
          CUSTOMER_bind_house_model.useModel.listData.value = res == null ? void 0 : res.data;
        }
        console.log(res);
      }
    );
  },
  selectHouse(e, index) {
    var _a, _b, _c;
    let isSelect = (_c = (_b = (_a = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _a.listData) == null ? void 0 : _b.value[index]) == null ? void 0 : _c.isSelect;
    CUSTOMER_bind_house_model.useModel.listData.value[index].isSelect = !isSelect;
  },
  handleBack() {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    if ((_b = (_a = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _a.bindPhone) == null ? void 0 : _b.value) {
      common_vendor.index.navigateTo({
        url: `/CUSTOMER/house_select/index?phone=${(_e = (_d = (_c = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _c.formData) == null ? void 0 : _d.value) == null ? void 0 : _e.phone}&name=${(_h = (_g = (_f = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _f.formData) == null ? void 0 : _g.value) == null ? void 0 : _h.name}`
      });
    } else {
      CUSTOMER_bind_house_model.useModel.bindHouseSelectPage.value = false;
      CUSTOMER_bind_house_model.useModel.bindHouseFormPage.value = true;
    }
  },
  handleBindHouse() {
    var _a, _b, _c, _d;
    let data = (_b = (_a = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value;
    let house_info = [];
    (_d = (_c = CUSTOMER_bind_house_model.useModel) == null ? void 0 : _c.listData) == null ? void 0 : _d.value.map((res) => {
      if (res == null ? void 0 : res.isSelect) {
        house_info.push({
          asset_houses_id: res == null ? void 0 : res.asset_houses_id,
          residential_relation: res == null ? void 0 : res.residential_relation
        });
      }
    });
    if (!(house_info == null ? void 0 : house_info.length)) {
      return common_libraries_naviHelper.showToast("请至少选择一套房屋！");
    }
    console.log(house_info);
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Archive.HouseRegisters.Store, {
      ...data,
      house_info
    }).then((res) => {
      common_libraries_naviHelper.showToastBack("绑定成功", 1, false, () => {
        common_vendor.index.reLaunch({
          url: `/CUSTOMER/house_list/index`
        });
      });
      console.log(res);
    });
  },
  handleInviteCustomer() {
    var _a;
    if (((_a = auth == null ? void 0 : auth.data) == null ? void 0 : _a.environment) === "wxwork") {
      common_libraries_sendWxWork.sendChatMessage({ page: "/INDEX/binding/index.html", title: "邀请你绑定房屋" });
    } else {
      common_libraries_sendWxWork.navigateToMiniProgram({
        path: "/pages/forward/index?source=HouseholdRegistration",
        envVersion: "develop",
        extraData: { source: "HouseholdRegistration" }
      });
    }
  }
};
exports.method = method;
