Blame view

src/pages/cart/cart.vue 17.3 KB
0db291810   BigBoss   “-mcomfirmOder页面
1
  <template>
a3d2beaa8   范牧   立即支付功能
2
3
    <view class="content">
      <block v-if="cartList.length==0">
7a7226fea   范牧   冲突合并
4
  
a3d2beaa8   范牧   立即支付功能
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
      </block>
      <block v-else>
        <view class="card">
          <view class="cardHeader">
            <view
              v-bind:class="pIsoPen? 'partentChecked' : 'partentCheck'"
              @tap="pChange(pIsoPen)"
            >
              <span class="correct"></span>
            </view>
            <image
              src="../../static/store.png"
              mode="aspectFill"
            ></image>
            <text>非常戴镜</text>
          </view>
7a7226fea   范牧   冲突合并
21
  
a3d2beaa8   范牧   立即支付功能
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
          <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'"
              @tap="Change(childIsOpen[index],index)"
            >
              <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">
cc196c33c   喻鹏   购物车和用户推荐接口渲染
43
  							<image :src="item.img_index_url" mode="aspectFit" style="width: 188rpx;height: 168rpx;"></image>
66638e4bb   喻鹏   购物车样式和新增验光单样式修改
44
  						</view> -->
a3d2beaa8   范牧   立即支付功能
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
              <view class="infoRight">
                <view
                  class="goodName"
                  @tap="toGoods(item.pid,item.sk_id)"
                >{{item.p_name}}</view>
                <!-- <view class="describ"> -->
                <uni-collapse accordion="true">
                  <uni-collapse-item
                    showAnimation='true'
                    :title="item.tag.prod_tag_fun[0].label+'/'+item.tag.prod_tag_fun[1].label+'/'+item.tag.prod_tag_fun[2].label+'...' || '暂无'"
                  >
                    <text class="describ">
                      <block
                        v-for="tag in item.tag.prod_tag_fun"
                        :key="tag.value"
                      >
                        {{tag.label+`&nbsp;&nbsp;`}}
                      </block>
                    </text>
                    <!-- 										<text>
66638e4bb   喻鹏   购物车样式和新增验光单样式修改
65
66
67
68
  											<block v-for="tag in item.tag.prod_tag_style" :key="tag.value">
  												{{tag.label+`&nbsp;&nbsp;`}}
  											</block>
  										</text> -->
a3d2beaa8   范牧   立即支付功能
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
                  </uni-collapse-item>
                </uni-collapse>
                <!-- <view v-bind:class="collapseList[index]? 'icon':'iconed'"></view> -->
                <!-- </view> -->
                <view class="priceBox">
                  <view class="price">¥{{item.nowPrice*item.num}}</view>
                  <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>
      <view class="footer">
        <view class="footerLeft">实付金额:<text>¥{{totalPrice}}</text></view>
        <view class="footerRight">
          <navigator
            url="/pages/confirmOrder/confirmOrder"
            hover-class="navigator-hover"
          >
            <view class="paybtn">立即结算</view>
          </navigator>
        </view>
      </view>
7a7226fea   范牧   冲突合并
108
  
a3d2beaa8   范牧   立即支付功能
109
    </view>
0db291810   BigBoss   “-mcomfirmOder页面
110
111
112
  </template>
  
  <script>
7a7226fea   范牧   冲突合并
113
114
115
  import UniCollapse from '@/components/UniCollapse/UniCollapse.vue'
  import UniCollapseItem from '@/components/UniCollapseItem/UniCollapseItem.vue'
  import store from '@/store'
ab4209caf   喻鹏   update
116
  
