"use strict";
const common_vendor = require("../../common/vendor.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 WORKORDER_add_model = require("./model.js");
const gen_Apis = require("../../gen/Apis.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const common_libraries_naviHelper = require("../../common/libraries/naviHelper.js");
const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
const work = common_store_useWorkStore.useWorkStore();
const method = {
  init() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
    WORKORDER_add_model.useModel.formData.value = {
      ...WORKORDER_add_model.useModel.formData.value,
      reporter_phone: WORKORDER_add_model.useModel.formData.value.reporter_phone || ((_b = (_a = auth == null ? void 0 : auth.data) == null ? void 0 : _a.user) == null ? void 0 : _b.phone) || "",
      reporter_name: WORKORDER_add_model.useModel.formData.value.reporter_name || ((_d = (_c = auth == null ? void 0 : auth.data) == null ? void 0 : _c.user) == null ? void 0 : _d.name) || "",
      contact_phone: WORKORDER_add_model.useModel.formData.value.contact_phone || ((_f = (_e = auth == null ? void 0 : auth.data) == null ? void 0 : _e.user) == null ? void 0 : _f.phone)
    };
    if ((_g = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _g.asset_house) {
      WORKORDER_add_model.useModel.formData.value = {
        ...WORKORDER_add_model.useModel.formData.value,
        asset_houses_id: (_i = (_h = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _h.asset_house) == null ? void 0 : _i.id,
        full_name: (_k = (_j = work == null ? void 0 : work.selectWorkHouse) == null ? void 0 : _j.asset_house) == null ? void 0 : _k.full_name
      };
    } else {
      WORKORDER_add_model.useModel.formData.value = {
        ...WORKORDER_add_model.useModel.formData.value,
        asset_houses_id: (_m = (_l = auth == null ? void 0 : auth.data) == null ? void 0 : _l.selected_house) == null ? void 0 : _m.id,
        full_name: (_o = (_n = auth == null ? void 0 : auth.data) == null ? void 0 : _n.selected_house) == null ? void 0 : _o.full_name
      };
    }
  },
  handleChangeType(e) {
    if ((e == null ? void 0 : e.value) === "Complaint") {
      WORKORDER_add_model.useModel.formData.value.location = "";
    }
    console.log("handleChangeType", e);
  },
  handleSubmit() {
    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;
    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_houses_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.type) === "Complaint" && !((_k = (_j = WORKORDER_add_model.useModel) == null ? void 0 : _j.formData.value) == null ? void 0 : _k.complaint_type)) {
      return common_libraries_naviHelper.showToast("请选择投诉类型！");
    }
    if (!WORKORDER_add_model.useModel.formData.value.content) {
      return common_libraries_naviHelper.showToast("请输入问题描述！");
    }
    if (((_n = (_m = (_l = WORKORDER_add_model.useModel) == null ? void 0 : _l.formData) == null ? void 0 : _m.value) == null ? void 0 : _n.location) === "MyHome" && ((_q = (_p = (_o = WORKORDER_add_model.useModel) == null ? void 0 : _o.formData) == null ? void 0 : _p.value) == null ? void 0 : _q.type) !== "Complaint" && !WORKORDER_add_model.useModel.formData.value.expect_start_time) {
      return common_libraries_naviHelper.showToast("请选择上门时间！");
    }
    if (((_t = (_s = (_r = WORKORDER_add_model.useModel) == null ? void 0 : _r.formData) == null ? void 0 : _s.value) == null ? void 0 : _t.type) !== "Complaint" && (!((_v = (_u = WORKORDER_add_model.useModel) == null ? void 0 : _u.formData.value) == null ? void 0 : _v.reporter_phone) || !((_x = (_w = WORKORDER_add_model.useModel) == null ? void 0 : _w.formData.value) == null ? void 0 : _x.reporter_name))) {
      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);
    });
  },
  handleToSelectHouse() {
    common_vendor.index.navigateTo({
      url: "/INDEX/asset_houses/index?type=work_add"
    });
  },
  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;
