<template>
|
<view>
|
<view class="login-title">
|
<view class="login-title-1">手机号注册</view>
|
</view>
|
<view class="login-list">
|
<view class="login-item">
|
<input type="tel" v-model="formData.phone" placeholder="请输入手机号" />
|
</view>
|
<view class="login-item">
|
<input type="password" v-model="formData.pass" placeholder="请输入登录密码" />
|
</view>
|
<view class="login-item">
|
<input type="password" v-model="formData.tpass" placeholder="请确认登录密码" />
|
</view>
|
<view class="login-item">
|
<input type="number" v-model="formData.code" maxlength="4" placeholder="请输入验证码" />
|
<text class="code2" v-if="leftTime < 60">{{leftTime}}S后获取</text>
|
<text class="code" @click="sendCode" v-else>获取验证码</text>
|
</view>
|
</view>
|
<view class="loginBtn">
|
<view class="loginBtn-desc">
|
<image @click="agreeClick" class="loginBtn-icon" :src="!loginAct ? '/static/imgs/check.png' : '/static/imgs/checked.png'" ></image>
|
<text>我已阅读并同意</text>
|
<text class="blue" @tap="agreeDialog1">《注册协议》</text>
|
<text class="blue" @tap="agreeDialog2">《隐私政策》</text>
|
</view>
|
<view :class="loginAct ? 'login-btn active' : 'login-btn'" @click="registUser">立即注册</view>
|
<view class="loginDesc">
|
<view class="fc" @tap="$util.goPages('/pages/login/login')">已有账号,立即登录</view>
|
</view>
|
</view>
|
<agreePup ref="agreePup1" :gp="1" title="注册协议"></agreePup>
|
<agreePup ref="agreePup2" :gp="2" title="隐私政策"></agreePup>
|
</view>
|
</template>
|
|
<script>
|
import agreePup from "@/components/agreePup/agreePup";
|
export default {
|
data() {
|
return {
|
loginType: 1,
|
loginAct: false,
|
formData: {
|
phone: '',
|
pass: '',
|
tpass: '',
|
code: '',
|
},
|
phoneReg: /^\d{11}$/,
|
leftTime: 60,
|
}
|
},
|
onLoad(op) {
|
this.backUrl = op.backUrl ? op.backUrl : ''
|
},
|
methods: {
|
agreeDialog1 (e) {
|
this.$refs.agreePup1.dialog = !this.$refs.agreePup1.dialog
|
},
|
agreeDialog2 (e) {
|
this.$refs.agreePup2.dialog = !this.$refs.agreePup2.dialog
|
},
|
loginTypeClick (e) {
|
this.loginType = e
|
},
|
agreeClick () {
|
this.loginAct = !this.loginAct
|
},
|
registUser () {
|
let t = this
|
if(!t.loginAct) {
|
return uni.showToast({
|
title: '请阅读并同意协议政策',
|
icon: 'error'
|
})
|
}
|
if(t.formData.phone == '' || !t.phoneReg.test(t.formData.phone)){
|
return uni.showToast({
|
title: '手机号错误!',
|
icon: 'error',
|
})
|
}
|
if(t.formData.pass == ''){
|
return uni.showToast({
|
title: '请输入密码!',
|
icon: 'error',
|
})
|
}
|
if(t.formData.tpass == ''){
|
return uni.showToast({
|
title: '请输入确认密码!',
|
icon: 'error',
|
})
|
}
|
if(t.formData.tpass != t.formData.pass){
|
return uni.showToast({
|
title: '密码不一致!',
|
icon: 'error',
|
})
|
}
|
if(t.formData.code == ''){
|
return uni.showToast({
|
title: '请输入验证码!',
|
icon: 'error',
|
})
|
}
|
t.$util.post('User/register', this.formData).then(res => {
|
if(res.code == 1) {
|
uni.setStorageSync('user-token', res.data.userToken)
|
uni.setStorageSync('user-info', JSON.stringify(res.data))
|
|
uni.showToast({
|
title: res.msg || '注册成功'
|
})
|
setTimeout(() => {
|
t.$util.goSwitch('/pages/index/index')
|
}, 1500)
|
} else {
|
uni.showToast({
|
title: res.msg || '注册失败',
|
icon: 'error'
|
})
|
}
|
})
|
},
|
sendCode () {
|
let t = this
|
if(this.formData.phone == '' || !this.phoneReg.test(t.formData.phone)){
|
return uni.showToast({
|
title: '手机号错误!',
|
icon: 'error',
|
})
|
}
|
if (this.leftTime < 60) {
|
return false
|
}
|
this.$util.post('Sms/sendVerificationCode', {phone: this.formData.phone}).then(res => {
|
if(res.code == 1){
|
console.log(res)
|
t.countDown()
|
uni.showToast({
|
title:'发送成功',
|
icon:'none'
|
})
|
} else {
|
uni.showToast({
|
title: res.msg,
|
icon: 'none',
|
})
|
}
|
})
|
},
|
countDown() {
|
this.leftTime--
|
if (this.leftTime > 0) {
|
setTimeout(this.countDown, 1000)
|
} else {
|
this.leftTime = 60
|
}
|
},
|
}
|
}
|
</script>
|
|
<style>
|
@import url(/static/css/login.css);
|
</style>
|