7a7226fea   范牧   冲突合并
117
118
119
120
121
122
123
  export default {
    components: { UniCollapse, UniCollapseItem },
    data() {
      return {
        totalPrice: 0,
        pIsoPen: false,
        // childIsOpen:[],
a3d2beaa8   范牧   立即支付功能
124
        maxCount: 20,
7a7226fea   范牧   冲突合并
125
126
127
      }
    },
    computed: {
cc196c33c   喻鹏   购物车和用户推荐接口渲染
128
  
7a7226fea   范牧   冲突合并
129
      cartList() {
b9fb65756   喻鹏   购物车和推荐产品根据sk_id来对应价格
130
        // console.log('cart-list', this.$store.state.cart.cartList);
637a02b07   尹聃   添加购物车
131
        return this.$store.state.cart.cartList
7a7226fea   范牧   冲突合并
132
133
134
135
136
137
138
139
140
      },
      childIsOpen() {
        const 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
a3d2beaa8   范牧   立即支付功能
141
      },
7a7226fea   范牧   冲突合并
142
143
    },
    onLoad: function() {
637a02b07   尹聃   添加购物车
144
145
  	  //  store.dispatch('cart/addCart', {
  	  //    uid: this.$store.state.user.userInfo.uid,
a3d2beaa8   范牧   立即支付功能
146
147
148
149
150
151
152
      // openid: this.$store.state.user.userInfo.openid,
      // mp_id: 7,
      // sk_id: 7,
      // num: 1,
      // pid: 8,
      // price: 128,
      // checkedSKU:{},
637a02b07   尹聃   添加购物车
153
  	 	//  })
7a7226fea   范牧   冲突合并
154
      store.dispatch('cart/getCartList', {
a3d2beaa8   范牧   立即支付功能
155
        uid: this.$store.state.user.userInfo.uid, // 用户id
7a7226fea   范牧   冲突合并
156
157
      })
    },
cc196c33c   喻鹏   购物车和用户推荐接口渲染
158
  
7a7226fea   范牧   冲突合并
159
    methods: {
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
160
  
b9fb65756   喻鹏   购物车和推荐产品根据sk_id来对应价格
161
      toGoods(id, sk_id) {
a3d2beaa8   范牧   立即支付功能
162
163
  	  console.log('cart-list', this.$store.state.cart.cartList)
  	  console.log('---', '../frameDetail/frameDetail?pid=' + id + '&sk_id=' + sk_id)
b83c44fe1   喻鹏   购物车和用户推荐传参
164
  	  uni.navigateTo({
a3d2beaa8   范牧   立即支付功能
165
  	    url: '../frameDetail/frameDetail?pid=' + id + '&sk_id=' + sk_id,
b83c44fe1   喻鹏   购物车和用户推荐传参
166
167
  	    success: res => {},
  	    fail: () => {},
a3d2beaa8   范牧   立即支付功能
168
  	    complete: () => {},
b83c44fe1   喻鹏   购物车和用户推荐传参
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
  	  })
        // 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
        // }
7a7226fea   范牧   冲突合并
213
      },
cc196c33c   喻鹏   购物车和用户推荐接口渲染
214
  
b83c44fe1   喻鹏   购物车和用户推荐传参
215
      counter(index, isadd, item) {
7a7226fea   范牧   冲突合并
216
217
        // console.log('===>>counter ===>num',num)
        // console.log('===>>counter ===>isadd',isadd)
a3d2beaa8   范牧   立即支付功能
218
219
220
  	  console.log('item=====>', item)
  	  console.log('num=====>', item.num)
        const nums = parseInt(item.num)
7a7226fea   范牧   冲突合并
221
        if (isadd) {
b83c44fe1   喻鹏   购物车和用户推荐传参
222
          if (nums >= this.maxCount) {
7a7226fea   范牧   冲突合并
223
224
225
226
            this.addDisabled = true
          } else {
            this.addDisabled = true
            // 修改num
637a02b07   尹聃   添加购物车
227
  		  if (this.childIsOpen[index]) {
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
228
229
  			  this.totalPrice = this.totalPrice + this.$store.state.cart.cartList[index].nowPrice
  		  }
7a7226fea   范牧   冲突合并
230
            store.dispatch('cart/modiCart', {
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
231
232
              uid: this.$store.state.user.userInfo.uid,
              openid: this.$store.state.user.userInfo.openid,
b83c44fe1   喻鹏   购物车和用户推荐传参
233
234
              mp_id: item.mp_id,
              sk_id: item.sk_id,
a3d2beaa8   范牧   立即支付功能
235
236
              price: item.nowPrice,
              pid: item.pid,
b83c44fe1   喻鹏   购物车和用户推荐传参
237
              num: nums + 1,
a3d2beaa8   范牧   立即支付功能
238
              cart_id: item.cart_id,
7a7226fea   范牧   冲突合并
239
240
              args: {
                index: index,
a3d2beaa8   范牧   立即支付功能
241
242
                isadd: isadd,
              },
7a7226fea   范牧   冲突合并
243
244
245
246
            })
            this.addDisabled = false
          }
        } else {
b83c44fe1   喻鹏   购物车和用户推荐传参
247
          if (nums <= 1) {
7a7226fea   范牧   冲突合并
248
249
250
251
            this.desDisabled = true
          } else {
            this.desDisabled = false
            // post 请求修改相关参数
637a02b07   尹聃   添加购物车
252
  		  if (this.childIsOpen[index]) {
a3d2beaa8   范牧   立即支付功能
253
              this.totalPrice = this.totalPrice - this.$store.state.cart.cartList[index].nowPrice
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
254
  		  }
7a7226fea   范牧   冲突合并
255
            store.dispatch('cart/modiCart', {
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
256
257
              uid: this.$store.state.user.userInfo.uid,
              openid: this.$store.state.user.userInfo.openid,
b83c44fe1   喻鹏   购物车和用户推荐传参
258
259
              mp_id: item.mp_id,
              sk_id: item.sk_id,
a3d2beaa8   范牧   立即支付功能
260
261
              price: item.nowPrice,
              pid: item.pid,
b83c44fe1   喻鹏   购物车和用户推荐传参
262
              num: nums - 1,
a3d2beaa8   范牧   立即支付功能
263
              cart_id: item.cart_id,
7a7226fea   范牧   冲突合并
264
265
              args: {
                index: index,
a3d2beaa8   范牧   立即支付功能
266
267
                isadd: isadd,
              },
7a7226fea   范牧   冲突合并
268
269
270
271
            })
            this.desDisabled = true
          }
        }
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
272
273
274
  	  // store.dispatch('cart/getCartList', {
  	  //   uid: this.$store.state.user.userInfo.uid // 用户id
  	  // })
7a7226fea   范牧   冲突合并
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
      },
  
      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)
        } else {
          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
        }
      },
      pChange(isopen) {
        this.pIsoPen = !isopen
        for (let i = 0; i < this.childIsOpen.length; i++) {
          this.childIsOpen[i] = !isopen
        }
        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
        }
      },
      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)
