"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");
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 ME_release_items_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 = ME_release_items_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    ME_release_items_add_model.useModel.listData.value = [...ME_release_items_add_model.useModel.listData.value, ...res.data];
    ME_release_items_add_model.useModel.metaData.value = res.meta;
    console.log(res);
  });
};
const method = {
  getList,
  init() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
    if ((_a = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _a.asset_house) {
      ME_release_items_add_model.useModel.formData.value = {
        ...ME_release_items_add_model.useModel.formData.value,
        asset_houses_id: (_c = (_b = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _b.asset_house) == null ? void 0 : _c.id,
        full_name: (_e = (_d = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _d.asset_house) == null ? void 0 : _e.full_name,
        apply_phone: ME_release_items_add_model.useModel.formData.value.apply_phone || ((_g = (_f = auth == null ? void 0 : auth.data) == null ? void 0 : _f.user) == null ? void 0 : _g.phone) || "",
        apply_name: ME_release_items_add_model.useModel.formData.value.apply_name || ((_i = (_h = auth == null ? void 0 : auth.data) == null ? void 0 : _h.user) == null ? void 0 : _i.name) || ""
      };
    } else {
      ME_release_items_add_model.useModel.formData.value = {
        ...ME_release_items_add_model.useModel.formData.value,
        asset_houses_id: (_k = (_j = auth == null ? void 0 : auth.data) == null ? void 0 : _j.selected_house) == null ? void 0 : _k.id,
        full_name: (_m = (_l = auth == null ? void 0 : auth.data) == null ? void 0 : _l.selected_house) == null ? void 0 : _m.full_name,
        apply_phone: ME_release_items_add_model.useModel.formData.value.apply_phone || ((_o = (_n = auth == null ? void 0 : auth.data) == null ? void 0 : _n.user) == null ? void 0 : _o.phone) || "",
        apply_name: ME_release_items_add_model.useModel.formData.value.apply_name || ((_q = (_p = auth == null ? void 0 : auth.data) == null ? void 0 : _p.user) == null ? void 0 : _q.name) || ""
      };
    }
  },
  loadMore(page) {
    ME_release_items_add_model.useModel.formData.value.page = page;
    this.getList();
  },
  handleTabsChange(idx, res) {
    ME_release_items_add_model.useModel.currentTabs.value = idx;
    ME_release_items_add_model.useModel.formData.value = {
      page: 1,
      status: res == null ? void 0 : res.value
    };
    ME_release_items_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;
    let data = (_b = (_a = ME_release_items_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value;
    if (!(data == null ? void 0 : data.asset_houses_id)) {
      return common_libraries_naviHelper.showToast("请选择房屋!");
    }
    if (!(data == null ? void 0 : data.apply_name)) {
      return common_libraries_naviHelper.showToast("请设置申请人姓名!");
    }
    if (!(data == null ? void 0 : data.apply_phone)) {
      return common_libraries_naviHelper.showToast("请设置申请人手机号!");
    }
    for (let i = 0; i < ((_c = data == null ? void 0 : data.goods) == null ? void 0 : _c.length); i++) {
      if (!((_d = data == null ? void 0 : data.goods[i]) == null ? void 0 : _d.name)) {
        return common_libraries_naviHelper.showToast("请设置物品名称!");
      }
    }
    if (!(data == null ? void 0 : data.passed_time)) {
      return common_libraries_naviHelper.showToast("请选择放行日期!");
    }
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.GoodsReleases.GoodsReleases.Store, (_f = (_e = ME_release_items_add_model.useModel) == null ? void 0 : _e.formData) == null ? void 0 : _f.value).then((res) => {
      common_libraries_naviHelper.showToastBack("提交成功！", 1, true);
      console.log(res);
    });
  },
  handleAddGoods() {
    ME_release_items_add_model.useModel.formData.value.goods.push({
      name: "",
      number: 1,
      remark: ""
    });
  },
  handleDeleteGoods(index) {
    ME_release_items_add_model.useModel.formData.value.goods.splice(index, 1);
  }
};
exports.method = method;
