findPassword.vue 2.97 KB
<template>
  <div class="login_container">
    <img src="@/assets/icon/bg_login_2.png" />
    <div class="login_box">
      <NafmHeader navClass="nafmii-head-bg1" :title="title" />
    </div>
    <div class="login_content">
      <div class="login_form_box">
        <div class="login_form">
          <van-field v-show="type=='phone'" v-model.trim="userName" clearable type="tel" maxlength="11" :left-icon="telIcon" placeholder="请输入手机号" />
          <van-field v-show="type=='email'" v-model.trim="email" clearable :left-icon="emailIcon" placeholder="请输入邮箱" />
          <van-field v-model="password" clearable label="" maxlength="6" :left-icon="VerificationIcon" placeholder="请输入验证码">
            <template #button>
              <SendVerificationCode :phone="userName" :email="email" :data="objParams" />
            </template>
          </van-field>
          <div class="login_btn" :class="{loginActive:isBothValue}" @click="jumpResetPasswordPage">确定</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import SendVerificationCode from '@/components/SendVerificationCode'

import utils from "@/utils/";

export default {
  name: 'Login',
  components: {
    SendVerificationCode
  },
  data() {
    return {
      userName: null,
      password: "",
      title: '',
      type: null,
      objParams: {},
      email: '',
      phone: '',
      telIcon: require('@/assets/icon/tel.png'),
      emailIcon: require('@/assets/icon/email.png'),
      VerificationIcon: require('@/assets/icon/verification.png'),
      passwordIcon: require('@/assets/icon/password.png'),
    }
  },
  created() {
    const { type } = this.$route.query
    this.type = type
    Object.assign(this.objParams, {
      type
    })
    if (type == 'phone') {
      this.title = '手机号找回'
    } else {
      this.title = '邮箱找回'
    }
  },
  computed: {
    isBothValue() {
      if ((this.userName && this.password) || (this.email && this.password)) {
        return true
      } else {
        return false
      }
    },
  },
  methods: {
    jumpResetPasswordPage() {
      const { type } = this.$route.query
      if (type == 'phone') {
        // 判断手机号不能为空
        if (!this.userName) {
          Toast('请输入手机号')
          return
        }

        if (!utils.phoneRegCheck(this.userName)) {
          Toast("请输入正确的手机号码!");
          return
        }
      } else {
        // 判断邮箱不能为空
        if (!this.email) {
          Toast('请输入邮箱')
          return
        }

        if (!utils.emailRegCheck(this.email)) {
          Toast("请输入正确的邮箱格式!");
          return
        }
      }

      if (!this.password) {
        Toast('请输入验证码')
        return
      }

      this.$router.push({
        path: '/user/resetPassword',
        query: {
          source: 'login'
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
@import "./less/login.less";
</style>