<template>
|
<view class="login-wrapper wrapperLayer colCen">
|
<titleBar titleText='' :pageForm='"login"' @backIndex="backHome"></titleBar>
|
<view class="pageContent borderBox colCen">
|
<view class="titleText">
|
绑定手机号
|
</view>
|
<view v-if="iscanbind" class="goaccount rowCenCen" @tap="mobShow()">
|
<view>本机手机号一键绑定</view>
|
</view>
|
<view v-else>
|
<view class="input-container colCen">
|
<view class="outSidebox rowCen" :class="selectedInput=='phone'?'outSidebox-active':''">
|
<input type="number" data-type='phone' @focus="changeType" @blur="cleanActive" v-model="phone"
|
placeholder="请输入手机号" placeholder-class="input-placeHolder" />
|
|
</view>
|
</view>
|
|
<view class="input-container colCen">
|
<view class="outSidebox rowCenBet" data-type='pass'
|
:class="selectedInput=='code'?'outSidebox-active':''">
|
<input @focus="changeType" @blur="cleanActive" data-type='code' type="number" v-model="code"
|
placeholder="请输入验证码" placeholder-class="input-placeHolder" />
|
<view class="getcodebox" :class="canGetCode?'colorTxt':''" @click="getCode()">
|
{{canGetCode?'获取验证码':second+'s后重新获取'}}
|
</view>
|
</view>
|
</view>
|
|
<view class="login-btn rowCenCen" :class="code&&phone?'colorfulbtn':''" @click="bindMobile()">
|
<view class="btn-font">
|
绑定
|
</view>
|
</view>
|
<view style="text-align: center; width: 100%;margin-top: 30rpx;" @click="mobShow()">
|
本机手机号一键绑定
|
</view>
|
</view>
|
</view>
|
|
<u-popup v-model="inviteCodeShow" mode="center" border-radius="32" :mask-close-able='true'>
|
<inviteCodeModel @closeModel='closeinvite' @confirm='nextStep'></inviteCodeModel>
|
</u-popup>
|
|
<u-popup v-model="inviterShow" mode="center" border-radius="32" v-if="inviterShow" :mask-close-able='true'>
|
<inviter-model ref='invitermodel' @rewrite='rewriteCode' @setInvite='setCodebtn'></inviter-model>
|
</u-popup>
|
</view>
|
</template>
|
|
<script>
|
import {
|
mapMutations
|
} from "vuex";
|
import inviteCodeModel from '../../components/inviteCode.vue'
|
import inviterModel from '../../components/inviterModel.vue'
|
import titleBar from '../../components/backTitlebar.vue'
|
import MD5 from '../../utils/md5.js'
|
import config from '../../utils/config.js'
|
import utils from '../../utils/utils.js'
|
const univerifyManager = uni.getUniverifyManager();
|
export default {
|
components: {
|
inviteCodeModel,
|
inviterModel,
|
titleBar
|
},
|
data() {
|
return {
|
user:"",
|
phone: '',
|
code: '',
|
cid: '',
|
selectedInput: '',
|
isread: false,
|
cleanfocus: true,
|
showPass: true,
|
second: 60,
|
canGetCode: true,
|
prevent: true,
|
inviteCodeShow:false,
|
inviterShow:false,
|
wxUser:"",
|
iscanbind:true,
|
isyj:false
|
};
|
},
|
onLoad(options) {
|
if(options.wx){ //微信授权页面过来的
|
this.wxUser = JSON.parse(options.wx);
|
}else{
|
if(!this.hasLogin){
|
uni.reLaunch({
|
url:"/pages/login/wxlogin"
|
})
|
}else{
|
this.getCid()
|
}
|
}
|
},
|
methods: {
|
...mapMutations(['login']),
|
doMobileLogin(mobRes)
|
{
|
var that=this;
|
uniCloud.callFunction({
|
name: 'getPhoneNumber', // 你的云函数名称
|
data: {
|
'access_token': mobRes.access_token, // 客户端一键登录接口返回的access_token
|
'openid': mobRes.openid, // 客户端一键登录接口返回的openid
|
'op_type':'getmob'
|
}
|
}).then(res => {
|
console.log(res);
|
that.phone=res.result.mobile;
|
univerifyManager.close();
|
that.isyj=true;
|
that.bindMobile();
|
}).catch(err=>{
|
// 处理错误
|
console.log(err)
|
that.iscanbind=false;
|
that.$alert('获取手机号码失败,请使用其他方式绑定')
|
setTimeout(function(){
|
univerifyManager.close();
|
},2000);
|
that.isyj=false;
|
})
|
},
|
mobShow()
|
{
|
var that=this;
|
univerifyManager.login({
|
provider: 'univerify',
|
univerifyStyle: { // 自定义登录框样式
|
"fullScreen":false,
|
"authButton":
|
{
|
"normalColor":"#F73314",
|
"highlightColor":"#F73314",
|
"title":"本机号码一键绑定"
|
},
|
"otherLoginButton":{
|
"title":"其他绑定方式"
|
},
|
"privacyTerms":{
|
"defaultCheckBoxState":false
|
}
|
|
},
|
success(res){ // 获取成功
|
console.log(res.authResult);
|
that.doMobileLogin(res.authResult);
|
},
|
fail(res){ // 登录失败
|
console.log(res)
|
if(res.errCode==30002)
|
{//切换登录方式
|
that.iscanbind=false;
|
univerifyManager.close();
|
}
|
else
|
{
|
that.$alert('获取手机号码失败,请使用其他方式绑定')
|
setTimeout(function(){
|
univerifyManager.close();
|
},2000);
|
}
|
|
that.iscanbind=false;
|
}
|
})
|
},
|
backHome() {
|
var pages = getCurrentPages();
|
console.log(pages.length);
|
if (pages.length == 1) {
|
uni.switchTab({
|
url: '../index/index'
|
})
|
} else {
|
uni.navigateBack({
|
delta: 1
|
})
|
}
|
},
|
targetToIndex(e)
|
{
|
var that = this;
|
|
that.login(e.data.userinfo);
|
utils.setCache('userInfo', e.data.userinfo)
|
getApp().globalData.userInfo = e.data.userinfo
|
that.$alert('登录成功')
|
setTimeout(function(){
|
console.log(e.data.userinfo)
|
if(!e.data.userinfo.invitation_code)
|
{
|
uni.redirectTo({
|
url: './setInviteCode'
|
})
|
}
|
/* else if (e.data.userinfo.isPwd == 'N') {
|
uni.redirectTo({
|
url: './setPass'
|
})
|
} */else {
|
uni.switchTab({
|
url: '../index/index'
|
})
|
}
|
},1000)
|
},
|
bindMobile(){
|
var that = this;
|
let clientInfo = uni.getStorageSync('clientInfo');
|
var pushCid="";
|
if(clientInfo&&clientInfo.clientid)
|
{
|
pushCid=clientInfo.clientid;
|
}
|
if(this.wxUser != ""){
|
this.$u.api.bindMobileLogin({
|
wxUser : encodeURIComponent(JSON.stringify(that.wxUser)),
|
mobile:this.phone,
|
captcha:this.code,
|
isyj:this.isyj,
|
pushCid:pushCid
|
}).then(e => {
|
console.log(e)
|
if (e.code != 0) return that.$alert(e.msg)
|
this.targetToIndex(e);
|
/* that.login(e.data.userinfo);
|
that.$alert('登录成功')
|
setTimeout(function() {
|
if (e.data.userinfo.isPwd ==
|
'N') {
|
uni.redirectTo({
|
url: './setPass'
|
})
|
} else {
|
uni.switchTab({
|
url: '../index/index'
|
})
|
}
|
}, 1000) */
|
}).catch(function (err) {
|
console.log(err)
|
})
|
}else{
|
this.$u.api.changeMobile({
|
mobile:this.phone,
|
captcha:this.code,
|
isyj:this.isyj
|
}).then(e => {
|
if(e.code != 0) return that.$alert(e.msg)
|
that.$alert('绑定成功');
|
that.getUserInfo();
|
}).catch(function (err) {
|
})
|
}
|
|
},
|
|
getUserInfo() {
|
var that = this;
|
this.$u.api.getUserInfo({}).then(e => {
|
console.log(e.data.userinfo)
|
that.user = e.data.userinfo;
|
uni.setStorageSync('userInfo',e.data.userinfo)
|
if(that.user.invitation_id == 0){
|
that.inviteCodeShow = true
|
}else{
|
setTimeout(function(){
|
uni.switchTab({
|
url:'../index/index'
|
})
|
})
|
}
|
}).catch(function (err) {
|
})
|
|
},
|
|
getCode() {
|
var that =this;
|
if (this.prevent && this.canGetCode) {
|
this.prevent = false
|
this.$u.api.sendSms({
|
mobile: that.phone,
|
event: 'changemobile'
|
}).then(e => {
|
if(e.code != 0){
|
that.canGetCode = true
|
that.prevent = true
|
return that.$alert(e.msg)
|
}
|
that.canGetCode = false
|
that.prevent = true
|
var timer = setInterval(() => {
|
that.second--
|
if (that.second < 1) {
|
that.second = 60
|
that.canGetCode = true
|
clearInterval(timer)
|
}
|
}, 1000)
|
|
}).catch(function (err) {
|
that.canGetCode = true
|
that.prevent = true
|
})
|
} else {
|
uni.showToast({
|
title: '您点的太快了~',
|
icon: 'none',
|
position: 'bottom',
|
duration: 3000
|
});
|
}
|
},
|
|
getCid() {
|
var pinf = plus.push.getClientInfo();
|
this.cid = pinf.clientid; //客户端标识
|
},
|
|
showPassfnc() {
|
this.showPass = !this.showPass
|
},
|
|
|
changeType(e) {
|
this.selectedInput = e.target.dataset.type
|
},
|
cleanActive() {
|
this.selectedInput = ''
|
},
|
|
changeWay() {
|
this.ifPasslogin = !this.ifPasslogin
|
},
|
|
goPage(type) {
|
uni.navigateTo({
|
url: './policyAgreement?type=' + type
|
})
|
},
|
|
closeinvite(){
|
this.inviteCodeShow = false
|
uni.switchTab({
|
url:'../index/index'
|
})
|
},
|
nextStep(e){
|
uni.setStorageSync('inviterInfo',e)
|
this.inviteCodeShow = false
|
this.inviterShow = true
|
},
|
rewriteCode(){
|
this.inviteCodeShow = true
|
this.inviterShow = false
|
},
|
setCodebtn(){
|
this.inviteCodeShow = false
|
this.inviterShow = false
|
uni.switchTab({
|
url:'../index/index'
|
})
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss">
|
.goaccount {
|
width: 100%;
|
height: 100rpx;
|
background: #FFFFFF;
|
border: 1rpx solid #999999;
|
border-radius: 50rpx;
|
font-size: 30rpx;
|
font-weight: 500;
|
color: #333333;
|
margin-top: 30rpx;
|
}
|
.login-wrapper {
|
width: 100%;
|
min-height: 100vh;
|
background-color: #FFFFFF;
|
|
.pageContent {
|
width: 100%;
|
padding: 0 60rpx;
|
|
.titleText {
|
width: 100%;
|
font-size: 42rpx;
|
font-weight: bold;
|
color: #333333;
|
margin: 60rpx 0;
|
}
|
|
.input-container {
|
width: 100%;
|
margin-bottom: 20rpx;
|
|
.outSidebox {
|
width: 100%;
|
height: 85rpx;
|
border-bottom: 2rpx solid #F1F1F1;
|
|
.input-placeHolder {
|
font-size: 34rpx;
|
font-weight: 500;
|
color: #CACACA;
|
}
|
|
input {
|
font-size: 34rpx;
|
font-weight: 500;
|
color: #222222;
|
}
|
|
.hidepass {
|
font-size: 32rpx;
|
font-weight: 800;
|
color: #CACACA;
|
}
|
|
.getcodebox {
|
font-size: 28rpx;
|
white-space: nowrap;
|
font-weight: 400;
|
color: #FF2851;
|
pointer-events: none;
|
}
|
|
.colorTxt {
|
pointer-events: auto;
|
}
|
}
|
|
.outSidebox-active {
|
border-bottom: 2rpx solid #FF2851;
|
}
|
}
|
|
.login-btn {
|
width: 100%;
|
height: 86rpx;
|
background: #E2E2E2;
|
border-radius: 43rpx;
|
margin-top: 80rpx;
|
pointer-events: none;
|
|
.btn-font {
|
font-size: 30rpx;
|
font-weight: 500;
|
color: #FFFFFF;
|
}
|
}
|
|
.txttips {
|
font-size: 24rpx;
|
font-weight: 500;
|
color: #666666;
|
margin-top: 20rpx;
|
}
|
|
.colorfulbtn {
|
background: #FD002F;
|
pointer-events: auto;
|
}
|
|
.bottom-fixed {
|
width: 100%;
|
position: fixed;
|
bottom: 100rpx;
|
bottom: calc(100rpx + constant(safe-area-inset-bottom));
|
bottom: env(100rpx + constant(safe-area-inset-bottom));
|
left: 0;
|
z-index: 1;
|
|
.verification-Code {
|
white-space: nowrap;
|
font-size: 28rpx;
|
font-weight: 500;
|
color: #333333;
|
}
|
|
.explain-text {
|
font-size: 22rpx;
|
font-weight: 500;
|
color: #999999;
|
margin-top: 30rpx;
|
white-space: nowrap;
|
}
|
}
|
}
|
}
|
</style>
|