Blame view

ceres-uniapp-master/pages_category_page2/userModule/accountLogin.vue 10.7 KB
3f535f30   杨鑫   '初始'
1
  <template>
1991126c   杨鑫   '最新'
2
3
4
5
6
  	<!-- 登录 -->
  	<view class="container flex-items-plus flex-column">
  		<global-loading />
  		<view class="login-logoBox">
  			<!--   <image
3f535f30   杨鑫   '初始'
7
8
9
            class="login-logo"
            src="@/static/logo.png"
        ></image> -->
1991126c   杨鑫   '最新'
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
  			<text style="color:#3f9b6a;font-weight:bold;font-size:30px;">锦江公园</text>
  		</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 class="font-color-C5AA7B" @click="protocol('app_user_agreement')">《APP用户服务协议》</text>和
  			<text class="font-color-C5AA7B" @click="protocol('app_privacy_agreement')">《APP个人隐私协议》</text>
  		</view>
  	</view>
3f535f30   杨鑫   '初始'
48
49
50
  </template>
  
  <script>
1991126c   杨鑫   '最新'
51
  	import sendVerifyCode from "@/mixins/SendVerifyCode";
3f535f30   杨鑫   '初始'
52
  
1991126c   杨鑫   '最新'
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
  	const NET = require('../../utils/request')
  	const API = require('../../config/api')
  	export default {
  		data() {
  			return {
  				loginQuery: {
  					account: '',
  					code: '',
  					salesId: '',
  				},
  				// 获取验证码
  				VerifyQuery: {
  					phone: ""
  				},
  				agreement: false,
  				inviteSpell: {},
  				inviteSpelltype: false,
  				beforePage: undefined,
  				doubleBeforePage: undefined,
  				text: '获取验证码',
  				disabled: false,
  				remainingTime: 0, // 剩余倒计时时间
  			}
  		},
  		mixins: [sendVerifyCode],
  		onLoad(options) {
  			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]
  			}
  		},
  		methods: {
  			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'
3f535f30   杨鑫   '初始'
112
  					})
1991126c   杨鑫   '最新'
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
  				} 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 => {
  						uni.hideLoading()
  						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');
  						}
  
  						// 购物车右上角数量
  						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()
  								})
  							}
  							console.log(cartNum)
  							uni.setStorageSync('allCartNum', cartNum)
  						})
  						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')
  						console.dir(res)
  						uni.hideLoading()
  						uni.showToast({
  							title: res.data.message,
  							duration: 2000,
  							icon: 'none',
  						});
  					})
  				}
  
  			},
  			// 获取时间
  			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   杨鑫   '初始'
232
  
