陶杰
2024-08-22 4aa0bd47801606b4d0e0a6a2ed8fe92a7e5f2444
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<template>
    <view class="main-container login-container bg-white img100 relative" style="margin-top: 0rpx;">
        <view class="t-login top-bg m-t-20">
            <view class="login" style="padding: 40rpx;">
                <form class="cl m-t-12">
                    <!--     <view class="t-a titles-top">
                        <view class="title-2 text-center">绑定微信
                        </view>
                    </view> -->
                    <view class="t-a input form-input">
 
 
                        <u-input placeholder="请输入手机号" :border="false" v-model="phoneNumber">
                            <template slot="suffix">
                                <view class="get-code" :style="{'color':getCodeBtnColor}" @click.stop="getCode()">
                                    {{ getCodeText }}
                                </view>
                            </template>
                        </u-input>
                    </view>
 
 
                    <view class="t-a form-input">
                        <u-input placeholder="请输入手机验证码" :border="false" v-model="smsCode"></u-input>
 
                    </view>
 
                    <view class="t-a form-input">
                        <u-input placeholder="请输入真实姓名" :border="false" v-model="realName"></u-input>
 
                    </view>
                    <view class="t-red">*提醒:未实名或者真实姓名与微信支付实名不一样,可能会导致转账失败</view>
                    <!-- <view class="t-red m-t-20"
                        v-if="currentInfo.partnerDTO&&currentInfo.partnerDTO.realName||currentInfo.supplierDTO&&currentInfo.supplierDTO.realName">
                        *已实名:{{currentInfo.partnerDTO && currentInfo.partnerDTO.realName  ||currentInfo.supplierDTO && currentInfo.supplierDTO.realName || '-'}}
                    </view> -->
                    <view class="t-red m-t-20"
                        v-if="!!currentInfo.bindWechat">
                        *已实名认证
                    </view>
                    <!-- <button @click="getUserProfile" open-type="getUserInfo" class="bottom-button">绑定当前微信</button> -->
                    <button @click="wxlogin" open-type="getUserInfo" class="bottom-button">绑定当前微信</button>
 
 
                </form>
            </view>
 
        </view>
    </view>
</template>
<script>
    export default {
 
        data() {
            return {
 
                phoneNumber: '',
                smsCode: '',
                realName: '',
 
                checked: false,
                loginType: 'code', //pwd和code,密码和验证码登录
                pcfvalue: undefined,
                getCodeText: '获取验证码',
                getCodeBtnColor: "#20613D",
                getCodeisWaiting: false,
                Timer: undefined,
                // #ifdef PUB_SUPPLIER
                apitype: 'supplier',
                // #endif
                // #ifdef PUB_PARTNER
                apitype: 'partner',
                // #endif
                // #ifdef PUB_CUSTOMER
                apitype: 'customer',
                // #endif
                // return 'loginPartner'
            };
        },
        methods: {
            async getCode() {
                console.log('getCode')
                uni.hideKeyboard() //隐藏已经显示的软键盘,如果软键盘没有显示则不做任何操作。
                if (this.getCodeisWaiting) {
                    return;
                }
                if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneNumber))) { //校验手机号码是否有误
                    this.$message.showToast('请填写正确手机号码')
                    return false;
                }
                this.getCodeText = "发送中..." //发送验证码
                this.getCodeisWaiting = true;
                this.getCodeBtnColor = "#000" //追加样式,修改颜色
                //示例用定时器模拟请求效果
                //setTimeout(()用于在指定的毫秒数后调用函数或计算表达式
                const {
                    code
                } = await this.$http.request('post', '/api/sms/send/code', {
                    data: {
                        tel: this.phoneNumber,
                        userType: this.apitype.toLowerCase()
                    }
                })
                if (code == 0) {
                    uni.showToast({
                        title: '验证码已发送',
                        icon: "none"
                    });
                    this.setTimer(); //调用定时器方法
                } else {
                    this.getCodeText = "获取验证码" //发送验证码
                    this.getCodeisWaiting = false;
                    this.getCodeBtnColor = "#20613D";
                }
 
            },
            //setTimer: 需要每隔一段时间执行一件事的的时候就需要使用SetTimer函数
            setTimer() {
                let holdTime = 60; //定义变量并赋值
                this.getCodeText = "重新获取(60)"
                //setInterval()是一个实现定时调用的函数,可按照指定的周期(以毫秒计)来调用函数或计算表达式。
                //setInterval方法会不停地调用函数,直到 clearInterval被调用或窗口被关闭。
                this.Timer = setInterval(() => {
                    if (holdTime <= 0) {
                        this.getCodeisWaiting = false;
                        this.getCodeBtnColor = "#20613D";
                        this.getCodeText = "获取验证码"
                        clearInterval(this.Timer); //清除该函数
                        return; //返回前面
                    }
                    this.getCodeText = "重新获取(" + holdTime + ")"
                    holdTime--;
                }, 1000)
            },
            async getUserProfile(e) {
                const res = await wx.getUserProfile({
                    desc: '用于转账实名验证',
                });
                console.log('getUserProfile', res);
                // this.login_Wx(res.userInfo.avatarUrl, res.userInfo.nickName)
            },
            async wxlogin() {
                var that = this;
 
                if (!that.realName) {
                    uni.showToast({
                        title: '请输入真实姓名',
                        icon: 'none'
                    });
                    return;
                }
                if (!that.phoneNumber) {
                    uni.showToast({
                        title: '请输入手机号',
                        icon: 'none'
                    });
                    return;
                }
                if (!that.smsCode) {
                    uni.showToast({
                        title: '请输入手机验证码',
                        icon: 'none'
                    });
                    return;
                }
                let tmp = this
                wx.login({
                    success: async res => {
                        console.log(res)
                        if (res.code) {
                            tmp.login(res.code)
                        } else {
                            tmp.$message.showToast('微信登录失败');
                        }
                    },
                    error: res => {
                        console.log('wx.login error', res)
                        tmp.$message.showToast('获取微信信息失败:' + res);
                    }
                });
            },
            async login(wxcode) {
 
 
                let post = {
                    tel: this.phoneNumber,
                    smsCode: this.smsCode,
                    userType: this.apitype,
                    realName: this.realName,
                    wxCode: wxcode,
                }
                this.$message.showLoading()
                const resp = await this.$http.request('post', '/api/current/bind/wechat', {
                    data: post
                });
                this.$message.hideLoading()
 
                if (resp.code === 0) {
                    this.$message.showToast('操作成功')
                    this.currentInfo.bindWechat = true
                    setTimeout(() => {
                        uni.navigateBack()
 
                    }, 400)
                } else {
 
                    return;
                }
 
            },
 
        }
    };
