绿满眶商城微信小程序-uniapp
zhanghua
5 天以前 1113721c0e068c57adbc15149cce15563960a7f2
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
<template>
    <view style="padding: 0 20rpx;">
        <view
            class="goods-item"
            v-for="(goods, index) in goodsList"
            :key="goods.goodsId"
            @click="selectGoods(goods, index)"
        >
            <image :src="goods.thumbnail" class="goods-image"></image>
            <view class="goods-info">
              <text class="goods-name">{{ goods.goodsName }}</text>
              <view style="display: flex;">
                  <view class="goods-price" style="flex: 1;">¥{{ goods.price }}</view>
                  <view @click.stop="() => {}" style="flex: 1;display: flex;justify-content: center;align-items: center;">
                      <view style="width: 90rpx">数量:</view>
                      <uni-number-box v-model="goods.goodsNum" :min="0"/>
                  </view>
              </view>
            </view>
        </view>
        <view style="position: fixed;bottom: 80rpx;display: flex;align-items: center;padding: 0 20rpx;width: calc(100% - 40rpx);">
            <view style="flex:7">已选{{totalNum}}个商品,合计:<text class="goods-price">¥{{totalMoney}}</text></view>
            <view style="flex:3;display: flex;align-items: flex-end">
                <u-button @click="toPay" type="success" size="medium" :disabled="totalNum < 1">去支付</u-button>
            </view>
        </view>
    </view>
</template>
 
<script>
    import {getGoodsDetail} from "@/api/video.js"
    
    import '@/components/uview-components/uview-ui';
    export default {
        computed: {
            totalMoney() {
                return this.goodsList.reduce((total, goods) => {
                        return total + (goods.price * goods.goodsNum)
                      }, 0)
            },
            totalNum() {
                return this.goodsList.filter(goods => goods.goodsNum !== 0).length;
            }
        },
        data() {
            return {
                videoId: '',
                goodsList: []
            }
        },
        onLoad(option) {
            this.videoId = option.videoId;
            this.getGoodsList();
        },
        methods: {
            // 获取商品列表
            async getGoodsList() {
                getGoodsDetail(this.videoId).then(res => {
                    this.goodsList = res.data.data
                })
            },
            // 生成订单-支付
            toPay() {
                
            }
        }
    }
</script>
 
<style>
.goods-item {
    display: flex;
    align-items: center;
    padding: 20rpx 0;
    border-bottom: 1rpx solid #f5f5f5;
}
.goods-image {
  width: 100rpx;
  height: 100rpx;
  border-radius: 8rpx;
  margin-right: 20rpx;
}
.goods-info {
  flex: 1;
}
.goods-name {
  font-size: 28rpx;
  color: #333;
  margin-bottom: 10rpx;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.goods-price {
  font-size: 28rpx;
  color: #f44;
  font-weight: bold;
}
</style>