"use strict";
const common_vendor = require("../../common/vendor.js");
const util_api = require("../../util/api.js");
if (!Array) {
  const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  _easycom_uni_easyinput2();
}
const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
if (!Math) {
  _easycom_uni_easyinput();
}
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const name = common_vendor.ref(common_vendor.index.getStorageSync("form_name") || "");
    const phone = common_vendor.ref(common_vendor.index.getStorageSync("form_phone") || "");
    const company = common_vendor.ref(common_vendor.index.getStorageSync("form_company") || "");
    const content = common_vendor.ref("");
    const wxPhone = common_vendor.ref(9876);
    const handleSubmit = () => {
      const reName = /^[\u4e00-\u9fa5]{2,4}$/;
      const rePhone = /^[1][3,4,5,7,8,9][0-9]{9}$/;
      if (name.value == "") {
        common_vendor.index.showToast({
          title: "请输入姓名",
          icon: "none"
        });
        return;
      }
      if (!reName.test(name.value)) {
        common_vendor.index.showToast({
          title: "姓名格式有误",
          icon: "none"
        });
        return;
      }
      if (phone.value == "") {
        common_vendor.index.showToast({
          title: "请输入手机号",
          icon: "none"
        });
        return;
      }
      if (!rePhone.test(phone.value)) {
        common_vendor.index.showToast({
          title: "手机格式有误",
          icon: "none"
        });
        return;
      }
      if (company.value == "") {
        common_vendor.index.showToast({
          title: "请输入单位名称",
          icon: "none"
        });
        return;
      }
      if (!content.value) {
        common_vendor.index.showToast({
          title: "请输入需要登记的事件",
          icon: "none"
        });
        return;
      }
      common_vendor.index.showModal({
        title: "提示",
        content: "确认提交吗",
        success: async (res) => {
          if (res.confirm) {
            const res2 = await util_api.myRequest({
              url: "/informationReporting/add",
              method: "post",
              data: {
                name: name.value,
                phone: phone.value,
                company: company.value,
                content: content.value,
                wxPhone: wxPhone.value
              }
            });
            if (res2.success && res2.code == 1) {
              common_vendor.index.showToast({
                title: "提交成功",
                duration: 3e3
              });
              common_vendor.index.setStorageSync("form_name", name.value);
              common_vendor.index.setStorageSync("form_phone", phone.value);
              common_vendor.index.setStorageSync("form_company", company.value);
              content.value = "";
            } else {
              common_vendor.index.showToast({
                title: res2.message,
                icon: "error"
              });
            }
          } else if (res.cancel)
            ;
        }
      });
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o(($event) => name.value = $event),
        b: common_vendor.p({
          placeholder: "请输入姓名",
          modelValue: name.value
        }),
        c: common_vendor.o(($event) => phone.value = $event),
        d: common_vendor.p({
          type: "number",
          placeholder: "请输入手机号",
          modelValue: phone.value
        }),
        e: common_vendor.o(($event) => company.value = $event),
        f: common_vendor.p({
          placeholder: "请输入单位名称",
          modelValue: company.value
        }),
        g: common_vendor.o(($event) => content.value = $event),
        h: common_vendor.p({
          type: "textarea",
          maxlength: -1,
          placeholder: "请输入需要登记的事件",
          modelValue: content.value
        }),
        i: common_vendor.o(handleSubmit)
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"], ["__file", "G:/workSpace/agent-registration/pages/index/index.vue"]]);
wx.createPage(MiniProgramPage);
