"use strict";
const ME_emergency_add_model = require("./model.js");
require("../../../common/libraries/request.js");
require("../../../common/store/useWatermarkStore.js");
require("../../../common/store/useWeAppAuthStore.js");
const common_store_useWorkStore = require("../../../common/store/useWorkStore.js");
const common_libraries_apiLoading = require("../../../common/libraries/apiLoading.js");
const gen_Apis = require("../../../gen/Apis.js");
const common_libraries_naviHelper = require("../../../common/libraries/naviHelper.js");
const work = common_store_useWorkStore.useWorkStore();
const getList = () => {
  var _a, _b;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.WorkOrder.HouseWorkOrders.List, (_b = (_a = ME_emergency_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    ME_emergency_add_model.useModel.listData.value = [...ME_emergency_add_model.useModel.listData.value, ...res == null ? void 0 : res.data];
    ME_emergency_add_model.useModel.metaData.value = res == null ? void 0 : res.meta;
  });
};
const method = {
  getList,
  init() {
    var _a, _b, _c, _d, _e;
    console.log("init", work == null ? void 0 : work.selectWorkProject);
    if ((_a = work == null ? void 0 : work.selectWorkProject) == null ? void 0 : _a.id) {
      ME_emergency_add_model.useModel.formData.value = {
        ...(_c = (_b = ME_emergency_add_model.useModel) == null ? void 0 : _b.formData) == null ? void 0 : _c.value,
        project_name: (_d = work == null ? void 0 : work.selectWorkProject) == null ? void 0 : _d.name,
        asset_projects_id: (_e = work == null ? void 0 : work.selectWorkProject) == null ? void 0 : _e.id
      };
    }
  },
  handleSubmit() {
    var _a, _b, _c, _d;
    let data = (_b = (_a = ME_emergency_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value;
    if (!(data == null ? void 0 : data.asset_projects_id)) {
      return common_libraries_naviHelper.showToast("请选择项目！");
    }
    if (!(data == null ? void 0 : data.name)) {
      return common_libraries_naviHelper.showToast("请输入事件名称！");
    }
    if (!(data == null ? void 0 : data.two_emergency_categories_id)) {
      return common_libraries_naviHelper.showToast("请选择分类！");
    }
    if (((_c = data == null ? void 0 : data.two_emergency_categories_id) == null ? void 0 : _c.length) === 1) {
      return common_libraries_naviHelper.showToast("请选择2级分类！");
    }
    if (!(data == null ? void 0 : data.emergency_event_levels_id)) {
      return common_libraries_naviHelper.showToast("请选择等级！");
    }
    if (!(data == null ? void 0 : data.emergency_event_levels_id)) {
      return common_libraries_naviHelper.showToast("请选择等级！");
    }
    if (!(data == null ? void 0 : data.emergency_time)) {
      return common_libraries_naviHelper.showToast("请选择发生时间！");
    }
    if (!(data == null ? void 0 : data.emergency_location)) {
      return common_libraries_naviHelper.showToast("请输入事发地点！");
    }
    if (!(data == null ? void 0 : data.emergency_description)) {
      return common_libraries_naviHelper.showToast("请输入事件描述！");
    }
    if (!(data == null ? void 0 : data.emergency_cause)) {
      return common_libraries_naviHelper.showToast("请输入原因！");
    }
    if (!(data == null ? void 0 : data.cause_result)) {
      return common_libraries_naviHelper.showToast("请设置结果！");
    }
    data.two_emergency_categories_id = (_d = data == null ? void 0 : data.two_emergency_categories_id) == null ? void 0 : _d[1];
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Emergency.EmergencyEvents.Store, data).then((res) => {
      common_libraries_naviHelper.showToastBack("提交成功！", 1, true);
      console.log(res);
    });
  }
};
exports.method = method;
