quanwei
13 hours ago 408c463c5b66bba2aa1c81d8dca23e04c1608e24
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
507
508
509
510
511
512
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
547
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
<template>
    <view :data-theme='theme()' :class="theme() || ''">
        <!-- #ifdef APP-PLUS -->
        <header-bar></header-bar>
        <!-- #endif -->
        <view class="card" v-if="!loadding">
            <view :class="{ pb100: tableData.length > 0 }" style="position: relative;">
                <!--产品列表-->
                <template v-if="tableData.length > 0">
                    <view class="address-bar d-e-c">
                        <view class="f30" @tap="isEdit = !isEdit">
                            <button class="f24" v-if="isEdit">完成</button>
                            <button class="f24" v-else>编辑</button>
                        </view>
                    </view>
                    <view class="section">
                        <view v-for="(supplier_item, supplier_index) in tableData" :key="supplier_index">
                            <view class="supplier_list">
                                <view class="supplier_list_tit">
                                    <label class="d-c-c" @tap="checkStprItem(supplier_item, supplier_index)">
                                        <checkbox color="red" value="cb" class="checkbox"
                                            :checked="supplier_item.checked" />
                                    </label>
                                    <view class="d-a-c" @tap="gotoShopPage(supplier_item.supplier.shop_supplier_id)">
                                        <i class="icon iconfont icon-dianpu1"></i>
                                        <text class="f32 gray3">{{supplier_item.supplier.name}}</text>
                                    </view>
                                </view>
                                <view class="item" v-for="(item, index) in supplier_item.productList" :key="index">
                                    <label class="d-c-c" @tap.stop="checkItem(item, supplier_index, index)">
                                        <checkbox color="red" value="cb" class="checkbox" :checked="item.checked" />
                                    </label>
                                    <view style="overflow: hidden;">
                                        <image
                                            @click="gotoPage('/pages/product/detail/detail?product_id='+item.product_id)"
                                            :src="item.product_image" class="cover" mode="aspectFit"></image>
                                    </view>
                                    <view class="info">
                                        <view class="title">{{ item.product_name }}</view>
                                        <view class="describe">{{ item.product_sku.product_attr }}</view>
                                        <view class="level-box count_choose">
                                            <view class="price">
                                                ¥
                                                <text class="num">{{ item.product_price }}</text>
                                                <view v-if="item.service_name">{{ item.service_name }}:¥
                                                    {{ item.service_price }}</view>
                                            </view>
                                            <view class="num-wrap">
                                                <view class="" @tap.stop="reduceFunc(item)" v-if="item.total_num > 1">
                                                    <image class="reduce_icon" src="/static/icon/reduce.png" mode="">
                                                    </image>
                                                </view>
                                                <view class="text-wrap">{{item.total_num}}</view>
                                                <view class="" @tap.stop="addFunc(item)"
                                                    v-if="item.total_num < item.product_sku.stock_num ">
                                                    <image class="add_icon" src="/static/icon/add.png" mode="">
                                                    </image>
                                                </view>
                                            </view>
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </template>
                <template v-else>
                    <view class="none-data-box cart_none">
                        <image class="cart_none_img" src="/static/cart_none.png" mode="widthFix"></image>
                        <text class="f26 gray9 pt10">购物车空空如也</text>
                        <button type="default" class="theme-btn mt30 ww100 none_btn" @tap="gotoShop">去购物</button>
                    </view>
                </template>
 
                <!--底部按钮-->
                <view class="bottom-btns f28" :class="is_auto?'is_auto':''" v-if="tableData.length > 0">
                    <label class="d-c-c mr20" @tap="onCheckedAll()">
                        <!--<checkbox color="red" class="checkbox" :checked="checkedAll" value="cb" />
                        全选-->
                    </label>
                    <view class="d-e-c pr20" v-if="!isEdit">
                        <view class="total d-s-c flex-1 mr20">
                            <text class="f24 gray9">合计:</text>
                            <view class="price f24">
                                ¥
                                <text class="num f32">{{ totalPrice }}</text>
                            </view>
                        </view>
                        <button type="primary" class="buy-btn theme-btn" @tap="Submit()">去结算</button>
                    </view>
                    <view class="pr20" v-else><button type="primary" @tap="onDelete()"
                            class="delete-btn theme-btn mr20">删除</button></view>
                </view>
 
                <!--推荐-->
                <recommendProduct :location="10" :city_supplier_ids="city_supplier_ids"></recommendProduct>
            </view>
        </view>
        <request-loading :loadding='isloadding'></request-loading>
        <tabBar></tabBar>
    </view>
