Blame view

src/pages/cart/cart.vue 14.7 KB
0db291810   BigBoss   “-mcomfirmOder页面
1
2
  <template>
  	<view class="content">
cc196c33c   喻鹏   购物车和用户推荐接口渲染
3
  		<block v-if="cartList.length==0">
ab4209caf   喻鹏   update
4
  			
cc196c33c   喻鹏   购物车和用户推荐接口渲染
5
6
7
8
9
10
11
  		</block>
  		<block v-else>
  			<view class="card">
  				<view class="cardHeader">
  					<view v-bind:class="pIsoPen? 'partentChecked' : 'partentCheck'"
  					@click="pChange(pIsoPen)">
  						<span class="correct"></span>
ab4209caf   喻鹏   update
12
  					</view>
cc196c33c   喻鹏   购物车和用户推荐接口渲染
13
14
15
16
17
18
19
20
21
  					<image src="../../static/store.png" mode="aspectFill"></image>
  					<text>非常戴镜</text>
  				</view>
  			
  				<view class="cardBody" v-for="(item,index) in cartList" :key="item.cart_id" 
  				@longpress="delCart(item.cart_id,index)">
  					<view v-bind:class="childIsOpen[index]? 'partentChecked':'partentCheck'" 
  					@click="Change(childIsOpen[index],index)">
  						<span class="correct"></span>
ab4209caf   喻鹏   update
22
  					</view>
cc196c33c   喻鹏   购物车和用户推荐接口渲染
23
24
25
  					<view class="goodInfo">
  						<view class="imageWrap">
  							<image :src="item.img_index_url" mode="aspectFit" style="width: 188rpx;height: 168rpx;"></image>
ab4209caf   喻鹏   update
26
  						</view>
cc196c33c   喻鹏   购物车和用户推荐接口渲染
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  						<view class="infoRight">
  							<view class="goodName" @tap="toGoods(item.pid,item.p_root_index)">{{item.p_name}}</view>
  							<view class="describ" @tap="toshop(item.pid,item.p_root_index)">
  								<text>
  									<block v-for="tag in item.tag.prod_tag_fun" :key="tag.value">
  										{{tag.label+`&nbsp;&nbsp;`}}
  									</block>
  								</text>
  							<view class="icon"></view>
  							</view>
  							<view class="priceBox">
  								<view class="price">¥{{item.nowPrice*item.num}}</view>
  								<text>(限购{{maxCount}}副)</text>
  								<view class="counter">
  									<view class="btn" disabled="this.addDisabled" type="default" 
  									@click="counter(index,false,item.mp_id,item.sk_id,item.num,item.cart_id)">-</view>
  									<text>{{item.num}}</text>
  									<view class="btn" disabled="this.desDisabled" type="default" 
  									@click="counter(index,true,item.mp_id,item.sk_id,item.num,item.cart_id)">+</view>
  								</view>
6111092e8   BigBoss   update cart
47
48
49
50
  							</view>
  						</view>
  					</view>
  				</view>
ab4209caf   喻鹏   update
51
  			</view>
cc196c33c   喻鹏   购物车和用户推荐接口渲染
52
  		</block>
6111092e8   BigBoss   update cart
53
54
55
  		<view class="footer">
  			<view class="footerLeft">实付金额:<text>¥{{totalPrice}}</text></view>
  			<view class="footerRight">
cc196c33c   喻鹏   购物车和用户推荐接口渲染
56
57
  				<navigator url="/pages/confirmOrder/confirmOrder" hover-class="navigator-hover">
  					<view class="paybtn" >立即结算</view>
ab4209caf   喻鹏   update
58
  				</navigator>
6111092e8   BigBoss   update cart
59
  			</view>
0db291810   BigBoss   “-mcomfirmOder页面
60
  		</view>
ab4209caf   喻鹏   update
61
  		
0db291810   BigBoss   “-mcomfirmOder页面
62
63
64
65
  	</view>
  </template>
  
  <script>
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
66
67
  	import store from '@/store';
  	
