Blame view

ceres-uniapp-master/pages_category_page2/userModule/login.vue 13.3 KB
3f535f30   杨鑫   '初始'
1
  <template>
e65c626a   杨鑫   '改bug'
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
  	<!-- 登录 -->
  	<view class="container flex-items-plus flex-column" :style="{backgroundImage:`url(${$imgUrl('/homePhoto.png')})`}">
  		<global-loading />
  		<view style="height: 100vh;width: 100%;position: fixed;bottom: 0;left: 0;">
  			<view style="width: 45%;margin: 0 auto;margin-top: 15vh;">
  				<image src="../../static/login/logo1.png" style="width: 100%;" mode="widthFix"></image>
  			</view>
  
  			<view style="width:60%;margin: 0 auto;">
  				<image src="../../static/login/logo2.png" style="width: 100%;" mode="widthFix"></image>
  			</view>
  			<!-- 填写区 -->
  			<view class="input-info" style="margin-top: 5vh;">
  				<view class="info">
  					<view class="info-icon">
  						<image src="../../static/login/icon1.png" mode="heightFix"></image>
  					</view>
  					<input v-model="loginQuery.account" type="tel" maxlength='11' placeholder="请输入您的手机号" />
  					<view class="more"></view>
  				</view>
  				<view class="info">
  					<view class="info-icon">
  						<image src="../../static/login/icon2.png" mode="heightFix"></image>
  					</view>
  
  					<input v-model="loginQuery.code" :maxlength="6" type="tel" placeholder="请输入验证码" />
  					<view class="more">
  						<text class="mo" v-if="!disabled" @click="codede">获取验证码</text>
  						<text class="mo" v-else>{{text}}</text>
  						<!-- <view :class="disabled === true ? 'no' : ''" :disabled="disabled" class="getcode"
  							@click="codede">{{ text }}
  						</view> -->
  					</view>
  				</view>
  			</view>
  			<!-- 按钮 -->
  			<view class="btn-info">
  				<view class="btn" @click="login">
  					<text>登录</text>
  				</view>
  			</view>
  	<!-- 		<view class="iphoneNum-box flex-row-plus flex-items">
  				<view style="margin-right: 30rpx">
  					<image class="loginIcon"
  						src="https://jy.scjysm.asia:18086/cdwlMall/questionnaire/file/static/images/phone.png"></image>
  				</view>
  				<view>
  					<input v-model="loginQuery.account" placeholder-class="iphoneNum-input" type="number" maxlength='11'
  						placeholder="请输入您的手机号" />
  				</view>
  			</view>
  			<view class="flex-row-plus">
  				<view class="code-box">
  					<view style="margin-right: 30rpx">
  						<image class="loginIcon"
  							src="https://jy.scjysm.asia:18086/cdwlMall/questionnaire/file/static/images/code.png">
  						</image>
  					</view>
  					<view>
  						<input v-model="loginQuery.code" :maxlength="6" placeholder-class="codeNum-input"
  							placeholder="请输入验证码" />
  					</view>
  				</view>
  				<view :class="disabled === true ? 'on' : ''" :disabled="disabled" class="getcode" @click="codede">
  					{{ text }}
  				</view>
  			</view> -->
  			<!-- <view class="mar-top-60">
  				<view class="registerBut mar-top-100" @click="login">登录
  				</view>
  			</view> -->
  			<view class="agreement">
  				<image v-if="!agreement" src="../../static/images/none.png" mode="" @click="agreement=true"></image>
  				<image v-else src="../../static/images/solid.png" mode="" @click="agreement=false"></image>
  				<text class="font-color-999">登录即代表同意</text>
  				<text style="color: #3f9b6a;" @click="protocol('app_user_agreement')">《APP用户服务协议》</text>和
  				<text style="color: #3f9b6a;" @click="protocol('app_privacy_agreement')">《APP个人隐私协议》</text>
  			</view>
3f535f30   杨鑫   '初始'
80
  		</view>
3f535f30   杨鑫   '初始'
81
82
83
84
  	</view>
  </template>
  
  <script>
e65c626a   杨鑫   '改bug'
85
86
  	import sendVerifyCode from "@/mixins/SendVerifyCode";
  
