Blame view

src/pages/cart/cart.vue 15 KB
61d825263   BigBoss   确认订单修改
1
  <template>
29c972fd5   范牧   再次购买、确认订单修改
2
3
4
5
6
7
8
9
10
11
    <view :class="cartList.length === 0 ? 'content no_content' : 'content'">
      <block v-if="cartList.length ===0">
        <view class="nocard">
          <image
            src="../../static/nocart.jpeg"
            class="nocartPic"
            mode="aspectFill"
          ></image>
          <text class="nocartText">购物车竟然是空的,快去加购吧!</text>
        </view>
61d825263   BigBoss   确认订单修改
12
13
14
15
16
17
      </block>
      <block v-else>
        <view class="card">
          <view class="cardHeader">
            <view
              v-bind:class="pIsoPen? 'partentChecked' : 'partentCheck'"
2cd0b0f44   范牧   bug修复
18
              @click="pClick"
61d825263   BigBoss   确认订单修改
19
20
21
22
23
24
25
26
27
28
            >
              <span class="correct"></span>
            </view>
            <image
              src="../../static/store.png"
              mode="aspectFill"
            ></image>
            <text>非常戴镜</text>
          </view>
          <view
29c972fd5   范牧   再次购买、确认订单修改
29
            class="cardBody"
61d825263   BigBoss   确认订单修改
30
31
32
33
34
35
            v-for="(item,index) in cartList"
            :key="index"
            @longpress="delCart(item.cart_id,index)"
          >
            <view
              v-bind:class="cartList[index].isChecked? 'partentChecked':'partentCheck'"
2cd0b0f44   范牧   bug修复
36
              @click="childClick(cartList[index],index)"
61d825263   BigBoss   确认订单修改
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
            >
              <span class="correct"></span>
            </view>
            <view class="imageWrap">
              <image
                :src="item.img_index_url"
                mode="aspectFit"
                style="width: 188rpx;height: 168rpx;"
              ></image>
            </view>
            <view class="goodInfo">
              <!-- <view class="imageWrap">
                <image :src="item.img_index_url" mode="aspectFit" style="width: 188rpx;height: 168rpx;"></image>
              </view> -->
              <view class="infoRight">
                <view
                  class="goodName"
                  @tap="toGoods(item.pid,item.sk_id)"
                >{{item.p_name}}</view>
2cd0b0f44   范牧   bug修复
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
                <view
                  class="describ"
                  @click="showBottom(3,item.pid,item.sk_id,item.mp_id,item.cart_id,index)"
                >
                  <view class="desL">
                    <view class="people">
                      使用人:{{item.peopleName}}
                    </view>
                    <view class="skuInfo">
                      {{item.sku_name}}
                    </view>
                  </view>
                  <view class="desR">
                    <image
                      src="../../static/right.png"
                      mode="aspectFit"
                      style="width: 18rpx;height: 18rpx;"
                    ></image>
                  </view>
61d825263   BigBoss   确认订单修改
75
76
                </view>
                <view class="priceBox">
7301fd560   BigBoss   添加购物车默认样式
77
                  <view class="price">¥{{item.nowPrice}}</view>
61d825263   BigBoss   确认订单修改
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
                  <text class="maxCount">(限购{{maxCount}}副)</text>
                  <view class="counter">
                    <view
                      class="btn"
                      disabled="this.addDisabled"
                      type="default"
                      @tap="counter(index,false,item)"
                    >-</view>
                    <text>{{item.num}}</text>
                    <view
                      class="btn"
                      disabled="this.desDisabled"
                      type="default"
                      @tap="counter(index,true,item)"
                    >+</view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </block>
29c972fd5   范牧   再次购买、确认订单修改
100
101
102
103
      <view
        v-if="cartList.length !==0 "
        class="footer"
      >
61d825263   BigBoss   确认订单修改
104
105
        <view class="footerLeft">实付金额:<text>¥{{totalPrice}}</text></view>
        <view class="footerRight">
2cd0b0f44   范牧   bug修复
106
107
108
109
          <view
            class="paybtn"
            @click="toComfirmOrder"
          >立即结算</view>
61d825263   BigBoss   确认订单修改
110
111
        </view>
      </view>
