"use strict";
const common_vendor = require("../../common/vendor.js");
const WORKORDER_list_model = require("./model.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const gen_Apis = require("../../gen/Apis.js");
const getList = () => {
  var _a, _b;
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.WorkOrder.HouseWorkOrders.List, (_b = (_a = WORKORDER_list_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
    var _a2, _b2;
    WORKORDER_list_model.useModel.dataList.value = [...(_b2 = (_a2 = WORKORDER_list_model.useModel) == null ? void 0 : _a2.dataList) == null ? void 0 : _b2.value, ...res == null ? void 0 : res.data];
    WORKORDER_list_model.useModel.meta.value = res == null ? void 0 : res.meta;
  });
};
const handleSearch = () => {
  WORKORDER_list_model.useModel.formData.value.page = 1;
  WORKORDER_list_model.useModel.dataList.value = [];
  getList();
};
const method = {
  getList,
  handleToDetail(e) {
    common_vendor.index.navigateTo({
      url: `/WORKORDER/show/index?id=${e == null ? void 0 : e.id}`
    });
  },
  handleAdd() {
    common_vendor.index.navigateTo({
      url: "/WORKORDER/add/index"
    });
  },
  handleChangeTabs(idx, e) {
    WORKORDER_list_model.useModel.currentTabs.value = idx;
    WORKORDER_list_model.useModel.formData.value.type = e == null ? void 0 : e.value;
    handleSearch();
  },
  handlepopupClose(e) {
    var _a, _b, _c;
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.WorkOrder.HouseWorkOrders.Evaluation, {
      id: (_c = (_b = (_a = WORKORDER_list_model.useModel) == null ? void 0 : _a.evaluateParams) == null ? void 0 : _b.value) == null ? void 0 : _c.id,
      evaluation_score: e == null ? void 0 : e.rating
    }).then(() => {
      WORKORDER_list_model.useModel.showEvaluate.value = false;
      common_vendor.index.showToast({
        title: "评价已提交",
        icon: "none"
      });
      handleSearch();
    });
    console.log(e, "eee");
  },
  handleAssignEmployee(e) {
    var _a, _b;
    if ((e == null ? void 0 : e.status) === "PendingAcceptance") {
      common_vendor.index.navigateTo({
        url: `/WORKORDER/acceptance/index?id=${e == null ? void 0 : e.id}`
      });
      return false;
    }
    if ((e == null ? void 0 : e.status) === "PendingPayment") {
      common_vendor.index.navigateTo({
        url: `/WORKORDER/pay/index?id=${e == null ? void 0 : e.id}`
      });
      return false;
    }
    if ((e == null ? void 0 : e.status) === "Completed") {
      WORKORDER_list_model.useModel.evaluateParams.value = e;
      WORKORDER_list_model.useModel.showEvaluate.value = true;
      return false;
    }
    if ((e == null ? void 0 : e.status) === "Processing") {
      if ((_a = e == null ? void 0 : e.assign_employee) == null ? void 0 : _a.phone) {
        common_vendor.index.makePhoneCall({
          phoneNumber: (_b = e == null ? void 0 : e.assign_employee) == null ? void 0 : _b.phone
          //仅为示例，并非真实的电话号码
        });
      } else {
        common_vendor.index.showToast({
          title: "暂无电话号码",
          icon: "none"
        });
      }
    }
    console.log(e, "eee");
  },
  handleChangeStatus(e) {
    WORKORDER_list_model.useModel.formData.value.status = e == null ? void 0 : e.value;
    handleSearch();
  },
  handleLoad(page) {
    WORKORDER_list_model.useModel.formData.value.page = page;
    getList();
  }
};
exports.method = method;