</template>
 
<script>
    import recommendProduct from '@/components/recommendProduct/recommendProduct.vue';
    export default {
        components: {
            recommendProduct
        },
        data() {
            return {
                isloadding: true,
                /*滚动组件高度*/
                scrollviewHigh: 0,
                /*是否加载完成*/
                loadding: true,
                isEdit: false,
                /*购物车各商铺商品*/
                tableData: [],
                arrIds: [],
                // 是否全选
                checkedAll: false,
                totalPrice: 0,
                totalProduct: 0,
                store_open: 1,
                is_auto: 0,
                activity_id: 0,
                longitude: '',
                latitude: '',
            };
        },
        onLoad(e) {
            this.activity_id = e.activity_id;
            if (!Object.hasOwn(e, 'activity_id')) {
                uni.navigateBack();
            }
            this.longitude = uni.getStorageSync('userLongitude');
            this.latitude = uni.getStorageSync('userLatitude');
        },
        onShow() {
            /*获取产品详情*/
            this.getData();
            // this.getTabBarLinks();
            if (uni.getStorageSync('citySupplierRes')) {
                let resData = uni.getStorageSync('citySupplierRes');
                this.city_supplier_ids = resData.supplier_ids;
            }
        },
        mounted() {
            this.init();
        },
        methods: {
            /*初始化*/
            init() {
                let _this = this;
                uni.getSystemInfo({
                    success(res) {
                        let ratio = res.windowWidth / 750;
                        let h = res.windowHeight - ratio * 98;
                        _this.scrollviewHigh = h;
                    }
                });
            },
 
            /*获取数据*/
            getData() {
                let self = this;
                self.isloadding = true;
                self._get('branch.activityCart/lists', {
                    longitude: self.longitude,
                    latitude: self.latitude,
                    activity_id: self.activity_id
                }, function(res) {
                    let auto = uni.getStorageSync('TabBar').is_auto && uni.getStorageSync('TabBar').is_auto != 0;
                    self.is_auto = auto;
                    self.isloadding = false;
                    self.tableData = res.data.productList;
                    //#ifdef MP-WEIXIN
                    self.store_open = res.data.store_open;
                    //#endif
                    self.tableData.forEach((item, index) => {
                        item.checked = false;
                    })
                    self.loadding = false;
                    self._initGoodsChecked();
                });
            },
            /**
             * 初始化商品选中状态
             */
            _initGoodsChecked() {
                let self = this;
                let checkedData = self.getCheckedData();
                // 将商品设置选中
                let productCount = 0;
                self.tableData.forEach(item => {
                    item.productList.forEach(product => {
                        productCount++;
                        product.checked = self.inArray(`${product.cart_id}`,
                            checkedData);
                    });
                });
                self.totalProduct = productCount;
                self.isEdit = false;
                self.checkedAll = checkedData.length == self.totalProduct;
                self.tableData.forEach((item, index) => {
                    this.onUpsupChecked(this.tableData, index)
                })
                // 更新购物车已选商品总价格
                self.updateTotalPrice();
            },
 
            /**
             * 获取选中的商品
             */
            getCheckedData() {
                let checkedData = uni.getStorageSync('checkedData');
                return checkedData ? checkedData : [];
            },
 
            /*单选*/
            checkItem(e, supplier_index, index) {
                //先把其他商户的去掉 by yj 2024.3.11
                let self = this;
                self.tableData.forEach(item => {
                    if (item.shop_supplier_id != this.tableData[supplier_index].shop_supplier_id) {
                        this.$set(item, 'checked', false);
                        item.productList.forEach(product => {
                            product.checked = false;
                        });
                    }
 
                });
 
                e.checked = !e.checked;
                this.$set(this.tableData[supplier_index].productList, index, e);
                console.log(this.tableData)
                // 更新店铺全选状态
                this.onUpsupChecked(this.tableData, supplier_index);
                // 更新选中记录
                this.onUpdateChecked();
                // 更新购物车已选商品总价格
                this.updateTotalPrice();
                // 更新全选状态
                console.log(this.getCheckedData().length);
                this.checkedAll = this.getCheckedData().length == this.totalProduct;
            },
            // 更新店铺全选状态
            onUpsupChecked(item, index) {
                let supplier_flag = true;
                for (var i = 0; i < item[index].productList.length; i++) {
                    if (!item[index].productList[i].checked) {
                        supplier_flag = false;
                    }
                }
                this.$set(item[index], 'checked', supplier_flag);
                console.log("item=====" + supplier_flag);
            },
            /**
             * 更新商品选中记录
             */
            onUpdateChecked() {
                let self = this,
                    checkedData = [];
                self.tableData.forEach(item => {
                    item.productList.forEach(product => {
                        if (product.checked == true) {
                            checkedData.push(`${product.cart_id}`);
                        }
                    });
                });
                console.log(checkedData)
                uni.setStorageSync('CheckedData', checkedData);
            },
            /* 店铺全选 */
            checkStprItem(itemp, index) {
                let self = this;
 
                //先把其他商户的去掉 by yj 2024.3.11
                self.tableData.forEach(item => {
                    this.$set(item, 'checked', false);
                    item.productList.forEach(product => {
                        product.checked = false;
                    });
                });
 
                //console.log(itemp)
                itemp.checked = !itemp.checked;
                itemp.productList.forEach((item, index) => {
                    item.checked = itemp.checked;
                })
 
                self.updateTotalPrice();
                // 更新选中记录
                self.onUpdateChecked();
                // 更新全选状态
                this.checkedAll = this.getCheckedData().length == this.totalProduct;
            },
            gotoShopPage(shop_supplier_id) {
                uni.setStorageSync('shop_supplier_id', shop_supplier_id)
                this.gotoPage('/pages/shop/shop?shop_supplier_id=' + shop_supplier_id)
            },
            /*全选*/
            onCheckedAll() {
                let self = this;
                self.checkedAll = !self.checkedAll;
                self.tableData.forEach(item => {
                    this.$set(item, 'checked', self.checkedAll);
                    item.productList.forEach(product => {
                        product.checked = self.checkedAll;
                    });
                });
                self.updateTotalPrice();
                // 更新选中记录
                self.onUpdateChecked();
            },
            updateTotalPrice: function() {
                let total_price = 0;
                let items = this.tableData;
                for (let i = 0; i < items.length; i++) {
                    for (let j = 0; j < items[i].productList.length; j++) {
                        if (items[i].productList[j]['checked'] == true) {
                            total_price += items[i].productList[j]['total_num'] * items[i].productList[j][
                                'product_price'
                            ];
                        }
                    }
                }
                /*保留2位小数*/
                this.totalPrice = total_price.toFixed(2);
            },
            /*去结算*/
            Submit() {
                const self = this;
                let arrIds = self.getCheckedIds();
                if (arrIds.length == 0) {
                    uni.showToast({
                        title: '请选择商品',
                        icon: 'none'
                    });
                    return false;
                }
                this.gotoPage('/pages/order/confirm-order?&branch_activity_id=' + self.activity_id +
                    '&order_type=cart&cart_ids=' + arrIds);
            },
            /*添加*/
            addFunc(item) {
                let self = this;
                let product_id = item.product_id;
                let spec_sku_id = item.spec_sku_id;
                let service_index = item.service_index;
                uni.showLoading({
                    title: '加载中'
                });
                self._post(
                    'branch.activityCart/add', {
                        product_id: product_id,
                        spec_sku_id: spec_sku_id,
                        activity_id: self.activity_id,
                        total_num: 1,
                        longitude: self.longitude,
                        latitude: self.latitude
                    },
                    function(res) {
                        uni.hideLoading()
                        self.loadding = false;
                        self.getData();
                    },
                    function() {
                        self.loadding = false;
                    }
                );
            },
            /*减少*/
            reduceFunc(item) {
                let self = this;
 
                let product_id = item.product_id;
                let spec_sku_id = item.spec_sku_id;
                let service_index = item.service_index;
                if (item.total_num <= 1) {
                    return;
                }
                //最低起卖个数
                if (item.min_sell >= item.total_num) {
                    return;
                }
                uni.showLoading({
                    title: '加载中'
                });
                self._post(
                    'branch.activityCart/sub', {
                        activity_id: self.activity_id,
                        product_id: product_id,
                        spec_sku_id: spec_sku_id,
                        longitude: self.longitude,
                        latitude: self.latitude
                    },
                    function(res) {
                        self.loadding = false;
                        uni.hideLoading()
                        self.getData();
                    },
                    function() {
                        self.loadding = false;
                    }
                );
            },
            /*删除购物车*/
            onDelete() {
                let self = this;
                let cartIds = self.getCheckedIds();
                if (!cartIds.length) {
                    self.showError('您还没有选择商品');
                    return false;
                }
                uni.showModal({
                    title: '提示',
                    content: '您确定要移除选择的商品吗?',
                    success(e) {
                        e.confirm &&
                            self._post(
                                'branch.activityCart/delete', {
                                    cart_id: cartIds,
                                    activity_id: self.activity_id,
                                    longitude: self.longitude,
                                    latitude: self.latitude
                                },
                                function(res) {
                                    // 删除选中的商品
                                    self.getData();
                                    self.onDeleteEvent(cartIds);
                                }
                            );
                    }
                });
            },
            /**
             * 获取已选中的商品
             */
            getCheckedIds() {
                let self = this;
                let arrIds = [];
                self.tableData.forEach(item => {
                    item.productList.forEach(product => {
                        if (product.checked == true) {
                            arrIds.push(`${product.cart_id}`);
                        }
                    });
                });
                return arrIds;
            },
 
            /**
             * 商品删除事件
             */
            onDeleteEvent(cartIds) {
                let self = this;
                cartIds.forEach(cartIndex => {
                    self.tableData.forEach((item, productIndex) => {
                        if (cartIndex == `${item.cart_id}`) {
                            self.tableData.splice(productIndex, 1);
                        }
                    });
                });
                self.$nextTick(() => {
                    // 更新选中记录
                    self.onUpdateChecked();
                })
 
                return true;
            },
            /**
             * 是否在数组内
             */
            inArray(search, array) {
                for (var i in array) {
                    if (array[i] == search) {
                        return true;
                    }
                }
                return false;
            },
 
            /*去购物*/
            gotoShop() {
                // let url = '/pages/branch/activity/product/index?activity_id='+ this.activity_id;
                // this.gotoPage(url, 'redirect');
                uni.navigateBack(-1);
            }
        }
    };
