cartlist.vue
13.4 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
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<template>
<view class="content">
<view class="sureshop">
<!-- 店铺商品-->
<view v-if="data1.length!=0">
<view class="sureorderbox flexone">
<view class="sureimg">
<image src="../../static/nearshop.png" mode=""></image>
</view>
<view class="sureshopname">红大地面品厂</view>
</view>
<view class='cartlist'>
<view class="sureorderitem flexone">
<view class="cartselimg">
<image src="../../static/cartsel.png" mode=""></image>
</view>
<view class="sureorderitemleft">
<image src="../../static/goodtailtop.png" mode=""></image>
</view>
<view class='shuright'>
<view class="suregoodnamek">商品名称商品名称商品名称商
品名称商品名称商品名称商品名称商品名称
</view>
<view class="surebot flextwo">
<view class="saleprice">¥288</view>
<view class="weightnumk flexone">
<view class="weightnumkleft leftk">
<image src="../../static/addimg.png" mode=""></image>
</view>
<view class="detailnum">1</view>
<view class="weightnumkleft rightk">
<image src="../../static/reduceimg.png" mode=""></image>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 面坊商品 -->
<view v-if="data2.length!=0">
<view class="sureorderbox flexone">
<view class="sureimg">
<image src="../../static/nearshop.png" mode=""></image>
</view>
<view class="sureshopname">面坊商品</view>
</view>
<view class='cartlist'>
<view class="sureorderitem flexone" v-for="(item,index) in data2" :key="index">
<view class="cartselimg" @click="selectcart(item,index)">
<image src="../../static/cartnosel.png" mode="" v-if="item.sel==false"></image>
<image src="../../static/cartsel.png" mode="" v-else></image>
</view>
<view class="sureorderitemleft">
<image :src="item.flour_goods.flour_goods_spec.spec_image" mode=""></image>
</view>
<view class='shuright'>
<view class="suregoodnamek">
{{item.flour_goods.name}}
</view>
<!-- 商品属性 -->
<view v-if="item.flour_goods.spec.length!=0">
<view class="spec" v-for="(item,index) in item.flour_goods.spec" :key="index">{{item.spec_name}}:{{item.spec_value}}</view>
</view>
<view class="surebot flextwo">
<view class="saleprice">¥{{item.flour_goods.price}}</view>
<view class="weightnumk flexone">
<view class="weightnumkleft rightk" @click="reducecart(item)">
<image src="../../static/reduceimg.png" mode=""></image>
</view>
<view class="detailnum">{{item.number}}</view>
<view class="weightnumkleft leftk" @click="addcart(item)">
<image src="../../static/addimg.png" mode=""></image>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 积分商品 -->
<view v-if="data3.length!=0">
<view class="sureorderbox flexone" @click="jifenshop">
<view class="sureimg">
<image src="../../static/nearshop.png" mode=""></image>
</view>
<view class="sureshopname">积分商品</view>
</view>
<view class='cartlist'>
<view class="sureorderitem flexone" v-for="(item,index) in data3" :key="index">
<view class="flexone" @click="selectcart(item)">
<view class="cartselimg">
{{item.sel}}
<image src="../../static/cartsel.png" mode="" v-if="item.sel==true"></image>
<image src="../../static/cartnosel.png" mode="" v-else></image>
</view>
<view class="sureorderitemleft">
<image src="" mode=""></image>
</view>
</view>
<view class='shuright'>
<!-- {{item.score_goods.name}} {{item.sel}} -->
<view class="suregoodnamek">
{{item.score_goods.name}}
</view>
<view v-if="item.score_goods.spec.length!=0">
<view class="spec" v-for="(item,index) in item.score_goods.spec" :key="index">{{item.spec_name}}:{{item.spec_value}}</view>
</view>
<view class="surebot flextwo">
<view class="saleprice">¥{{item.score_goods.price}}</view>
<view class="weightnumk flexone">
<view class="weightnumkleft rightk" @click="reducecart(item)">
<image src="../../static/reduceimg.png" mode=""></image>
</view>
<view class="detailnum">{{item.number}}</view>
<view class="weightnumkleft leftk" @click='addcart(item)'>
<image src="../../static/addimg.png" mode=""></image>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="cartbottom flextwo">
<view class="cartbotleft flexone" @click="selectall">
<view class="cartselimg">
<image src="../../static/cartsel.png" mode="" v-if="selall"></image>
<image src="../../static/cartnosel.png" mode="" v-else></image>
</view>
<view class="totalnum">总计:</view>
<view class="totalmoney">¥{{total}}</view>
</view>
<view class='jiesuan' @click="jiesuan">去结算({{arr.length}}件)</view>
</view>
</view>
</view>
</template>
<script>
import app from "../../App.vue";
export default {
data() {
return {
data1: [], //店铺商品
data2: [], //面坊商品
data3: [], //积分商品
selall: false,
total: 0,
arr:[],
data:[]
}
},
onLoad() {
// 获取购物车列表
this.getcartlist()
console.log(uni.getStorageSync("token"))
},
methods: {
// 积分商品
jifenshop() {
uni.navigateTo({
url: '/pages/homepage/jifenshop'
})
},
//面坊商品
mianfang() {
uni.navigateTo({
url: '/pages/homepage/shoplist'
})
},
// 获取购物车列表
getcartlist() {
let that = this;
var url = 'car/get_all';
var params = {
}
console.log(params)
app.post(url, params).then((res) => {
console.log(res);
that.data1 = res.data.data.data3;
that.data2 = res.data.data.data1;
that.data3 = res.data.data.data2;
// 面坊商品
that.data2.forEach(function(value, index, array) {
value.sel = false;
})
that.data2 = that.data2;
console.log('738932893', that.data2)
// 积分商品
that.data3.forEach(function(value, index, array) {
value.sel = false
})
that.data3 = that.data3;
}).catch((err) => {
console.log(err)
})
},
//面坊商品选择购物车
selectcart(item, index) {
console.log(item, index)
let that = this;
let obj={}
if (item.type == 2) {
that.data3.forEach(function(value, index, array) {
if (value.id == item.id) {
value.sel = !value.sel;
if (value.sel == true) {
that.arr.push(1)
that.total = that.total * 100 / 100 + value.score_goods.price * 100 / 100 * value.number;
console.log(6666);
obj.type=item.type;
obj.goods_id=item.goods_id;
obj.spec_sku_id=item.spec_sku_id;
obj.number=item.number;
console.log('34898348',obj);
that.data.push(obj)
} else {
that.arr.splice(0,1)
that.total = that.total * 100 / 100 - value.score_goods.price * 100 / 100 * value.number;
that.data.forEach(function(value,index,array){
console.log(value.goods_id);
console.log(item.goods_id)
if(item.goods_id==value.goods_id){
console.log(34349349043)
that.data.splice(index,1)
}
})
}
that.data=that.data;
console.log(that.data)
}
})
that.data3 = that.data3
} else if (item.type == 1) {
console.log(88888)
that.data2.forEach(function(value, index, array) {
if (value.id == item.id) {
value.sel = !value.sel;
if (value.sel == true) {
that.arr.push(1)
that.total = that.total * 100 / 100 + value.flour_goods.price * 100 / 100 * value.number;
obj.type=item.type;
obj.goods_id=item.goods_id;
obj.spec_sku_id=item.spec_sku_id;
obj.number=item.number;
that.data.push(obj)
} else {
that.total = that.total * 100 / 100 - value.flour_goods.price * 100 / 100 * value.number;
that.arr.splice(0,1);
that.data.forEach(function(value,index,array){
if(item.goods_id==value.goods_id){
that.data.splice(index,1)
}
})
}
}
})
that.data2 = that.data2;
that.data=that.data;
console.log(that.data)
}
},
// 选择全部购物车
selectall() {
let that=this;
this.selall = !this.selall;
let newarr=[];
let newtotal=0
if (this.selall == true) {
this.data3.forEach(function(value, index, array) {
value.sel = true;
newarr.push(1);
newtotal=newtotal+value.score_goods.price * 100 / 100 * value.number
// this.total = this.total * 100 / 100 + value.score_goods.price * 100 / 100 * value.number
})
this.data2.forEach(function(value, index, array){
value.sel = true;
newtotal=newtotal+value.flour_goods.price * 100 / 100 * value.number
// this.total = this.total * 100 / 100 + value.flour_goods.price * 100 / 100 * value.number;
newarr.push(1)
})
} else {
this.data3.forEach(function(value, index, array) {
value.sel = false;
})
this.data2.forEach(function(value, index, array){
value.sel =false
})
newarr=[];
newtotal=0
}
this.data3 = this.data3;
this.total=newtotal;
this.arr=newarr;
},
//购物车增加
addcart(item) {
let that = this
if (item.type == 2) {
that.data3.forEach(function(value, index, array) {
if (value.id == item.id) {
value.number++;
if (item.sel == true) {
that.total = that.total * 100 / 100 + value.score_goods.price * 100 / 100 * 1;
}
}
})
that.data3 = that.data3;
} else if (item.type == 1) {
that.data2.forEach(function(value, index, array) {
if (value.id == item.id) {
value.number++;
if (item.sel == true) {
that.total = that.total * 100 / 100 + value.flour_goods.price * 100 / 100 * 1;
}
}
})
that.data2 = that.data2;
}
that.addcartk(item.id)
},
// 购物车增加
addcartk(id) {
let that = this;
var url = 'car/update_car';
var params = {
type: 1,
car_id: id
}
console.log(params)
app.post(url, params).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err)
})
},
// 购物车减少
reducecart(item) {
let that = this;
if (item.type == 2) {
that.data3.forEach(function(value, index, array) {
if (value.id == item.id) {
if (value.number > 1) {
value.number = value.number - 1;
if (item.sel == true) {
that.total = that.total * 100 / 100 - value.score_goods.price * 100 / 100 * 1;
}
that.reducecartk(item.id)
} else {
uni.showToast({
title: '不能再减少了~',
icon: 'none'
})
}
}
})
that.data3 = that.data3;
} else if (item.type == 1) {
that.data2.forEach(function(value, index, array) {
if (value.id == item.id) {
if (value.number > 1) {
value.number = value.number - 1;
that.reducecartk(item.id);
if (item.sel == true) {
that.total = that.total * 100 / 100 - value.flour_goods.price * 100 / 100 * 1;
}
}else{
uni.showToast({
title: '不能再减少了~',
icon: 'none'
})
}
}
})
that.data2 = that.data2;
}
},
reducecartk(id) {
let that = this;
var url = 'car/update_car';
var params = {
type: 2,
car_id: id
}
console.log(params)
app.post(url, params).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err)
})
},
// 去结算
jiesuan(){
let that = this;
if(that.data.length==0){
uni.showToast({
title:'请选择商品',
icon:'none'
})
return false
}
var url = 'order/confirm_order';
console.log('获取的参数',that.data)
var params = {
data: JSON.stringify(that.data),
}
console.log(params)
app.post(url, params,"post").then((res) => {
console.log(res);
console.log(res.data.data)
uni.setStorageSync("goodinfo",res.data.data);
uni.navigateTo({
url:'/pages/nearshop/sureorder'
})
}).catch((err) => {
console.log(err)
})
},
},
}
</script>
<style>
@import url('../../base/nearshop');
@import url('../../base/homepage');
page {
background: #F8F6F9;
}
.cartlist {
/* padding-bottom: 120rpx; */
}
.spec{
color:#3D454C;
font-size: 28rpx;
}
.cartselimg {
width: 30rpx;
height: 30rpx;
font-size: 0;
margin-right: 30rpx;
flex: 0 0 auto;
}
.sureorderitem {
padding-bottom: 30rpx;
box-sizing: border-box;
}
.cartbottom {
width: 750rpx;
position: fixed;
bottom: 0;
left: 0;
padding: 38rpx 32rpx;
box-sizing: border-box;
background: #fff;
}
.totalnum {
color: #3D454C;
font-size: 28rpx;
/* margin-left:12rpx; */
}
.totalmoney {
color: #E26335;
font-size: 28rpx;
/* margin-left:12rpx; */
}
.jiesuan {
width: 280rpx;
height: 88rpx;
background: rgba(194, 148, 69, 1);
border-radius: 16rpx;
color: #fff;
font-size: 28rpx;
text-align: center;
line-height: 88rpx;
}
</style>