1991126c   杨鑫   '最新'
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
  			},
  			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后重试`;
3f535f30   杨鑫   '初始'
252
  
1991126c   杨鑫   '最新'
253
254
255
256
257
258
259
260
261
262
  					const timer = setInterval(() => {
  						this.remainingTime--;
  						if (this.remainingTime > 0) {
  							this.text = `${this.remainingTime}s后重试`;
  						} else {
  							clearInterval(timer);
  							this.disabled = false; // 倒计时结束,启用按钮
  							this.text = '获取验证码';
  						}
  					}, 1000);
3f535f30   杨鑫   '初始'
263
  
1991126c   杨鑫   '最新'
264
  					this.VerifyQuery.phone = this.loginQuery.account;
3f535f30   杨鑫   '初始'
265
  
1991126c   杨鑫   '最新'
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
  					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'
  						});
  					});
  				}
  			},
  			//绑定关系
  			bindSalesCustomer(salesId, storeId) {
  				if (salesId && storeId) {
  					//如果已登录,静默绑定客户关系,否则跳转到登录页面
  					NET.request(API.BindSalesCustomer, {
  						shopId: storeId,
  						distributorId: salesId
  					}, 'POST').then(res => {
  						uni.showToast({
  							title: "绑定成功",
  							icon: "none"
  						})
  					}).catch(res => {
  						uni.showToast({
  							title: res.data.message,
  							icon: "none"
  						})
  					})
  
  				}
  			},
  			// 多商户用户协议
  			protocol(type) {
  				uni.navigateTo({
  					url: 'protocol?type=' + type
  				})
  			},
  		}
  	}
3f535f30   杨鑫   '初始'
310
311
312
  </script>
  
  <style lang="scss">
1991126c   杨鑫   '最新'
313
314
315
316
317
318
319
320
321
322
323
324
  	.container {
  		background-color: #FFFFFF;
  		height: 100vh;
  
  		.login-logoBox {
  			margin-top: -300rpx;
  
  			.login-logo {
  				width: 234rpx;
  				height: 193rpx;
  			}
  		}
3f535f30   杨鑫   '初始'
325
  
1991126c   杨鑫   '最新'
326
327
328
329
330
  		.iphoneNum-box {
  			margin-top: 100rpx;
  			border-bottom: 1rpx solid #DDDDDD;
  			height: 100rpx;
  			width: 600rpx;
3f535f30   杨鑫   '初始'
331
  
1991126c   杨鑫   '最新'
332
333
334
335
  			.loginIcon {
  				width: 40rpx;
  				height: 53rpx;
  			}
3f535f30   杨鑫   '初始'
336
  
1991126c   杨鑫   '最新'
337
338
339
340
341
342
  			.iphoneNum-input {
  				color: #999999;
  				font-size: 28rpx;
  				font-weight: 400;
  			}
  		}
3f535f30   杨鑫   '初始'
343
  
1991126c   杨鑫   '最新'
344
345
346
347
  		.passwordNum-box {
  			border-bottom: 1rpx solid #DDDDDD;
  			height: 100rpx;
  			width: 600rpx;
3f535f30   杨鑫   '初始'
348
  
1991126c   杨鑫   '最新'
349
350
351
352
353
354
355
  			.passwordNum-input {
  				color: #999999;
  				font-size: 28rpx;
  				font-weight: 400;
  				width: 346rpx;
  			}
  		}
3f535f30   杨鑫   '初始'
356
  
1991126c   杨鑫   '最新'
357
358
359
360
361
362
363
364
  		.code-box {
  			border-bottom: 1rpx solid #DDDDDD;
  			height: 100rpx;
  			width: 360rpx;
  			display: flex;
  			flex-direction: row;
  			justify-content: space-between;
  			align-items: center;
3f535f30   杨鑫   '初始'
365
  
1991126c   杨鑫   '最新'
366
367
368
369
  			.loginIcon {
  				width: 44rpx;
  				height: 50rpx;
  			}
3f535f30   杨鑫   '初始'
370
  
1991126c   杨鑫   '最新'
371
372
373
  			.code-lab {
  				width: 200rpx;
  			}
3f535f30   杨鑫   '初始'
374
  
1991126c   杨鑫   '最新'
375
376
377
378
379
380
  			.codeNum-input {
  				color: #999999;
  				font-size: 28rpx;
  				font-weight: 400;
  			}
  		}
3f535f30   杨鑫   '初始'
381
  
1991126c   杨鑫   '最新'
382
383
384
385
386
387
388
389
390
391
392
  		.getcode {
  			background-color: #39be7a;
  			height: 100rpx;
  			width: 230rpx;
  			display: flex;
  			flex-direction: row;
  			justify-content: center;
  			align-items: center;
  			margin-left: 20rpx;
  			color: #FFFFFF;
  		}
3f535f30   杨鑫   '初始'
393
  
1991126c   杨鑫   '最新'
394
395
396
397
398
399
400
401
402
  		.registerBut {
  			background: #3f9b6a;
  			color: #FFEBC4;
  			height: 100rpx;
  			width: 600rpx;
  			text-align: center;
  			line-height: 100rpx;
  			margin-top: 30rpx;
  		}
3f535f30   杨鑫   '初始'
403
  
1991126c   杨鑫   '最新'
404
405
406
  		.agreement {
  			margin: 100rpx 50rpx;
  			line-height: 50rpx;
3f535f30   杨鑫   '初始'
407
  
1991126c   杨鑫   '最新'
408
409
410
411
412
413
414
415
  			image {
  				width: 34rpx;
  				height: 34rpx;
  				margin-right: 15upx;
  			}
  		}
  	}
  </style>