a3d2beaa8   范牧   立即支付功能
319
320
  	  const uid = this.$store.state.user.userInfo.uid
  	  const openid = this.$store.state.user.userInfo.openid
7a7226fea   范牧   冲突合并
321
322
323
324
325
326
327
        uni.showModal({
          title: '是否删除该商品',
          // content: '是否删除该商品',
          success: function (res) {
            if (res.confirm) {
              // this.$store.state.cart.cartList.splice(index,1)
              store.dispatch('cart/delCart', {
b83c44fe1   喻鹏   购物车和用户推荐传参
328
329
                uid: uid,
                openid: openid,
7a7226fea   范牧   冲突合并
330
                cart_id: cart_id, // 要修改的购物车id
a3d2beaa8   范牧   立即支付功能
331
                arg: index, // 由于action 传参是能接收两参数,因此将index放入对象
7a7226fea   范牧   冲突合并
332
333
334
              })
              console.log('用户点击确定')
            }
a3d2beaa8   范牧   立即支付功能
335
          },
7a7226fea   范牧   冲突合并
336
        })
a3d2beaa8   范牧   立即支付功能
337
338
      },
    },
7a7226fea   范牧   冲突合并
339
  }
0db291810   BigBoss   “-mcomfirmOder页面
340
341
  </script>
  
6111092e8   BigBoss   update cart
342
  <style lang="scss">
637a02b07   尹聃   添加购物车
343
  .content {
a3d2beaa8   范牧   立即支付功能
344
345
346
347
348
349
350
351
    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;
66638e4bb   喻鹏   购物车样式和新增验光单样式修改
352
  
a3d2beaa8   范牧   立即支付功能
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
    .partentCheck {
      width: 16px;
      height: 16px;
      border-radius: 22px;
      border: 1px solid #cfcfcf;
      background-color: #ffffff;
      margin: 6px;
    }
    .partentChecked {
      width: 18px;
      height: 18px;
      border-radius: 22px;
      background-color: #ff6b4a;
      margin: 6px;
      .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%);
      }
    }
66638e4bb   喻鹏   购物车样式和新增验光单样式修改
389
  
a3d2beaa8   范牧   立即支付功能
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
    .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;
7a7226fea   范牧   冲突合并
432
  
a3d2beaa8   范牧   立即支付功能
433
434
435
436
          .imageWrap {
            height: 188rpx;
            width: 188rpx;
            margin-right: 28rpx;
7a7226fea   范牧   冲突合并
437
  
a3d2beaa8   范牧   立即支付功能
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
            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;
            .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;
              // box-sizing: border-box;
              // padding: 10rpx;
              font-size: 20rpx;
              letter-spacing: -0.23px;
              text-align: justify;
              color: #999999;
              // background: #F9F9F9;
              // display: flex;
              // justify-content: center;
              // align-items: center;
              // 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 {
              // 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;
              // }
            }
            .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: 24rpx;
              }
              .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;
                }
              }
            }
          }
        }
      }
    }
7a7226fea   范牧   冲突合并
544
  
a3d2beaa8   范牧   立即支付功能
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
    .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;
        }
      }
    }
  }
7a7226fea   范牧   冲突合并
586
  </style>