"use strict";
require("../../common/libraries/request.js");
require("../../common/store/useWatermarkStore.js");
const common_store_useWeAppAuthStore = require("../../common/store/useWeAppAuthStore.js");
const common_store_useWorkStore = require("../../common/store/useWorkStore.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const common_libraries_naviHelper = require("../../common/libraries/naviHelper.js");
const gen_Apis = require("../../gen/Apis.js");
const WORKORDER_add_model = require("./model.js");
common_store_useWeAppAuthStore.useWeAppAuthStore();
const work = common_store_useWorkStore.useWorkStore();
const method = {
  unInit() {
    WORKORDER_add_model.useModel.formData.value = { is_anonymous: false, is_self: "0" };
    work.selectWorkHouse = {};
  },
  init() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
    console.log("init", work == null ? void 0 : work.selectWorkProject);
    WORKORDER_add_model.useModel.formData.value = {
      ...(_b = (_a = WORKORDER_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value
    };
    if ((_c = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _c.id) {
      WORKORDER_add_model.useModel.formData.value = {
        ...(_e = (_d = WORKORDER_add_model.useModel) == null ? void 0 : _d.formData) == null ? void 0 : _e.value,
        asset_houses_id: (_f = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _f.id,
        full_name: (_g = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _g.full_name
      };
    }
    if ((_h = work == null ? void 0 : work.selectWorkProject) == null ? void 0 : _h.id) {
      WORKORDER_add_model.useModel.formData.value = {
        ...(_j = (_i = WORKORDER_add_model.useModel) == null ? void 0 : _i.formData) == null ? void 0 : _j.value,
        project_name: (_k = work == null ? void 0 : work.selectWorkProject) == null ? void 0 : _k.name,
        asset_projects_id: (_l = work == null ? void 0 : work.selectWorkProject) == null ? void 0 : _l.id
      };
    }
  },
  handleSelectProject(data) {
    var _a, _b;
    let obj = data[3];
    WORKORDER_add_model.useModel.formData.value = {
      ...(_b = (_a = WORKORDER_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value,
      asset_houses_id: obj == null ? void 0 : obj.id,
      full_name: obj == null ? void 0 : obj.full_name
    };
    console.log(data, "data");
  },
  handleSubmit() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
    console.log("handleSubmit", WORKORDER_add_model.useModel.formData.value);
    if (!((_c = (_b = (_a = WORKORDER_add_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value) == null ? void 0 : _c.type)) {
      return common_libraries_naviHelper.showToast("请选择工单类型！");
    }
    if (((_f = (_e = (_d = WORKORDER_add_model.useModel) == null ? void 0 : _d.formData) == null ? void 0 : _e.value) == null ? void 0 : _f.location) !== "MyHome" && !WORKORDER_add_model.useModel.formData.value.asset_projects_id) {
      return common_libraries_naviHelper.showToast("请选择项目！");
    }
    if (((_i = (_h = (_g = WORKORDER_add_model.useModel) == null ? void 0 : _g.formData) == null ? void 0 : _h.value) == null ? void 0 : _i.location) === "MyHome" && !WORKORDER_add_model.useModel.formData.value.asset_houses_id) {
      return common_libraries_naviHelper.showToast("请选择房屋！");
    }
    if (((_l = (_k = (_j = WORKORDER_add_model.useModel) == null ? void 0 : _j.formData) == null ? void 0 : _k.value) == null ? void 0 : _l.location) === "MyHome" && !((_n = (_m = WORKORDER_add_model.useModel) == null ? void 0 : _m.formData.value) == null ? void 0 : _n.reporter_phone)) {
      return common_libraries_naviHelper.showToast("请输入联系人电话！");
    }
    if (!((_q = (_p = (_o = WORKORDER_add_model.useModel) == null ? void 0 : _o.formData) == null ? void 0 : _p.value) == null ? void 0 : _q.content)) {
      return common_libraries_naviHelper.showToast("请输入问题描述！");
    }
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.WorkOrder.HouseWorkOrders.Store, WORKORDER_add_model.useModel.formData.value).then((res) => {
      common_libraries_naviHelper.showToastBack("提交成功！", 1, true);
      console.log(res);
    });
  },
  handleSwitchChange(e) {
    var _a;
    WORKORDER_add_model.useModel.formData.value.is_anonymous = (_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.value;
    console.log(e, "e");
  }
};
exports.method = method;