3f535f30   杨鑫   '初始'
87
88
89
90
91
  	const NET = require('../../utils/request')
  	const API = require('../../config/api')
  	export default {
  		data() {
  			return {
e65c626a   杨鑫   '改bug'
92
93
94
95
96
97
98
99
  				loginQuery: {
  					account: '',
  					code: '',
  					salesId: '',
  				},
  				// 获取验证码
  				VerifyQuery: {
  					phone: ""
3f535f30   杨鑫   '初始'
100
  				},
e65c626a   杨鑫   '改bug'
101
102
103
104
105
106
107
108
  				agreement: false,
  				inviteSpell: {},
  				inviteSpelltype: false,
  				beforePage: undefined,
  				doubleBeforePage: undefined,
  				text: '获取验证码',
  				disabled: false,
  				remainingTime: 0, // 剩余倒计时时间
3f535f30   杨鑫   '初始'
109
110
  			}
  		},
e65c626a   杨鑫   '改bug'
111
  		mixins: [sendVerifyCode],
3f535f30   杨鑫   '初始'
112
  		onLoad(options) {
e65c626a   杨鑫   '改bug'
113
114
115
116
117
118
119
120
121
122
123
  			if (options.inviteSpell == 1) {
  				this.inviteSpelltype = true
  				this.inviteSpell = uni.getStorageSync('inviteSpell');
  			}
  			this.loginQuery.salesId = uni.getStorageSync('salesId');
  			var pages = getCurrentPages()
  			if (pages.length >= 2) {
  				this.beforePage = pages[pages.length - 2]
  			}
  			if (pages.length >= 3) {
  				this.doubleBeforePage = pages[pages.length - 3]
3f535f30   杨鑫   '初始'
124
  			}
3f535f30   杨鑫   '初始'
125
126
  		},
  		methods: {
e65c626a   杨鑫   '改bug'
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
  			login() {
  				let phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
  				if (this.loginQuery.account == '') {
  					uni.showToast({
  						title: '请输入手机号!',
  						duration: 2000,
  						icon: 'none'
  					});
  				} else if (!phoneCodeVerification.test(this.loginQuery.account)) {
  					uni.showToast({
  						title: '请输入正确的手机号!',
  						duration: 2000,
  						icon: 'none'
  					});
  				} else if (this.loginQuery.code == '') {
  					uni.showToast({
  						title: '请获取验证码!',
  						duration: 2000,
  						icon: 'none'
  					})
  				} else if (!this.agreement) {
  					uni.showToast({
  						title: '请先阅读并同意《用户服务协议和个人隐私协议》',
  						duration: 2000,
  						icon: 'none'
  					});
  				} else {
  					const that = this
  					// uni.showLoading({
  					//   mask: true,
  					//   title: '正在登录...',
  					//   duration: 2000,
  					// });
  					NET.request(API.Login, {
  						phone: this.loginQuery.account,
  						verificationCode: this.loginQuery.code
  					}, 'POST').then(res => {
3f535f30   杨鑫   '初始'
164
  						uni.hideLoading()
e65c626a   杨鑫   '改bug'
165
166
167
168
169
170
171
172
173
  						const item = res.data
  						uni.setStorageSync('storage_key', item);
  						if (uni.getStorageSync("salesId")) {
  							let salesId = uni.getStorageSync("salesId")
  							let shopId = uni.getStorageSync("shopId")
  							this.bindSalesCustomer(salesId, shopId)
  							uni.removeStorageSync('salesId');
  							uni.removeStorageSync('shopId');
  						}
3f535f30   杨鑫   '初始'
174
  
e65c626a   杨鑫   '改bug'
175
176
177
178
179
180
181
182
183
184
185
186
187
  						// 购物车右上角数量
  						NET.request(API.ShoppingCart, {}, 'GET').then(resCart => {
  							let cartNum = 0
  							resCart.data.forEach(shopItem => {
  								shopItem.skus.forEach(goodsItem => {
  									cartNum += goodsItem.number
  								})
  							})
  							if (cartNum > 0) {
  								uni.setTabBarBadge({
  									index: 2,
  									text: cartNum.toString()
  								})
3f535f30   杨鑫   '初始'
188
  							}
e65c626a   杨鑫   '改bug'
189
190
  							console.log(cartNum)
  							uni.setStorageSync('allCartNum', cartNum)
3f535f30   杨鑫   '初始'
191
  						})
e65c626a   杨鑫   '改bug'
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
  						if (this.inviteSpelltype == true) {
  							setTimeout(function() {
  								uni.reLaunch({
  									url: '../../pages_category_page1/goodsModule/inviteSpell?collageId=' +
  										this.inviteSpell.collageId + '&orderId=' + this.inviteSpell
  										.orderId + '&type=0' + '&productId=' + this.inviteSpell
  										.productId + '&skuId=' + this.inviteSpell.skuId
  								})
  								uni.removeStorageSync('inviteSpell');
  							}, 2000)
  						} else {
  							if (that.beforePage && that.beforePage.route !==
  								'pages_category_page2/userModule/accountLogin' &&
  								that.beforePage.route !== 'pages_category_page2/userModule/login' &&
  								that.beforePage.route !== 'pages_category_page2/userModule/register') {
  								console.log(19)
  								uni.navigateBack({
  									delta: 1
  								})
  							} else if (that.doubleBeforePage && that.doubleBeforePage.route !==
  								'pages_category_page2/userModule/accountLogin' &&
  								that.doubleBeforePage.route !== 'pages_category_page2/userModule/login' &&
  								that.doubleBeforePage.route !== 'pages_category_page2/userModule/register') {
  								uni.navigateBack({
  									delta: 2
  								})
  							} else {
  								NET.request(API.GetUser, {}, 'GET').then(res => {
  									let MsgList = {
  										username: res.data.name,
  										userId: res.data.buyerUserId,
  										phoneNumber: res.data.phone,
  										createTime: this.getCurrentDateTime(),
  									}
  									NET.request(API.DengJi, MsgList, 'POST').then(res => {
  
  									})
  								})
  								setTimeout(function() {
  									uni.switchTab({
  										url: '../../pages/tabbar/user/index'
  									})
  								}, 600)
  							}
  						}
  					}).catch(res => {
  						console.log('Login failed')
3f535f30   杨鑫   '初始'
239
  						console.dir(res)
e65c626a   杨鑫   '改bug'
240
  						uni.hideLoading()
3f535f30   杨鑫   '初始'
241
  						uni.showToast({
e65c626a   杨鑫   '改bug'
242
243
244
  							title: res.data.message,
  							duration: 2000,
  							icon: 'none',
3f535f30   杨鑫   '初始'
245
  						});
3f535f30   杨鑫   '初始'
246
  					})
e65c626a   杨鑫   '改bug'
247
248
  				}
  
3f535f30   杨鑫   '初始'
249
  			},
e65c626a   杨鑫   '改bug'
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  			// 获取时间
  			getCurrentDateTime() {
  				const now = new Date();
  				const year = now.getFullYear();
  				const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的,所以需要+1
  				const day = String(now.getDate()).padStart(2, '0');
  				const hours = String(now.getHours()).padStart(2, '0');
  				const minutes = String(now.getMinutes()).padStart(2, '0');
  				const seconds = String(now.getSeconds()).padStart(2, '0');
  
  				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  			},
  			// 获取验证码
  			codede() {
  				if (this.disabled) return
  				this.getVerify()
  
3f535f30   杨鑫   '初始'
267
  			},
e65c626a   杨鑫   '改bug'
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
  			getVerify() {
  				let phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
  				if (this.loginQuery.account === '') {
  					uni.showToast({
  						title: '请输入手机号!',
  						duration: 2000,
  						icon: 'none'
  					});
  				} else if (!phoneCodeVerification.test(this.loginQuery.account)) {
  					uni.showToast({
  						title: '请输入正确的手机号!',
  						duration: 2000,
  						icon: 'none'
  					});
  				} else {
  					this.disabled = true;
  					this.remainingTime = 60;
  					this.text = `${this.remainingTime}s后重试`;
  
  					const timer = setInterval(() => {
  						this.remainingTime--;
  						if (this.remainingTime > 0) {
  							this.text = `${this.remainingTime}s后重试`;
  						} else {
  							clearInterval(timer);
  							this.disabled = false; // 倒计时结束,启用按钮
  							this.text = '获取验证码';
3f535f30   杨鑫   '初始'
295
  						}
e65c626a   杨鑫   '改bug'
296
  					}, 1000);
3f535f30   杨鑫   '初始'
297
  
e65c626a   杨鑫   '改bug'
298
  					this.VerifyQuery.phone = this.loginQuery.account;
3f535f30   杨鑫   '初始'
299
  
e65c626a   杨鑫   '改bug'
300
301
302
303
304
305
306
307
308
309
310
311
312
  					NET.request(API.verification, {
  						phone: this.VerifyQuery.phone
  					}, 'POST').then(res => {
  						// 如果 sendCode 方法有实际用途,需要定义该方法
  						// this.sendCode(); 
  						console.log(res);
  					}).catch(res => {
  						uni.showToast({
  							title: res.data.message,
  							duration: 1000,
  							icon: 'none'
  						});
  					});
3f535f30   杨鑫   '初始'
313
314
  				}
  			},
e65c626a   杨鑫   '改bug'
315
316
317
318
  			//绑定关系
  			bindSalesCustomer(salesId, storeId) {
  				if (salesId && storeId) {
  					//如果已登录,静默绑定客户关系,否则跳转到登录页面
3f535f30   杨鑫   '初始'
319
  					NET.request(API.BindSalesCustomer, {
e65c626a   杨鑫   '改bug'
320
  						shopId: storeId,
3f535f30   杨鑫   '初始'
321
322
  						distributorId: salesId
  					}, 'POST').then(res => {
e65c626a   杨鑫   '改bug'
323
324
325
326
327
328
329
330
331
  						uni.showToast({
  							title: "绑定成功",
  							icon: "none"
  						})
  					}).catch(res => {
  						uni.showToast({
  							title: res.data.message,
  							icon: "none"
  						})
3f535f30   杨鑫   '初始'
332
  					})
e65c626a   杨鑫   '改bug'
333
  
3f535f30   杨鑫   '初始'
334
  				}
e65c626a   杨鑫   '改bug'
335
336
337
338
339
340
341
  			},
  			// 多商户用户协议
  			protocol(type) {
  				uni.navigateTo({
  					url: 'protocol?type=' + type
  				})
  			},
3f535f30   杨鑫   '初始'
342
343
344
345
346
347
  		}
  	}
  </script>
  
  <style lang="scss">
  	.container {
e65c626a   杨鑫   '改bug'
348
349
350
351
352
353
  		position: absolute;
  		left: 0;
  		top: 0;
  		width: 100%;
  		height: 100%;
  		background-size: cover;
3f535f30   杨鑫   '初始'
354
  		background-color: #FFFFFF;
3f535f30   杨鑫   '初始'
355
356
  
  		.login-logoBox {
e65c626a   杨鑫   '改bug'
357
  			margin-top: -300rpx;
3f535f30   杨鑫   '初始'
358
359
  
  			.login-logo {
e65c626a   杨鑫   '改bug'
360
361
  				width: 234rpx;
  				height: 193rpx;
3f535f30   杨鑫   '初始'
362
363
364
  			}
  		}
  
e65c626a   杨鑫   '改bug'
365
  		.iphoneNum-box {
3f535f30   杨鑫   '初始'
366
  			margin-top: 100rpx;
e65c626a   杨鑫   '改bug'
367
368
369
  			border-bottom: 1rpx solid #DDDDDD;
  			height: 100rpx;
  			width: 600rpx;
3f535f30   杨鑫   '初始'
370
  
e65c626a   杨鑫   '改bug'
371
372
373
374
  			.loginIcon {
  				width: 40rpx;
  				height: 53rpx;
  			}
3f535f30   杨鑫   '初始'
375
  
e65c626a   杨鑫   '改bug'
376
377
378
379
  			.iphoneNum-input {
  				color: #999999;
  				font-size: 28rpx;
  				font-weight: 400;
3f535f30   杨鑫   '初始'
380
381
382
  			}
  		}
  
e65c626a   杨鑫   '改bug'
383
384
385
  		.passwordNum-box {
  			border-bottom: 1rpx solid #DDDDDD;
  			height: 100rpx;
3f535f30   杨鑫   '初始'
386
  			width: 600rpx;
e65c626a   杨鑫   '改bug'
387
388
389
390
391
392
393
  
  			.passwordNum-input {
  				color: #999999;
  				font-size: 28rpx;
  				font-weight: 400;
  				width: 346rpx;
  			}
3f535f30   杨鑫   '初始'
394
395
  		}
  
e65c626a   杨鑫   '改bug'
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
  		.code-box {
  			border-bottom: 1rpx solid #DDDDDD;
  			height: 100rpx;
  			width: 360rpx;
  			display: flex;
  			flex-direction: row;
  			justify-content: space-between;
  			align-items: center;
  
  			.loginIcon {
  				width: 44rpx;
  				height: 50rpx;
  			}
  
  			.code-lab {
  				width: 200rpx;
  			}
  
  			.codeNum-input {
  				color: #999999;
  				font-size: 28rpx;
  				font-weight: 400;
  			}
  		}
  
  		.getcode {
  			background-color: #39be7a;
  			height: 100rpx;
  			width: 230rpx;
  			display: flex;
  			flex-direction: row;
  			justify-content: center;
  			align-items: center;
  			margin-left: 20rpx;
  			color: #FFFFFF;
  		}
  
  		.registerBut {
  			background: #3f9b6a;
3f535f30   杨鑫   '初始'
435
  			color: #FFEBC4;
e65c626a   杨鑫   '改bug'
436
  			height: 100rpx;
3f535f30   杨鑫   '初始'
437
438
  			width: 600rpx;
  			text-align: center;
e65c626a   杨鑫   '改bug'
439
  			line-height: 100rpx;
3f535f30   杨鑫   '初始'
440
441
442
  			margin-top: 30rpx;
  		}
  
e65c626a   杨鑫   '改bug'
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
  		.agreement {
  			margin: 100rpx 50rpx;
  			line-height: 50rpx;
  
  			image {
  				width: 34rpx;
  				height: 34rpx;
  				margin-right: 15upx;
  			}
  		}
  	}
  	/* 填写 */
  	.input-info{
  	  padding: 0 6%;
  	  // margin: 80rpx 0 40rpx 0;
  	  .info{
  	    display: flex;
  	    align-items:center;
  	    justify-content: space-between;
  	    width: 100%;
  	    height: 100rpx;
  		background-color: #fff;
  		border-radius: 32rpx;
  		margin-bottom: 40rpx;
  		padding: 0 30rpx 0 40rpx;
  		border: 2rpx solid rgba(15,187,89,0.1804);
  	    input{
  	      width: 70%;
  	      height: 100%;
  	      font-size: 26rpx;
  	      color: #222222;
  	    }
  		.info-icon {
  			image {
  				width: 28rpx;
  				height: 28rpx;
  				margin-right: 20rpx;
  			}
3f535f30   杨鑫   '初始'
481
  		}
e65c626a   杨鑫   '改bug'
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
  	    .more{
  	      display: flex;
  	      align-items: center;
  	      justify-content: flex-end;
  	      width: 32%;
  	      height: 100%;
  	      .iconfont{
  	        font-size: 34rpx;
  	      }
  	      .mo{
  	        font-size: 26rpx;
  	        padding-left: 20rpx;
  	        // margin-left: 10rpx;
  	        border-left: 2rpx solid #ccc;
  	      }
  	    }
  	  }
3f535f30   杨鑫   '初始'
499
  	}
e65c626a   杨鑫   '改bug'
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
  	/* 按钮 */
  	.btn-info{
  	  display: flex;
  	  align-items: center;
  	  justify-content: center;
  	  width: 100%;
  	  .btn{
  	    display: flex;
  	    align-items: center;
  	    justify-content: center;
  	    width: 88%;
  	    height: 90rpx;
  	    background-color:#0FBB59;
  	    border-radius: 32rpx;
  	    color: #FFFFFF;
  	    font-size: 32rpx;
  	  }
3f535f30   杨鑫   '初始'
517
  	}
e65c626a   杨鑫   '改bug'
518
  </style>