"use strict";
const common_vendor = require("../../../../common/vendor.js");
const sheep_index = require("../../../index.js");
const sheep_validate_form = require("../../../validate/form.js");
const sheep_hooks_useModal = require("../../../hooks/useModal.js");
const sheep_api_member_auth = require("../../../api/member/auth.js");
require("../../../api/index.js");
require("../../../api/distri/score.js");
require("../../../request/index.js");
require("../../../config/index.js");
require("../../../store/index.js");
require("../../../store/app.js");
require("../../../api/promotion/diy.js");
require("../../../platform/index.js");
require("../../../platform/provider/wechat/index.js");
require("../../../platform/provider/wechat/miniProgram.js");
require("../../../api/member/social.js");
require("../../../api/member/user.js");
require("../../../platform/provider/apple/index.js");
require("../../../platform/share.js");
require("../../../router/index.js");
require("../../../helper/throttle.js");
require("../../../url/index.js");
require("../../../platform/pay.js");
require("../../../helper/index.js");
require("../../../helper/test.js");
require("../../../helper/digit.js");
require("../../../api/pay/order.js");
require("../../../store/user.js");
require("../../../store/cart.js");
require("../../../api/trade/cart.js");
require("../../../api/pay/wallet.js");
require("../../../api/trade/order.js");
require("../../../api/promotion/coupon.js");
require("../../../store/sys.js");
require("../../../store/modal.js");
require("../../../api/distri/share.js");
require("../../../api/distri/team.js");
require("../../../api/infra/file.js");
require("../../../api/member/address.js");
require("../../../api/member/point.js");
require("../../../api/member/signin.js");
require("../../../api/migration/app.js");
require("../../../api/migration/chat.js");
require("../../../api/migration/index.js");
require("../../../api/migration/third.js");
require("../../../api/pay/channel.js");
require("../../../api/product/category.js");
require("../../../api/product/comment.js");
require("../../../api/product/favorite.js");
require("../../../api/product/history.js");
require("../../../api/product/spu.js");
require("../../../api/promotion/activity.js");
require("../../../api/promotion/article.js");
require("../../../api/promotion/bargain.js");
require("../../../api/promotion/combination.js");
require("../../../api/promotion/rewardActivity.js");
require("../../../api/promotion/seckill.js");
require("../../../api/system/area.js");
require("../../../api/system/voice.js");
require("../../../api/trade/afterSale.js");
require("../../../api/trade/brokerage.js");
require("../../../api/trade/config.js");
require("../../../api/trade/delivery.js");
require("../../../config/zIndex.js");
if (!Array) {
  const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
  const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
  (_easycom_uni_easyinput2 + _easycom_uni_forms_item2 + _easycom_uni_forms2)();
}
const _easycom_uni_easyinput = () => "../../../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
const _easycom_uni_forms_item = () => "../../../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js";
const _easycom_uni_forms = () => "../../../../uni_modules/uni-forms/components/uni-forms/uni-forms.js";
if (!Math) {
  (_easycom_uni_easyinput + _easycom_uni_forms_item + phoneInternationalInput + _easycom_uni_forms)();
}
const phoneInternationalInput = () => "./phone-international-input.js";
const _sfc_main = {
  __name: "register",
  props: {
    agreeStatus: {
      type: Boolean,
      default: false
    }
  },
  emits: ["onConfirm"],
  setup(__props, { emit: __emit }) {
    const mobileInput = (mobile, mobileError) => {
      state.model.mobile = mobile;
      state.mobileErrorMsg = mobileError;
    };
    const state = common_vendor.reactive({
      verifyUsername: false,
      // 校验用户名是否可用
      codeText: "获取验证码",
      mobileErrorMsg: "",
      usernameErrorMsg: "",
      model: {
        username: "",
        // 用户名
        password: "",
        // 密码
        mobile: "",
        // 手机号
        code: ""
        // 验证码
      },
      rules: {
        username: sheep_validate_form.username,
        password: sheep_validate_form.password,
        code: sheep_validate_form.code
      }
    });
    const smsLoginRef = common_vendor.ref(null);
    const emits = __emit;
    const props = __props;
    let lastUsername = common_vendor.ref("");
    async function verifyUsername(e) {
      const username = e.detail.value;
      if (username == "" || username == lastUsername.value) {
        return false;
      }
      lastUsername.value = username;
      const { data } = await sheep_api_member_auth.AuthUtil.verifyUsername(username);
      if (data) {
        state.usernameErrorMsg = "";
        state.verifyUsername = data;
      } else {
        state.usernameErrorMsg = "已存在用户名!";
        state.verifyUsername = data;
      }
    }
    async function registerSubmit() {
      console.log(state.model);
      const validate = await common_vendor.unref(smsLoginRef).validate().catch((error) => {
        console.log("error: ", error);
      });
      if (!validate) {
        return;
      }
      if (!props.agreeStatus) {
        emits("onConfirm", true);
        sheep_index.sheep.$helper.toast("请勾选同意");
        return;
      }
      const linkId = common_vendor.index.getStorageSync("linkId");
      if (linkId) {
        state.model.linkId = linkId;
      } else {
        sheep_index.sheep.$helper.toast("您只能通过分享注册");
        return false;
      }
      const {
        code
      } = await sheep_api_member_auth.AuthUtil.register(state.model);
      if (code === 0) {
        sheep_hooks_useModal.closeAuthModal();
      }
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: !state.verifyUsername
      }, !state.verifyUsername ? {
        b: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/shibai.png")
      } : {
        c: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/chenggong.png")
      }, {
        d: common_vendor.o(verifyUsername),
        e: common_vendor.o(($event) => state.model.username = $event),
        f: common_vendor.p({
          placeholder: "请输入用户名",
          inputBorder: false,
          clearable: false,
          modelValue: state.model.username
        }),
        g: common_vendor.p({
          name: "username",
          label: "用户名",
          ["error-message"]: state.usernameErrorMsg
        }),
        h: common_vendor.o(($event) => state.model.password = $event),
        i: common_vendor.p({
          type: "password",
          placeholder: "请输入密码",
          inputBorder: false,
          modelValue: state.model.password
        }),
        j: common_vendor.p({
          name: "password",
          label: "密码"
        }),
        k: common_vendor.o(mobileInput),
        l: common_vendor.p({
          ["verify-username"]: state.verifyUsername
        }),
        m: common_vendor.p({
          name: "mobile",
          label: "手机号",
          ["error-message"]: state.mobileErrorMsg
        }),
        n: common_vendor.o(($event) => state.model.code = $event),
        o: common_vendor.p({
          placeholder: "请输入验证码",
          inputBorder: false,
          type: "number",
          maxlength: "4",
          modelValue: state.model.code
        }),
        p: common_vendor.p({
          name: "code",
          label: "验证码"
        }),
        q: common_vendor.sr(smsLoginRef, "5a48a10b-0", {
          "k": "smsLoginRef"
        }),
        r: common_vendor.o(($event) => state.model = $event),
        s: common_vendor.p({
          rules: state.rules,
          validateTrigger: "bind",
          labelWidth: "140",
          labelAlign: "center",
          modelValue: state.model
        }),
        t: common_vendor.o(registerSubmit)
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5a48a10b"], ["__file", "D:/zx/mall-front-app/sheep/components/s-auth-modal/components/register.vue"]]);
wx.createComponent(Component);
