"use strict";
const common_vendor = require("../../../common/vendor.js");
const request_api = require("../../../request/api.js");
const common_assets = require("../../../common/assets.js");
const app = getApp();
const _sfc_main = {
  data() {
    return {
      contentTop: "",
      mobile: "",
      //手机号
      code: "",
      //验证码
      isAgree: false,
      countdown: 0,
      //验证码倒计时
      getCode: false,
      //是否已经获取过验证码
      timer: null
      //定时器
    };
  },
  onLoad() {
    this.contentTop = common_vendor.inject("navHeight") + 230 / 750 * common_vendor.inject("windowWidth");
  },
  methods: {
    /**
     * 点击获取验证码
     */
    clickGetCode() {
      let mobile = this.mobile;
      if (!mobile) {
        common_vendor.index.showToast({
          title: "请输入手机号",
          icon: "none"
        });
        return;
      }
      if (!app.globalData.mobileReg.test(mobile)) {
        common_vendor.index.showToast({
          title: "请输入正确格式的手机号",
          icon: "none"
        });
        return;
      }
      if (this.isSubmiting) {
        return;
      }
      if (this.countdown > 0) {
        return;
      }
      this.isSubmiting = true;
      let param = { phone: this.mobile, isJson: 1 };
      let that = this;
      request_api.sendSMS(param).then((res) => {
        common_vendor.index.showToast({
          title: res.message,
          icon: "none"
        });
        let time = 60;
        this.timer = setInterval(() => {
          that.isSubmiting = false;
          time--;
          if (time == 0) {
            clearInterval(that.timer);
          }
          that.getCode = true;
          that.countdown = time;
        }, 1e3);
      }).catch((error) => {
        this.isSubmiting = false;
      });
    },
    /**
     * 点击立即登录
     */
    clickLoginAtOnce() {
      if (!this.mobile) {
        common_vendor.index.showToast({
          title: "请输入手机号",
          icon: "none"
        });
        return;
      }
      if (!this.code) {
        common_vendor.index.showToast({
          title: "请输入验证码",
          icon: "none"
        });
        return;
      }
      if (!this.isAgree) {
        common_vendor.index.showToast({
          title: "请阅读并同意我们的《用户服务协议》和《隐私政策》",
          icon: "none"
        });
        return;
      }
      let param = { phone: this.mobile, code: this.code, isJson: 1 };
      request_api.loginByPhone(param).then((res) => {
        if (res.code == 0) {
          common_vendor.index.showToast({
            title: res.message
          });
          common_vendor.index.setStorageSync("token", res.token);
          setTimeout(function() {
            common_vendor.index.switchTab({
              url: "/pages/index/index"
            });
          }, 1e3);
        } else
          common_vendor.index.showToast({
            title: res.message,
            icon: "none"
          });
      }).catch((error) => {
      });
    },
    /**
     * 点击一键登录
     */
    clickOneClickLogin() {
      common_vendor.index.navigateBack();
    },
    /**
     * 点击同意
     */
    clickAgree() {
      this.isAgree = !this.isAgree;
    },
    /**
     * 点击查看协议
     */
    clickProtocol(type) {
      common_vendor.index.navigateTo({
        url: "/pages/mine/web/web?type=" + type
      });
    }
  }
};
if (!Array) {
  const _easycom_navBar2 = common_vendor.resolveComponent("navBar");
  _easycom_navBar2();
}
const _easycom_navBar = () => "../../../components/navBar/navBar.js";
if (!Math) {
  _easycom_navBar();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_vendor.p({
      leftText: "登录",
      hideNavBg: true,
      backBlack: true
    }),
    b: common_vendor.s("margin-top:" + $data.contentTop + "px;"),
    c: common_assets._imports_0$1,
    d: common_assets._imports_1$7,
    e: $data.mobile,
    f: common_vendor.o(($event) => $data.mobile = $event.detail.value),
    g: common_assets._imports_2$6,
    h: $data.code,
    i: common_vendor.o(($event) => $data.code = $event.detail.value),
    j: common_vendor.t($data.getCode ? $data.countdown > 0 ? $data.countdown + "s" : "重新获取验证码" : "获取验证码"),
    k: common_vendor.o(($event) => $options.clickGetCode()),
    l: common_vendor.o(($event) => $options.clickLoginAtOnce()),
    m: common_vendor.o(($event) => $options.clickOneClickLogin()),
    n: $data.isAgree
  }, $data.isAgree ? {
    o: common_assets._imports_3$5
  } : {
    p: common_assets._imports_4$6
  }, {
    q: common_vendor.o(($event) => $options.clickAgree())
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/login/codeLogin/codeLogin.js.map
