"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_api = require("../../utils/api.js");
const _sfc_main = {
  __name: "bind",
  setup(__props) {
    const name = common_vendor.ref("");
    const number = common_vendor.ref("");
    const identity = common_vendor.ref("");
    common_vendor.onLoad(() => {
    });
    const handleConfirm = () => {
      const flag = verifyValue();
      if (flag) {
        bindReq();
      }
    };
    const bindReq = async () => {
      const res = await utils_api.myRequest({
        url: "/wanzai/api/smartUser/bindStudent",
        method: "post",
        data: {
          userId: common_vendor.index.getStorageSync("userInfo").id,
          name: name.value,
          cardNo: number.value,
          idCard: identity.value
        }
      });
      common_vendor.index.showToast({
        title: res.message,
        icon: "none",
        duration: 2e3
      });
      if (res.code == 200) {
        setTimeout(() => {
          common_vendor.index.redirectTo({
            url: "/pages/home/home"
          });
        }, 2e3);
      }
    };
    const verifyValue = () => {
      const regName = /^[\u4e00-\u9fa5]{2,4}$/;
      const regIdentity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      if (!name.value) {
        common_vendor.index.showToast({
          title: "请输入姓名",
          icon: "none"
        });
        return false;
      }
      if (!regName.test(name.value)) {
        common_vendor.index.showToast({
          title: "姓名格式错误",
          icon: "none"
        });
        return false;
      }
      if (!number.value) {
        common_vendor.index.showToast({
          title: "请输入编号",
          icon: "none"
        });
        return false;
      }
      if (!identity.value) {
        common_vendor.index.showToast({
          title: "请输入身份证",
          icon: "none"
        });
        return false;
      }
      if (!regIdentity.test(identity.value)) {
        common_vendor.index.showToast({
          title: "证件号格式错误",
          icon: "none"
        });
        return false;
      }
      return true;
    };
    return (_ctx, _cache) => {
      return {
        a: name.value,
        b: common_vendor.o(($event) => name.value = $event.detail.value),
        c: number.value,
        d: common_vendor.o(($event) => number.value = $event.detail.value),
        e: identity.value,
        f: common_vendor.o(($event) => identity.value = $event.detail.value),
        g: common_vendor.o(handleConfirm)
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-8c1ad2ae"], ["__file", "E:/workSpace/WanZai_School_app/pages/bind/bind.vue"]]);
wx.createPage(MiniProgramPage);
