"use strict";
const common_vendor = require("../../common/vendor.js");
const modules_api_AppServer = require("../../modules/api/AppServer.js");
const common_assets = require("../../common/assets.js");
const appServer = new modules_api_AppServer.AppServer();
const _sfc_main = {
  data() {
    return {
      serviceId: "",
      serviceTitle: "",
      userName: "",
      userWechat: "",
      userPhone: "",
      userWhats: "",
      remark: "",
      specificRequirements: "",
      submitting: false,
      flashingField: "",
      selectedDialCode: "86"
    };
  },
  onLoad(options) {
    if (options.id) {
      this.serviceId = options.id;
    }
    if (options.title) {
      this.serviceTitle = decodeURIComponent(options.title);
    }
  },
  methods: {
    checkData() {
      const validations = [
        {
          field: "userName",
          selector: "#fieldUserName",
          check: () => !this.userName.trim(),
          message: "请输入真实姓名"
        },
        {
          field: "contact",
          selector: "#fieldContact",
          check: () => !this.userWechat.trim() && !this.userPhone.trim() && !this.userWhats.trim(),
          message: "请至少填写一种联系方式（微信号/手机号/WhatsApp）"
        },
        {
          field: "specificRequirements",
          selector: "#fieldSpecificRequirements",
          check: () => !this.specificRequirements.trim(),
          message: "请输入具体需求"
        }
      ];
      for (const validation of validations) {
        if (validation.check()) {
          common_vendor.index.showToast({
            title: validation.message,
            icon: "none"
          });
          this.scrollToElement(validation.selector);
          this.flashingField = validation.field;
          setTimeout(() => {
            this.flashingField = "";
          }, 1500);
          return;
        }
      }
      this.submitAppointment();
    },
    async submitAppointment() {
      var _a;
      if (this.submitting)
        return;
      this.submitting = true;
      common_vendor.index.showLoading({
        title: "提交中...",
        mask: true
      });
      try {
        const appointmentData = {
          hotServiceId: parseInt(this.serviceId) || null,
          serviceType: "visa_consultation",
          realName: this.userName.trim(),
          wechatId: this.userWechat.trim() || null,
          phone: this.userPhone.trim() || null,
          phoneCountryCode: this.userPhone.trim() ? this.selectedDialCode : null,
          whatsapp: this.userWhats.trim() || null,
          notes: this.remark.trim() || null,
          specificRequirements: this.specificRequirements.trim()
        };
        const result = await appServer.CreateAppointment(appointmentData);
        common_vendor.index.hideLoading();
        if (result.success || result.code === 0) {
          common_vendor.index.showToast({
            title: "预约提交成功",
            icon: "success"
          });
          setTimeout(() => {
            common_vendor.index.navigateBack({
              delta: 1
            });
          }, 1500);
        } else {
          common_vendor.index.showToast({
            title: ((_a = result.error) == null ? void 0 : _a.message) || "提交失败，请重试",
            icon: "none"
          });
        }
      } catch (error) {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("error", "at pages/appointment/visa-consultation-page.vue:217", "提交预约失败:", error);
        common_vendor.index.showToast({
          title: "网络错误，请重试",
          icon: "none"
        });
      } finally {
        this.submitting = false;
      }
    },
    scrollToElement(selector) {
      const systemInfo = common_vendor.index.getSystemInfoSync();
      const screenHeight = systemInfo.windowHeight;
      const query = common_vendor.index.createSelectorQuery().in(this);
      query.select(selector).boundingClientRect();
      query.selectViewport().scrollOffset();
      query.exec((res) => {
        if (res[0] && res[1]) {
          const rect = res[0];
          const scrollInfo = res[1];
          const targetScrollTop = scrollInfo.scrollTop + rect.top - screenHeight / 2 + rect.height / 2;
          common_vendor.index.pageScrollTo({
            scrollTop: Math.max(0, targetScrollTop),
            duration: 300
          });
        }
      });
    },
    back() {
      common_vendor.index.navigateBack({
        delta: 1
      });
    }
  }
};
if (!Array) {
  const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  const _easycom_aure_country_picker2 = common_vendor.resolveComponent("aure-country-picker");
  const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
  (_easycom_up_input2 + _easycom_aure_country_picker2 + _easycom_up_textarea2)();
}
const _easycom_up_input = () => "../../node-modules/uview-plus/components/u-input/u-input.js";
const _easycom_aure_country_picker = () => "../../uni_modules/aure-country-picker/components/aure-country-picker/aure-country-picker.js";
const _easycom_up_textarea = () => "../../node-modules/uview-plus/components/u-textarea/u-textarea.js";
if (!Math) {
  (_easycom_up_input + _easycom_aure_country_picker + _easycom_up_textarea)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_assets._imports_0,
    b: common_vendor.o((...args) => $options.back && $options.back(...args)),
    c: common_vendor.t(_ctx.$t("infoEntry.title")),
    d: common_vendor.t(_ctx.$t("infoEntry.personalInfo")),
    e: common_vendor.t(_ctx.$t("infoEntry.realName")),
    f: common_vendor.o(($event) => $data.userName = $event),
    g: common_vendor.p({
      placeholder: _ctx.$t("infoEntry.realNamePlaceholder"),
      border: "surround",
      modelValue: $data.userName
    }),
    h: $data.flashingField === "userName" ? 1 : "",
    i: common_vendor.t(_ctx.$t("infoEntry.wechat")),
    j: common_vendor.t(_ctx.$t("infoEntry.contactMethod")),
    k: common_vendor.o(($event) => $data.userWechat = $event),
    l: common_vendor.p({
      placeholder: _ctx.$t("infoEntry.wechatPlaceholder"),
      border: "surround",
      modelValue: $data.userWechat
    }),
    m: $data.flashingField === "contact" ? 1 : "",
    n: common_vendor.t(_ctx.$t("infoEntry.phone")),
    o: common_vendor.t(_ctx.$t("infoEntry.contactMethod")),
    p: common_vendor.o(($event) => $data.selectedDialCode = $event),
    q: common_vendor.p({
      title: _ctx.$t("infoEntry.selectCountry"),
      height: "70%",
      width: "60vw",
      duration: 350,
      position: "bottom",
      round: true,
      radius: "24rpx",
      ["mask-closable"]: true,
      modelValue: $data.selectedDialCode
    }),
    r: common_vendor.o(($event) => $data.userPhone = $event),
    s: common_vendor.p({
      placeholder: _ctx.$t("infoEntry.phonePlaceholder"),
      border: "surround",
      modelValue: $data.userPhone
    }),
    t: $data.flashingField === "contact" ? 1 : "",
    v: common_vendor.t(_ctx.$t("infoEntry.whatsapp")),
    w: common_vendor.t(_ctx.$t("infoEntry.contactMethod")),
    x: common_vendor.o(($event) => $data.userWhats = $event),
    y: common_vendor.p({
      placeholder: _ctx.$t("infoEntry.whatsappPlaceholder"),
      border: "surround",
      modelValue: $data.userWhats
    }),
    z: $data.flashingField === "contact" ? 1 : "",
    A: common_vendor.t(_ctx.$t("infoEntry.remark")),
    B: common_vendor.o(($event) => $data.remark = $event),
    C: common_vendor.p({
      placeholder: _ctx.$t("infoEntry.remarkPlaceholder"),
      border: "surround",
      modelValue: $data.remark
    }),
    D: common_vendor.t(_ctx.$t("infoEntry.serviceInfo")),
    E: common_vendor.o(($event) => $data.specificRequirements = $event),
    F: common_vendor.p({
      placeholder: "请详细描述您的签证咨询需求，如：签证类型、目的国家、出行时间等",
      maxlength: 1e3,
      count: true,
      height: "200",
      border: "surround",
      modelValue: $data.specificRequirements
    }),
    G: $data.flashingField === "specificRequirements" ? 1 : "",
    H: common_vendor.t(_ctx.$t("common.submit")),
    I: common_vendor.o(($event) => $options.checkData())
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/appointment/visa-consultation-page.js.map