</script>
<style lang="scss" scoped>
    .form-input {
        background-color: #f8f7fc;
        border-radius: 50rpx;
        margin-bottom: 50rpx;
        border: 1px solid #e9e9e9;
 
        /deep/ .u-input {
            padding-left: 60rpx !important;
            padding-right: 40rpx !important;
        }
 
        /deep/ input {
            height: 70rpx;
            line-height: 70rpx;
 
        }
 
    }
</style>
<style lang="scss" scoped>
    @import '../../login/login.scss';
 
    .main-container {
        margin: 20px 0;
    }
 
    .img-a {
        position: absolute;
        width: 100%;
        top: -150rpx;
        right: 0;
    }
 
    .img-b {
        position: absolute;
        width: 50%;
        bottom: 0;
        left: -120rpx;
    }
 
    .to-home {
        margin-top: 30rpx;
        font-size: 30rpx;
        color: #5af;
        display: flex;
        flex-direction: row-reverse;
    }
 
    .t-login {
        width: 100%;
        margin: 0 auto;
        font-size: 28rpx;
        color: #000;
    }
 
    .t-login .bg {
        width: 100%;
        position: relative;
    }
 
    .t-login .login {
        width: 650rpx;
        margin: 60rpx auto;
        margin-top: 0rpx;
        font-size: 28rpx;
        color: #000;
    }
 
    .t-login button {
        font-size: 28rpx;
        background: #5677fc;
        color: #fff;
        height: 90rpx;
        line-height: 90rpx;
        border-radius: 50rpx;
        box-shadow: 0 5px 7px 0 rgba(86, 119, 252, 0.2);
    }
 
    .t-login input {
        padding: 0 20rpx 0 60rpx;
        height: 90rpx;
        line-height: 90rpx;
        margin-bottom: 50rpx;
        background: #f8f7fc;
        border: 1px solid #e9e9e9;
        font-size: 28rpx;
        border-radius: 50rpx;
    }
 
    .t-login .t-a {
        position: relative;
 
        .get-code {
            // position: absolute;
            // right: 40rpx;
            // top: 25rpx;
        }
    }
 
    .t-login .t-a .icon {
        width: 40rpx;
        height: 40rpx;
        position: absolute;
        left: 24rpx;
        top: 14rpx;
        margin-right: 20rpx;
    }
 
    .t-login .t-a .line {
        width: 2rpx;
        height: 40rpx;
        background-color: #dedede;
        position: absolute;
        top: 28rpx;
        left: 98rpx;
    }
 
    .t-login .t-b {
        text-align: left;
        font-size: 46rpx;
        color: #000;
        padding: 300rpx 0 30rpx 0;
        font-weight: bold;
    }
 
    .t-login .t-b2 {
        text-align: left;
        font-size: 32rpx;
        color: #aaaaaa;
        padding: 0rpx 0 120rpx 0;
    }
 
    .t-login .t-c {
        position: absolute;
        right: 22rpx;
        top: 22rpx;
        background: #5677fc;
        color: #fff;
        font-size: 24rpx;
        border-radius: 50rpx;
        height: 50rpx;
        line-height: 50rpx;
        padding: 0 25rpx;
        z-index: 999;
    }
 
    .t-login .t-d {
        text-align: center;
        color: #999;
        margin: 80rpx 0;
    }
 
    .t-login .t-e {
        text-align: center;
        width: 250rpx;
        margin: 80rpx auto 0;
    }
 
    .t-login .t-g {
        float: left;
        width: 50%;
    }
 
    .t-login .t-e image {
        width: 50rpx;
        height: 50rpx;
    }
 
    .t-login .t-f {
        text-align: center;
        margin: 200rpx 0 0 0;
        color: #666;
    }
 
    .t-login .t-f text {
        margin-left: 20rpx;
        color: #aaaaaa;
        font-size: 27rpx;
    }
 
    // .t-login .uni-input-placeholder {
    //     color: #000;
    // }
 
    .cl {
        zoom: 1;
    }
 
    .cl:after {
        clear: both;
        display: block;
        visibility: hidden;
        height: 0;
        content: '\20';
    }
</style>