bindphone.vue
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<template>
<view class="content">
<view class="loginbox loginboxmima">
<view class="loginboxitem flex">
<view class="boxitemleftkk">
手机号
</view>
<view class="boxitemright">
<input type="number" value="" placeholder="请输入手机号" placeholder-class="enter" @input="enterphone" />
</view>
</view>
<view class="loginboxitem flextwo">
<view class="flex">
<view class="boxitemleftkk">
短信验证码
</view>
<view class="boxitemright">
<!-- :value="code" -->
<input type="text" placeholder="请输入短信验证码" placeholder-class="enter" @input="entercode" />
</view>
</view>
<view class="cardyan" @click="getcode" v-if="disable==false">{{time}}</view>
<view class="cardyan" v-else>{{time}}</view>
</view>
</view>
<view class="next" @click="finish">完成</view>
</view>
</template>
<script>
import app from "../../App.vue";
import picyan from "../../components/picyan/picyan.vue";
var interval = null;
export default {
components:{
picyan
},
data() {
return {
showbanben: false,
rangenum: '',
phone: '',
code: '',
disable: false,
currentTime: 60,
time: '获取验证码',
yancode:''
}
},
onLoad() {
console.log(348344390)
// // 生成随机验证码
// var randomNum = ('000000' + Math.floor(Math.random() * 999999)).slice(-6);
// this.rangenum = randomNum;
},
methods: {
getpic(e) {
console.log('我是子组件的值', e);
this.rangenum = e
},
changenum() {
var randomNum = ('000000' + Math.floor(Math.random() * 999999)).slice(-6);
this.rangenum = randomNum;
},
// 输入手机号
enterphone(e) {
this.phone = e.detail.value
},
// 输入验证码
entercode(e) {
this.code = e.detail.value
},
enteryan(e){
this.yancode=e.detail.value
},
// 获取验证码
getcode() {
let that = this;
that.disable = true;
if (that.phone == '') {
uni.showToast({
title: "请输入手机号",
icon: "none"
})
that.disable = false;
return false
}
if (that.phone != '') {
if (!(/^1[3456789]\d{9}$/.test(that.phone))) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none'
})
that.disable = false;
return false;
}
}
let currentTime = that.currentTime;
let url = "user/get_code";
let param = {
mobile: that.phone,
};
console.log('8888', param)
app.post(url, param, 'get').then(r => {
console.log(r)
that.setcode = r.data.data.code;
that.code = r.data.data.code;
interval = setInterval(function() {
currentTime--;
that.time = currentTime + '秒';
if (currentTime <= 0) {
clearInterval(interval)
that.time = '重新发送';
that.currentTime = 61;
that.disable = false;
}
}, 1000)
}).catch(err => {
console.log(err);
})
},
// 下一步
finish() {
console.log(34348483)
let that=this;
console.log('66666',that.rangenum);
console.log(that.yancode)
if (that.phone == '') {
uni.showToast({
title: "请输入手机号",
icon: "none"
})
that.disable = false;
return false
}
if (that.phone != '') {
if (!(/^1[3456789]\d{9}$/.test(that.phone))) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none'
})
that.disable = false;
return false;
}
}
if (that.code == '') {
uni.showToast({
title: "请输入短信验证码",
icon: 'none'
})
return false
}
if(that.code!=that.setcode){
uni.showToast({
title: "短信验证码错误",
icon: 'none'
})
return false
}
let url = "user/update_mobile";
let params={
mobile:that.phone,
code:that.setcode,
}
console.log('参数',params)
app.post(url, params).then((res) => {
console.log(res);
uni.showToast({
title:"绑定成功",
icon:'none'
})
setTimeout(function(){
uni.$emit('phone',that.phone)
uni.navigateBack({
checked:true
})
},1500)
}).catch((err) => {
console.log(err)
uni.showToast({
title:err.msg,
icon:'none'
})
})
},
}
}
</script>
<style>
@import url('../../base/login');
page {
overflow-y: hidden;
}
.yanzhengk{
width:170rpx;
}
.boxitemleftkk {
color: #3D454C;
font-size: 28rpx;
width: 130rpx;
}
.next {
width: 686rpx;
height: 88rpx;
background: #C29445;
color: #fff;
font-size: 32rpx;
text-align: center;
line-height: 88rpx;
position: fixed;
bottom: 14rpx;
left: 32rpx;
}
</style>