</script>
 
<style lang="scss" scoped>
    page {
        background-color: #f2f2f2;
    }
 
    .foot_ {
        height: 98rpx;
        width: 100%;
    }
 
    .card .scroll-Y {
        position: relative;
    }
 
    .card .checkbox {
        @include font_color("font_color");
        transform: scale(0.7);
    }
 
    .address-bar {
        // padding: 20rpx;
        // background-color: #f2f2f2;
    }
 
    .address-bar button {
        border: none;
        background: none;
        color: #333333;
    }
 
    .section {
        // background: #f2f2f2;
        padding: 20rpx;
        padding-top: 0;
    }
 
    .section .item {
        margin: 0 26rpx;
        display: flex;
        align-items: center;
        // border: 1px solid #f2f2f2;
        padding-right: 19rpx;
        padding-bottom: 29rpx;
        padding-top: 29rpx;
    }
 
    .section .cover {
        width: 150rpx;
        height: 150rpx;
        border-radius: 8px;
    }
 
    .section .info {
        flex: 1;
        padding-left: 30rpx;
        box-sizing: border-box;
        overflow: hidden;
    }
 
    .section .title {
        width: 100%;
        font-size: 26rpx;
        display: -webkit-box;
        overflow: hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
 
    .vender .list .describe {
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
 
    .section .describe {
        margin-top: 20rpx;
        font-size: 24rpx;
        color: #999999;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
    }
 
    .section .price {
        @include font_color("font_color");
        font-size: 24rpx;
    }
 
    .section .price .num {
        padding: 0 4rpx;
        font-size: 32rpx;
    }
 
    .section .level-box {
        margin-top: 20rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
 
    .section .level-box .key {
        font-size: 24rpx;
        color: #999999;
    }
 
    .section .level-box .num-wrap {
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
 
    .section .level-box .icon-box {
        width: 33rpx;
        height: 33rpx;
        border: 1px solid #c5c5c5;
        background: #f2f2f2;
    }
 
    .section .level-box .icon-box .gray {
        color: #cccccc;
    }
 
    .section .level-box .icon-box .gray3 {
        color: #333333;
    }
 
    .section .level-box .text-wrap {
        margin: 0 20rpx;
        height: 33rpx;
        border: none;
        background: none;
    }
 
    .section .level-box .text-wrap input {
        padding: 0 4rpx;
        height: 33rpx;
        line-height: 1;
        width: 40rpx;
        font-size: 32rpx;
        text-align: center;
        display: flex;
        align-items: center;
        min-height: 33rpx;
    }
 
    .bottom-btns {
        position: fixed;
        width: 100%;
        padding: 0 0 0 20rpx;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 90rpx;
        // /* bottom: calc(var(--window-bottom); */
        // bottom: var(--window-bottom, 0);
        bottom: var(--window-bottom, 0);
        // bottom: 50px;
        left: 0;
        box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.1);
        background: #ffffff;
        z-index: 1000;
    }
 
    // .bottom-btns.is_auto {
    //     bottom: calc(env(safe-area-inset-bottom) + 98rpx);
    // }
    .bottom-btns .delete-btn {
        margin: 0;
        padding: 0 30rpx;
        height: 60rpx;
        line-height: 60rpx;
        border-radius: 30rpx;
        font-size: 26rpx;
    }
 
    .bottom-btns .buy-btn {
        margin: 0;
        padding: 0 24rpx;
        height: 60rpx;
        line-height: 60rpx;
        border-radius: 30rpx;
        font-size: 26rpx;
    }
 
    .bottom-btns .price {
        @include font_color("price_color");
    }
 
    .supplier_list {
        overflow: hidden;
        background-color: #FFFFFF;
        border-radius: 24rpx;
        margin-bottom: 30rpx;
    }
 
    .supplier_list_tit {
        display: flex;
        align-items: center;
        margin-left: 28rpx;
        margin-top: 28rpx;
    }
 
    .icon-dianpu1 {
        font-size: 34rpx;
        color: #333333;
        margin: 0 17rpx;
    }
 
    .cart_none .cart_none_img {
        width: 348rpx;
        height: 222rpx;
    }
 
    .none_btn {
        font-size: 32rpx;
        border-radius: 40rpx;
    }
 
    .add_icon,
    .reduce_icon {
        width: 32rpx;
        height: 32rpx;
    }
</style>