0db291810   BigBoss   “-mcomfirmOder页面
68
  	export default {
ab4209caf   喻鹏   update
69
  
0db291810   BigBoss   “-mcomfirmOder页面
70
71
  		data() {
  			return {
cc196c33c   喻鹏   购物车和用户推荐接口渲染
72
73
74
  				totalPrice: 0,
  				pIsoPen:false,
  				// childIsOpen:[],
6111092e8   BigBoss   update cart
75
  				maxCount:20,
0db291810   BigBoss   “-mcomfirmOder页面
76
77
  			}
  		},
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
78
  		computed:{
cc196c33c   喻鹏   购物车和用户推荐接口渲染
79
  
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
80
  			cartList() {
cc196c33c   喻鹏   购物车和用户推荐接口渲染
81
  			    // console.log('cart-list', this.$store.state.cart.cartList);
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
82
  			    return this.$store.state.cart.cartList;
cc196c33c   喻鹏   购物车和用户推荐接口渲染
83
84
85
86
87
88
89
90
91
  			},
  			childIsOpen(){
  				let temp=[];
  				temp.length=this.$store.state.cart.cartList.length;
  				for (let i = 0; i < temp.length; i++) {
  					temp[i]= false
  				}
  				console.log('this.childisOPne===>',temp)
  				return temp
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
92
93
94
  			}
  		},
  		onLoad: function() {
cc196c33c   喻鹏   购物车和用户推荐接口渲染
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
  			// 判断是否授权
  			// uni.getSetting({
  			// 	success(res) {
  			// 		console.log('authSetting',res.authSetting)
  			// 		if(res.authSetting['scope.userInfo'] !== true) {
  						
  			// 			uni.switchTab({
  			// 				url:'/pages/user/user'
  			// 			})
  			// 		}else {
  			// 		}
  			// 	}
  			// })
  
  			// console.log('usr-my',this.$store.state.user.userInfo)
  			// store.dispatch('cart/addCart',{
  			// 	"num":1,
  			// 	"pid": 7,//产品id
  			// 	"uid":1,
  			// 	"sk_id": 72,
  			// 	"price": 120,
  			// 	"mp_id":1,
  			// 	"checkedSKU":{
  			// 		 "discount": "45",
  			// 		 "in_price": "6000",
  			// 		 "kc": "0",
  			// 		 "model_pic": null,
  			// 		 "out_price": 191.8,
  			// 		 "pic": "https://glass.xiuyetang.com//upload_jk/7/7_22AE0C.jpg",
  			// 		 "pid": "7",
  			// 		 "real_price": 99,
  			// 		 "sk_id": "89",
  			// 		 "sku_name": "1.56非球面防蓝光_黑",
  			// 		 "sku_shop_value": "",
  			// 		 "sku_value": "58_61",
  			// 		 "status": "1",
  			// 	},	
  			// });
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
133
134
135
136
  			store.dispatch('cart/getCartList',{
  				uid: 1, //用户id
  			});
  		},
cc196c33c   喻鹏   购物车和用户推荐接口渲染
137
  
0db291810   BigBoss   “-mcomfirmOder页面
138
  		methods: {
cc196c33c   喻鹏   购物车和用户推荐接口渲染
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
  			// 跳转到对应的选购页面
  			toshop(id,type){
  				console.log('===',id,type)
  				switch(type){
  					case 1:
  						uni.navigateTo({
  							url:  `../detailsChoiceArgs/detailsChoiceArgs?oderId=`+id+`&goodType=`+type,
  							success: res => {},
  							fail: () => {},
  							complete: () => {}
  						});
  					break;
  					case 2:
  						uni.navigateTo({
  							url: `../detailStandard/detailStandard_k?oderId=`+id+`&goodType=`+type,
  							success: res => {},
  							fail: () => {},
  							complete: () => {}
  						});
  					break;
  					case 3||4:
  						uni.navigateTo({
  							url: `../detailStandard/detailStandard_sun?oderId=`+id+`&goodType=`+type,
  							success: res => {},
  							fail: () => {},
  							complete: () => {}
  						});
  					break;
  					// case 4:
  					// 	uni.navigateTo({
  					// 		url: `../detailStandard/detailStandard_sun?oderId=`+id+`&goodType=`+type,
  					// 		success: res => {},
  					// 		fail: () => {},
  					// 		complete: () => {}
  					// 	});
  					case 5:
  						uni.navigateTo({
  							url: `../purchaseLenses/purchaseLenses?oderId=`+id+`&goodType=`+type,
  							success: res => {},
  							fail: () => {},
  							complete: () => {}
  						});
  					break;
  					default :
  						break
  				}
  			},
  			toGoods(id,type){
  					uni.navigateTo({
  						url: `../frameDetail/frameDetail?oderId=`+id,
  						success: res => {},
  						fail: () => {},
  						complete: () => {}
  					});
  					console.log('toGoods =====> id:'+id +"======>type:"+type)
  					switch(type){
  						case 1:
  							uni.navigateTo({
  								url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  								success: res => {},
  								fail: () => {},
  								complete: () => {}
  							});
  						break;
  						case 2:
  							uni.navigateTo({
  								url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  								success: res => {},
  								fail: () => {},
  								complete: () => {}
  							});
  						break;
  						case 3:
  							uni.navigateTo({
  								url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  								success: res => {},
  								fail: () => {},
  								complete: () => {}
  							});
  						break;
  						case 4:
  							uni.navigateTo({
  								url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  								success: res => {},
  								fail: () => {},
  								complete: () => {}
  							});
  						break;
  						default :
  							break
  					}
  				},
  			
  			counter(index,isadd,mp_id,sk_id,num,cart_id){
  				// console.log('===>>counter ===>num',num)
  				// console.log('===>>counter ===>isadd',isadd)
  				num=parseInt(num);
6111092e8   BigBoss   update cart
236
  				if(isadd){
cc196c33c   喻鹏   购物车和用户推荐接口渲染
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
  					if(num>=this.maxCount){
  						this.addDisabled = true
  					} else{
  						this.addDisabled= true
  						// 修改num
  						store.dispatch('cart/modiCart',{
  							uid: 1,
  							// openid: '',
  							mp_id: mp_id,
  							sk_id: sk_id,
  							cart_id:cart_id,
  							num:num+1,
  							args:{
  								index:index,
  								isadd:isadd,
  							}
  						})
  						this.addDisabled= false
  					}
  				}else{
  					if(num<=1){
  						this.desDisabled = true
  					} else{
  						this.desDisabled = false
  						// post 请求修改相关参数
  						store.dispatch('cart/modiCart',{
  							uid: 1,
  							// openid: '',
  							mp_id: mp_id,
  							sk_id: sk_id,
  							cart_id:cart_id,
  							num:num-1,
  							args:{
  								index:index,
  								isadd:isadd,
  							}
  						})
  						this.desDisabled = true
  					}
  				}
  			},
  
  			Change(isopen,indexC){
  				// console.log('lalla===>',isopen)
  				this.childIsOpen[indexC]=!isopen
  				if(!isopen){
  					this.totalPrice=this.totalPrice+(this.$store.state.cart.cartList[indexC].num*this.$store.state.cart.cartList[indexC].nowPrice)
6111092e8   BigBoss   update cart
284
  				}else{
cc196c33c   喻鹏   购物车和用户推荐接口渲染
285
286
287
288
289
290
291
292
293
294
  					this.totalPrice=this.totalPrice-(this.$store.state.cart.cartList[indexC].num*this.$store.state.cart.cartList[indexC].nowPrice)
  				}
  				let m=true;
  				for (let i = 0; i < this.childIsOpen.length; i++) {
  					m=m&this.childIsOpen[i]
  				}
  				if(m==1){
  					this.pIsoPen=true
  				} else{
  					this.pIsoPen=false
6111092e8   BigBoss   update cart
295
296
  				}
  			},
ab4209caf   喻鹏   update
297
  			pChange(isopen){
ab4209caf   喻鹏   update
298
  				this.pIsoPen=!isopen
cc196c33c   喻鹏   购物车和用户推荐接口渲染
299
300
  				for (let i = 0; i < this.childIsOpen.length; i++) {
  					this.childIsOpen[i]=!isopen
ab4209caf   喻鹏   update
301
  				}
cc196c33c   喻鹏   购物车和用户推荐接口渲染
302
303
304
305
306
307
308
309
310
311
312
  				if(this.pIsoPen){
  					// 计算总价逻辑
  					if(this.childIsOpen.length!=0){
  						for (let i = 0; i < this.childIsOpen.length; i++) {
  							if(this.childIsOpen[i]){
  								this.totalPrice= this.totalPrice+(this.$store.state.cart.cartList[i].num*this.$store.state.cart.cartList[i].nowPrice)
  							}
  						}
  					} 
  				} else{
  					this.totalPrice=0
ab4209caf   喻鹏   update
313
  				}
cc196c33c   喻鹏   购物车和用户推荐接口渲染
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
  			
  			},
  			delCart(cart_id,index){
  				// console.log('userInfo',this.$store.state.user.userInfo)
  				cart_id=parseInt(cart_id)
  				// console.log('delcart------>cart_id',cart_id)
  				// console.log('cartlist====>delcart',this.$store.state.cart.cartList)
  				// console.log('delcart======>index',index)
  				uni.showModal({
  					title: "是否删除该商品",
  					// content: '是否删除该商品',
  					success: function (res) {
  						if (res.confirm) {
  							// this.$store.state.cart.cartList.splice(index,1)
  							store.dispatch('cart/delCart',{
  								uid: 1, //用户id
  								openid: "",
  								cart_id: cart_id, // 要修改的购物车id
  								arg:index, // 由于action 传参是能接收两参数,因此将index放入对象
  							});
  							console.log('用户点击确定');
  						} 
  					}
  				});
  
ab4209caf   喻鹏   update
339
  			}
0db291810   BigBoss   “-mcomfirmOder页面
340
341
342
343
  		}
  	}
  </script>
  