2cd0b0f44   范牧   bug修复
112
113
114
115
116
117
118
119
120
121
122
123
124
125
      <BottomSheet
        v-if="isShowBottom"
        :isCart="isCart"
        @addCart="addCart"
        :sk_id="sk_id"
        :propMpId="mp_id"
        @chooseCartModi="chooseCartModi"
        :cart_id="cart_id"
        :index="cartIndex"
        :pid="pid"
        :goodInfo="goodInfo"
        :isShowBottom="isShowBottom"
        @closeBottom="closeBottom"
      ></BottomSheet>
61d825263   BigBoss   确认订单修改
126
127
128
129
130
131
    </view>
  </template>
  
  <script>
  
  import store from '@/store'
2cd0b0f44   范牧   bug修复
132
133
134
135
136
  import BottomSheet from '../../components/BottomSheet/BottomSheet.vue'
  export default {
    components: {
      BottomSheet,
    },
61d825263   BigBoss   确认订单修改
137
138
    data() {
      return {
2cd0b0f44   范牧   bug修复
139
140
141
142
        pid: Number,
        isCart: Number,
        sk_id: String,
        mp_id: String,
678d6b48a   范牧   async函数修改
143
        isShowBottom: false, // 底部弹窗开关
2cd0b0f44   范牧   bug修复
144
145
146
147
        cart_id: Number,
        maxCount: 20,
        cartIndex: Number,
        cartList: [],
61d825263   BigBoss   确认订单修改
148
149
150
      }
    },
    computed: {
2cd0b0f44   范牧   bug修复
151
152
153
154
155
156
157
      pIsoPen () {
        if (this.cartList.length > 0) {
          return !this.cartList.find(item => !item.isChecked)
        }
        return false
      },
      goodInfo () {
678d6b48a   范牧   async函数修改
158
        return this.$store.state.read.goodInfo
2cd0b0f44   范牧   bug修复
159
160
161
162
      },
      totalPrice() {
        let totalPrice = 0
        this.cartList.forEach((item) => {
678d6b48a   范牧   async函数修改
163
          if (item.isChecked) {
2cd0b0f44   范牧   bug修复
164
            totalPrice += item.nowPrice * item.num
678d6b48a   范牧   async函数修改
165
          }
2cd0b0f44   范牧   bug修复
166
167
168
169
        })
        return totalPrice
      },
    },
678d6b48a   范牧   async函数修改
170
    onShow: async function() {
61d825263   BigBoss   确认订单修改
171
172
      await this.$store.dispatch('cart/getCartList', {
        uid: this.$store.state.user.userInfo.uid, // 用户id
1dbb125ac   吉鹏   购物车bug修改重构
173
      })
2cd0b0f44   范牧   bug修复
174
175
176
  
      this.cartList = this.$store.state.cart.cartList
      this.cartList.forEach((item) => {
678d6b48a   范牧   async函数修改
177
        item.isChecked = false
2cd0b0f44   范牧   bug修复
178
      })
61d825263   BigBoss   确认订单修改
179
    },
1a4cad719   BigBoss   修改待付款支付跳转逻辑&新增已完成...
180
181
    // onLoad: async function() {
    // },
61d825263   BigBoss   确认订单修改
182
    methods: {
678d6b48a   范牧   async函数修改
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
      // 全选按钮
      pClick() {
        const pStatus = !this.cartList.find(item => !item.isChecked)
        const oldList = this.cartList
        oldList.forEach((item, index) => {
          item.isChecked = !pStatus
          this.cartList.splice(index, 1, item)
        })
      },
      // 单选按钮
      childClick(type, index) {
        this.cartList[index].isChecked = !this.cartList[index].isChecked
        // vue没有办法监听数组内部值的变化,所以需要通过这个方法去触发
        this.cartList.splice(index, 1, this.cartList[index])
      },
      // 修改购物车
      chooseCartModi(mp_id, sk_id, price, pid, num, cart_id, index) {
        // console.log('modi',mp_id,sk_id,price,pid,num,cart_id)
        store.dispatch('cart/modiCart', {
          uid: this.$store.state.user.userInfo.uid,
          openid: this.$store.state.user.userInfo.openid,
          mp_id: mp_id,
          sk_id: sk_id,
          price: price,
          pid: pid,
          num: num,
          cart_id: cart_id,
2cd0b0f44   范牧   bug修复
210
          args: {
678d6b48a   范牧   async函数修改
211
            index: index,
2cd0b0f44   范牧   bug修复
212
          },
678d6b48a   范牧   async函数修改
213
214
215
216
217
        })
        this.$nextTick(function() {
          store.dispatch('cart/getCartList', {
            uid: this.$store.state.user.userInfo.uid, // 用户id
          }).then(() => {
2cd0b0f44   范牧   bug修复
218
219
            this.cartList = this.$store.state.cart.cartList
          })
678d6b48a   范牧   async函数修改
220
221
222
223
224
        })
      },
      // 底部弹窗开关
      showBottom(isCart, pid, skId, mp_id, cart_id, index) {
        store.dispatch('read/fetch', {
2cd0b0f44   范牧   bug修复
225
226
          pid,
          sk_id: skId,
678d6b48a   范牧   async函数修改
227
228
229
230
231
232
233
234
235
236
237
238
239
        }).then(() => {
          this.cartIndex = index
          this.sk_id = skId
          this.pid = pid
          this.mp_id = mp_id
          this.isCart = isCart
          this.cart_id = cart_id
          this.isShowBottom = true
        })
      },
      closeBottom() {
        this.isShowBottom = false
      },
2cd0b0f44   范牧   bug修复
240
      toGoods(id, skId) {
61d825263   BigBoss   确认订单修改
241
        uni.navigateTo({
2cd0b0f44   范牧   bug修复
242
          url: '../details/details?pid=' + id + '&sk_id=' + skId,
61d825263   BigBoss   确认订单修改
243
244
245
246
247
          success: res => {},
          fail: () => {},
          complete: () => {},
        })
      },
c4494f932   BigBoss   修改冲突
248

2cd0b0f44   范牧   bug修复
249
250
251
252
253
254
255
256
257
258
259
260
261
      toComfirmOrder() {
        this.$store.state.cart.checkedCartLst = this.cartList.filter(item => item.isChecked)
        if (this.$store.state.cart.checkedCartLst.length > 0) {
          uni.navigateTo({
            url: '../confirmOrder/confirmOrder?isCart=true',
          })
        } else {
          uni.showToast({
            title: '您还没有选择宝贝哦~',
            icon: 'none',
          })
        }
      },
61d825263   BigBoss   确认订单修改
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
      counter(index, isadd, item) {
        // console.log('item=====>', item)
        // console.log('num=====>', item.num)
        const nums = parseInt(item.num)
        if (isadd) {
          if (nums >= this.maxCount) {
            this.addDisabled = true
          } else {
            this.addDisabled = true
            store.dispatch('cart/modiCart', {
              uid: this.$store.state.user.userInfo.uid,
              openid: this.$store.state.user.userInfo.openid,
              mp_id: item.mp_id,
              sk_id: item.sk_id,
              price: item.nowPrice,
              pid: item.pid,
              num: nums + 1,
              cart_id: item.cart_id,
              args: {
                index: index,
                isadd: isadd,
              },
            })
            this.addDisabled = false
          }
        } else {
          if (nums <= 1) {
            this.desDisabled = true
          } else {
            this.desDisabled = false
2cd0b0f44   范牧   bug修复
292

61d825263   BigBoss   确认订单修改
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
            store.dispatch('cart/modiCart', {
              uid: this.$store.state.user.userInfo.uid,
              openid: this.$store.state.user.userInfo.openid,
              mp_id: item.mp_id,
              sk_id: item.sk_id,
              price: item.nowPrice,
              pid: item.pid,
              num: nums - 1,
              cart_id: item.cart_id,
              args: {
                index: index,
                isadd: isadd,
              },
            })
            this.desDisabled = true
          }
        }
61d825263   BigBoss   确认订单修改
310
311
312
      },
      delCart(cart_id, index) {
        cart_id = parseInt(cart_id)
678d6b48a   范牧   async函数修改
313
314
315
316
317
318
319
320
321
322
323
324
325
326
        uni.showModal({
          title: '是否删除该商品',
          success: function (res) {
            if (res.confirm) {
              store.dispatch('cart/delCart', {
                uid: this.$store.state.user.userInfo.uid,
                openid: this.$store.state.user.userInfo.openid,
                cart_id: cart_id, // 要修改的购物车id
                arg: index, // 由于action 传参是能接收两参数,因此将index放入对象
              })
            }
          }.bind(this),
        })
      // this.cartList.splice(index,1)
61d825263   BigBoss   确认订单修改
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
      },
    },
  }
  </script>
  
  <style lang="scss">
  .content {
    min-height: 100vh;
    background-color: #f2f2f2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 20rpx 40rpx;
    box-sizing: border-box;
29c972fd5   范牧   再次购买、确认订单修改
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
    .nocard {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      .nocartPic {
        width: 320rpx;
        height: 300rpx;
        margin: 40rpx 0;
      }
      .nocartText {
        color: #999;
        font-size: 28rpx;
      }
    }
61d825263   BigBoss   确认订单修改
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
    .partentCheck {
      width: 16px;
      height: 16px;
      border-radius: 22px;
      border: 1px solid #cfcfcf;
      background-color: #ffffff;
      margin: 24rpx 12rpx 24rpx 24rpx;
    }
    .partentChecked {
      width: 18px;
      height: 18px;
      border-radius: 22px;
      background-color: #ff6b4a;
      margin: 24rpx 12rpx 24rpx 24rpx;
      .correct {
        display: inline-block;
        position: relative;
        width: 10rpx;
        height: 2rpx;
        background: #ffffff;
        line-height: 0;
        font-size: 0;
        position: relative;
        top: -7px;
        left: 4px;
        -webkit-transform: rotate(45deg);
      }
      .correct:after {
        content: "/";
        display: block;
        width: 16rpx;
        height: 2rpx;
        background: #ffffff;
        -webkit-transform: rotate(-90deg) translateY(50%) translateX(50%);
      }
    }
  
    .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;
      margin-bottom: 180rpx;
      .cardHeader {
        width: 100%;
        height: 36rpx;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        margin-bottom: 20rpx;
        image {
          height: 32rpx;
          width: 32rpx;
          padding-left: 6px;
          padding-right: 10px;
        }
        text {
          // font-family: PingFangSC-Regular;
          font-size: 14px;
          color: #333333;
          letter-spacing: -0.26px;
        }
      }
      .cardBody {
        width: 100%;
        min-height: 300rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .goodInfo {
          width: 390rpx;
          display: flex;
          flex-direction: row;
          justify-content: flex-start;
          padding-left: 6px;
  
          .imageWrap {
            height: 188rpx;
            width: 188rpx;
            margin-right: 28rpx;
  
            image {
              border-radius: 4px;
              height: 188rpx;
              width: 188rpx;
            }
          }
          .infoRight {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: space-between;
            min-height: 240rpx;
2cd0b0f44   范牧   bug修复
455
            width: 100%;
61d825263   BigBoss   确认订单修改
456
457
458
459
460
461
462
463
464
465
466
467
            .goodName {
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              text-align: justify;
              overflow: hidden;
              font-size: 28rpx;
              color: #333333;
            }
            .describ {
              width: 100%;
              min-height: 80rpx;
2cd0b0f44   范牧   bug修复
468
469
              background: #f9f9f9;
              border-radius: 2px;
61d825263   BigBoss   确认订单修改
470
471
472
473
474
              box-sizing: border-box;
              padding: 10rpx;
              font-size: 20rpx;
              letter-spacing: -0.23px;
              color: #999999;
2cd0b0f44   范牧   bug修复
475
476
477
478
479
480
481
482
              display: flex;
              justify-content: space-between;
              align-items: center;
              .desL {
                view {
                  margin: 10rpx 0 10rpx 0;
                }
              }
61d825263   BigBoss   确认订单修改
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
            }
            .priceBox {
              display: flex;
              justify-content: space-between;
              align-items: center;
              // margin-top: 26px;
              width: 100%;
              font-size: 14px;
              color: #999999;
              .maxCount {
                color: #999999;
                font-size: 20rpx;
              }
              .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;
      bottom: 0px;
      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;
        }
      }
    }
  }
29c972fd5   范牧   再次购买、确认订单修改
564
565
566
  .no_content {
    background-color: #fff;
  }
61d825263   BigBoss   确认订单修改
567
  /* 隐藏滚动条 */
2cd0b0f44   范牧   bug修复
568
569
570
571
572
573
  ::-webkit-scrollbar {
    width: 0;
    height: 0;
    color: transparent;
  }
  </style>