"use strict";
const common_vendor = require("../../../common/vendor.js");
const gen_Apis = require("../../../gen/Apis.js");
const common_libraries_apiLoading = require("../../../common/libraries/apiLoading.js");
const common_libraries_userUserLogin = require("../../../common/libraries/userUserLogin.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 INDEX_visitor_applies_add_model = require("./model.js");
const work = common_store_useWorkStore.useWorkStore();
const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
const getList = () => {
  var _a, _b;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Activity.ActivityEnrolls.List, (_b = (_a = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    INDEX_visitor_applies_add_model.useModel.listData.value = [...INDEX_visitor_applies_add_model.useModel.listData.value, ...res.data];
    INDEX_visitor_applies_add_model.useModel.metaData.value = res.meta;
    console.log(res);
  });
};
const method = {
  getList,
  init(e) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
    console.log(e, "e");
    if ((e == null ? void 0 : e.page_type) === "share" || ((_c = (_b = (_a = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value) == null ? void 0 : _c.page_type) === "share") {
      INDEX_visitor_applies_add_model.useModel.formData.value = {
        ...INDEX_visitor_applies_add_model.useModel.formData.value,
        asset_houses_id: (e == null ? void 0 : e.id) || ((_f = (_e = (_d = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _d.formData) == null ? void 0 : _e.value) == null ? void 0 : _f.asset_houses_id),
        full_name: (e == null ? void 0 : e.full_name) || ((_i = (_h = (_g = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _g.formData) == null ? void 0 : _h.value) == null ? void 0 : _i.full_name),
        page_type: (e == null ? void 0 : e.page_type) || ((_l = (_k = (_j = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _j.formData) == null ? void 0 : _k.value) == null ? void 0 : _l.page_type),
        visitor_phone: INDEX_visitor_applies_add_model.useModel.formData.value.visitor_phone || ((_n = (_m = auth == null ? void 0 : auth.data) == null ? void 0 : _m.user) == null ? void 0 : _n.phone) || "",
        visitor_name: INDEX_visitor_applies_add_model.useModel.formData.value.visitor_name || ((_p = (_o = auth == null ? void 0 : auth.data) == null ? void 0 : _o.user) == null ? void 0 : _p.name) || "",
        companions_json: [
          {
            name: ""
          }
        ]
      };
      return false;
    }
    if (((_s = (_r = (_q = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _q.formData) == null ? void 0 : _r.value) == null ? void 0 : _s.page_type) === "share") {
      return;
    }
    if ((_t = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _t.asset_house) {
      INDEX_visitor_applies_add_model.useModel.formData.value = {
        ...INDEX_visitor_applies_add_model.useModel.formData.value,
        asset_houses_id: (_v = (_u = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _u.asset_house) == null ? void 0 : _v.id,
        full_name: (_x = (_w = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _w.asset_house) == null ? void 0 : _x.full_name,
        visitor_phone: INDEX_visitor_applies_add_model.useModel.formData.value.visitor_phone || "",
        visitor_name: INDEX_visitor_applies_add_model.useModel.formData.value.visitor_name || ""
      };
    } else {
      INDEX_visitor_applies_add_model.useModel.formData.value = {
        ...INDEX_visitor_applies_add_model.useModel.formData.value,
        asset_houses_id: (_z = (_y = auth == null ? void 0 : auth.data) == null ? void 0 : _y.selected_house) == null ? void 0 : _z.id,
        full_name: (_B = (_A = auth == null ? void 0 : auth.data) == null ? void 0 : _A.selected_house) == null ? void 0 : _B.full_name,
        visitor_phone: INDEX_visitor_applies_add_model.useModel.formData.value.visitor_phone || "",
        visitor_name: INDEX_visitor_applies_add_model.useModel.formData.value.visitor_name || ""
      };
    }
  },
  loadMore(page) {
    INDEX_visitor_applies_add_model.useModel.formData.value.page = page;
    this.getList();
  },
  handleTabsChange(idx, res) {
    INDEX_visitor_applies_add_model.useModel.currentTabs.value = idx;
    INDEX_visitor_applies_add_model.useModel.formData.value = {
      page: 1,
      status: res == null ? void 0 : res.value
    };
    INDEX_visitor_applies_add_model.useModel.listData.value = [];
    getList();
    console.log(idx, "e");
  },
  handleToSelectHouse() {
    common_vendor.index.navigateTo({
      url: "/INDEX/asset_houses/index?type=work_add"
    });
  },
  handleSubmit() {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    let data = (_b = (_a = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value;
    if (!((_c = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _c.onBindPhone())) {
      return false;
    }
    if (!(data == null ? void 0 : data.asset_houses_id)) {
      return common_libraries_naviHelper.showToast("请选择房屋!");
    }
    if (!(data == null ? void 0 : data.visitor_name)) {
      return common_libraries_naviHelper.showToast("请设置访客姓名!");
    }
    if (!(data == null ? void 0 : data.visitor_phone)) {
      return common_libraries_naviHelper.showToast("请设置访客手机号!");
    }
    if (!(data == null ? void 0 : data.visit_reason)) {
      return common_libraries_naviHelper.showToast("请添加来访事由!");
    }
    if (!(data == null ? void 0 : data.visit_start_time) || !(data == null ? void 0 : data.visit_end_time)) {
      return common_libraries_naviHelper.showToast("请选择到访时间-离开时间!");
    }
    common_libraries_apiLoading.getApiLoading(
      ((_f = (_e = (_d = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _d.formData) == null ? void 0 : _e.value) == null ? void 0 : _f.page_type) === "share" ? gen_Apis.Apis.Visitor.VisitorApplies.Register : gen_Apis.Apis.Visitor.VisitorApplies.Invite,
      (_h = (_g = INDEX_visitor_applies_add_model.useModel) == null ? void 0 : _g.formData) == null ? void 0 : _h.value
    ).then((res) => {
      common_libraries_naviHelper.showToastBack("提交成功！", 1, true);
      console.log(res);
    });
  },
  handleAddGoods() {
    INDEX_visitor_applies_add_model.useModel.formData.value.companions_json.push({
      name: ""
    });
  },
  handleDeleteGoods(index) {
    INDEX_visitor_applies_add_model.useModel.formData.value.companions_json.splice(index, 1);
  },
  handleToApplyRecords() {
    var _a;
    if (!((_a = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _a.onBindPhone())) {
      return false;
    }
    common_vendor.index.navigateTo({
      url: "/INDEX/visitor_applies/list/index"
    });
  }
};
exports.method = method;