6111092e8   BigBoss   update cart
344
  <style lang="scss">
0db291810   BigBoss   “-mcomfirmOder页面
345
  	.content {
6111092e8   BigBoss   update cart
346
  		min-height: 100vh;
ab4209caf   喻鹏   update
347
  		background-color: #f2f2f2;
0db291810   BigBoss   “-mcomfirmOder页面
348
349
350
  		display: flex;
  		flex-direction: column;
  		align-items: center;
6111092e8   BigBoss   update cart
351
352
353
354
  		justify-content: space-between;
  		padding: 20rpx 40rpx;
  		box-sizing: border-box;
  		
ab4209caf   喻鹏   update
355
356
357
358
359
360
361
362
363
364
365
366
367
368
  		.partentCheck{
  			width: 16px;
  			height: 16px;
  			border-radius: 18px;
  			border: 1px solid #CFCFCF;
  			background-color: #FFFFFF;
  		}
  		.partentChecked{
  			width: 18px;
  			height: 18px;
  			border-radius: 18px;
  			background-color: #FF6B4A;
  			.correct {
  				display: inline-block;
cc196c33c   喻鹏   购物车和用户推荐接口渲染
369
370
371
  				position: relative;
  				width: 10rpx;
  				height: 2rpx;
ab4209caf   喻鹏   update
372
373
374
375
  				background: #FFFFFF;
  				line-height: 0;
  				font-size: 0;
  				position: relative;
cc196c33c   喻鹏   购物车和用户推荐接口渲染
376
  				top: -7px;
ab4209caf   喻鹏   update
377
378
379
380
381
382
  				left: 4px;
  				-webkit-transform: rotate(45deg);
  			}
  			.correct:after {
  				content: '/';
  				display: block;
cc196c33c   喻鹏   购物车和用户推荐接口渲染
383
384
  				width: 16rpx;
  				height: 2rpx;
ab4209caf   喻鹏   update
385
386
387
388
389
  				background: #FFFFFF;
  				-webkit-transform: rotate(-90deg) translateY(50%) translateX(50%);
  			}
  		}
  		
6111092e8   BigBoss   update cart
390
391
392
393
394
395
396
397
398
  		.card{
  			background-color: #FFFFFF;
  			border-radius: 16rpx;
  			box-sizing: border-box;
  			padding: 36rpx 36rpx 36rpx 18rpx;
  			display: flex;
  			flex-direction: column;
  			align-items: center;
  			justify-content: space-between;
cc196c33c   喻鹏   购物车和用户推荐接口渲染
399
  			margin-bottom: 180rpx;
6111092e8   BigBoss   update cart
400
401
402
403
404
405
406
407
408
  			.cardHeader{
  				width: 100%;
  				height: 36rpx;
  				display: flex;
  				align-items: center;
  				justify-content: flex-start;
  				image{
  					height: 32rpx;
  					width: 32rpx;
ab4209caf   喻鹏   update
409
410
411
412
413
414
415
416
  					padding-left: 6px;
  					padding-right: 10px;
  				}
  				text{
  					// font-family: PingFangSC-Regular;
  					font-size: 14px;
  					color: #333333;
  					letter-spacing: -0.26px;
6111092e8   BigBoss   update cart
417
418
419
420
421
422
423
424
425
426
427
428
429
  				}
  			}
  			.cardBody{
  				width: 100%;
  				height: 300rpx;
  				display: flex;
  				align-items: center;
  				justify-content: space-between;
  				.goodInfo{
  					width: 95%;
  					display: flex;
  					flex-direction: row;
  					justify-content: flex-start;
ab4209caf   喻鹏   update
430
  					padding-left: 6px;
6111092e8   BigBoss   update cart
431
432
433
  					.imageWrap{
  						height: 188rpx;
  						width: 188rpx;
ab4209caf   喻鹏   update
434
  						margin-right: 28rpx;
6111092e8   BigBoss   update cart
435
  						image{
ab4209caf   喻鹏   update
436
  							border-radius: 4px;
6111092e8   BigBoss   update cart
437
438
439
440
441
442
443
444
445
  							height: 188rpx;
  							width: 188rpx;
  						}
  					}
  					.infoRight{
  						display: flex;
  						flex-direction: column;
  						align-items: flex-start;
  						justify-content: space-between;
ab4209caf   喻鹏   update
446
  						height: 240rpx;
6111092e8   BigBoss   update cart
447
  						.goodName{
cc196c33c   喻鹏   购物车和用户推荐接口渲染
448
449
450
451
452
  							display: -webkit-box;
  							-webkit-box-orient: vertical;
  							-webkit-line-clamp: 2;
  							text-align: justify;
  							overflow: hidden;
6111092e8   BigBoss   update cart
453
454
455
456
457
458
459
460
461
  							font-size: 28rpx;
  							color: #333333;
  						}
  						.describ{
  							width: 100%;
  							height: 80rpx;
  							box-sizing: border-box;
  							padding: 10rpx;
  							font-size: 20rpx;
cc196c33c   喻鹏   购物车和用户推荐接口渲染
462
463
  							letter-spacing: -0.23px;
  							text-align: justify;
6111092e8   BigBoss   update cart
464
  							color: #999999;
cc196c33c   喻鹏   购物车和用户推荐接口渲染
465
  							background: #F9F9F9;
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
466
467
468
  							display: flex;
  							justify-content: center;
  							align-items: center;
6111092e8   BigBoss   update cart
469
470
471
472
473
474
475
476
477
478
479
  							text{
  								 text-overflow: -o-ellipsis-lastline;
  								  overflow: hidden;
  								  text-overflow: ellipsis;
  								  display: -webkit-box;
  								  -webkit-line-clamp: 2;
  								  line-clamp: 2;
  								  -webkit-box-orient: vertical;
  							}
  							// .icon{
  							// 	transform: rotate(90deg);
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
480
481
482
  							// 	height: 13px;
  							// 	width: 20px;
  
6111092e8   BigBoss   update cart
483
  							// }
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
  							.icon{
  							width: 0;
  							height: 0;
  							border-left: 5px transparent;
  							border-right: 5px transparent;
  							border-top: 5px #979797;
  							border-bottom: 0 transparent;
  							border-style: solid;
  							position: relative;
  							margin-left: 10px;
  							// transform: scaleY(-1);
  							}
  							.icon::after{
  							    content: '';
  							    position: absolute;
  							    top: -6.5px;
  							    left: -5px;
  								border-left: 5px transparent;
  								border-right: 5px transparent;
  								border-top: 5px #FFFFFF;
  								border-bottom: 0 transparent;
  								border-style: solid;
  							}
6111092e8   BigBoss   update cart
507
508
509
510
511
  						}
  						.priceBox{
  							display: flex;
  							justify-content: space-between;
  							align-items: center;
ab4209caf   喻鹏   update
512
  							// margin-top: 26px;
6111092e8   BigBoss   update cart
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
  							width: 100%;
  							font-size: 14px;
  							color: #999999;
  							.price{
  								color: #FF6B4A;
  								font-size: 28rpx;
  							}
  							.counter{
  								display: flex;
  								flex-direction: row;
  								justify-content: space-between;
  								align-items: center;
  								font-size: 28rpx;
  								color: #333333;
  								width: 122rpx;
  								.btn{
  									display: flex;
  									justify-content: center;
  									line-height: 32rpx;
  									height: 32rpx;
  									width: 32rpx;
  									background-color: #F2F2F2;
  									color: #CFCFCF;
  								}
  							}
  						}
  					}
  				}
  			}
  		}
  		
  		.footer{
  			position: fixed;
  			left: 0;
eab89b254   喻鹏   updates
547
  			bottom: 0px;
6111092e8   BigBoss   update cart
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
  			height: 112rpx;
  			width: 100%;
  			background-color: #FFFFFF;
  			font-size: 16px;
  			display: flex;
  			justify-content: space-between;
  			align-items: center;
  			.footerLeft{
  				display: flex;
  				justify-content: center;
  				align-items: center;
  				width: 50%;
  				color: #333333;
  				text{
  					color: #FF6B4A;
  				}
  			}
  			.footerRight{
  				display: flex;
  				justify-content: flex-end;
  				align-items: center;
  				width: 50%;
  				margin-right: 26rpx;
  				.paybtn{
  					display: flex;
  					justify-content: center;
  					align-items: center;
  					background: #FF6B4A;
  					border-radius: 20px;
  					border-radius: 20px;
  					color: #FFFFFF;
  					width: 204rpx;
  					height: 80rpx;
  				}
  			}
  				
  		}
0db291810   BigBoss   “-mcomfirmOder页面
585
  	}
6111092e8   BigBoss   update cart
586
  	
ab4209caf   喻鹏   update
587
588
  	
  	
a2408fc3f   BigBoss   init
589
  </style>