"use strict";
const common_vendor = require("../../../common/vendor.js");
const ME_emergency_update_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_update_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    ME_emergency_update_model.useModel.listData.value = [...ME_emergency_update_model.useModel.listData.value, ...res == null ? void 0 : res.data];
    ME_emergency_update_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_update_model.useModel.formData.value = {
        ...(_c = (_b = ME_emergency_update_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, _e, _f, _g, _h, _i, _j;
    let data = (_b = (_a = ME_emergency_update_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value;
    if (((_e = (_d = (_c = ME_emergency_update_model.useModel) == null ? void 0 : _c.formData) == null ? void 0 : _d.value) == null ? void 0 : _e.type) === "申请关闭") {
      if (!(data == null ? void 0 : data.handled_result)) {
        return common_libraries_naviHelper.showToast("请输入处理结果！");
      }
      common_vendor.index.showModal({
        title: "提示",
        content: "确定要申请关闭？",
        success: function(res) {
          var _a2, _b2;
          if (res.confirm) {
            common_libraries_apiLoading.getApiLoading(
              gen_Apis.Apis.Emergency.EmergencyEvents.ApplyClose,
              (_b2 = (_a2 = ME_emergency_update_model.useModel) == null ? void 0 : _a2.formData) == null ? void 0 : _b2.value
            ).then((res2) => {
              common_libraries_naviHelper.showToastBack("提交成功！", 1, true);
              console.log(res2);
            });
            console.log("用户点击确定");
          } else if (res.cancel) {
            console.log("用户点击取消");
          }
        }
      });
    }
    if (((_h = (_g = (_f = ME_emergency_update_model.useModel) == null ? void 0 : _f.formData) == null ? void 0 : _g.value) == null ? void 0 : _h.type) === "更新进度") {
      if (!(data == null ? void 0 : data.content)) {
        return common_libraries_naviHelper.showToast("请输入跟进内容！");
      }
      common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Emergency.EmergencyEventFollows.Store, (_j = (_i = ME_emergency_update_model.useModel) == null ? void 0 : _i.formData) == null ? void 0 : _j.value).then(
        (res) => {
          common_libraries_naviHelper.showToastBack("提交成功！", 1, true);
          console.log(res);
        }
      );
    }
  }
};
exports.method = method;
