绿满眶商城微信小程序-uniapp
peng
19 小时以前 a6c950ba797dffec842cf7e923fc439868645766
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
<template>
    <view class="similar-goods">
        <view class="goods" @click="goDetail(goods.goods_id)">
            <image :src="goods.goods_img" mode=""></image>
            <view class="goods-intro">
                <view>{{goods.goodsName}}</view>
                <view>{{goods.goods_sn}}</view>
                <view>¥{{goods.goods_price | unitPrice}}</view>
            </view>
            <!-- <button>找相似</button> -->
        </view>
        <view class="title">相似好货&nbsp;为您推荐</view>
        <view class="scroll-con">
            <view v-if="nomsg">没有相似商品</view>
            <view v-else class="con" v-for="(item,index) in goodsList" :key="index" @click="goDetail(item)">
                <image :src="item.thumbnail" mode=""></image>
                <view class="nowrap">{{item.name}}</view>
                <view>
                    <text>¥{{item.price | unitPrice}}
                    <!-- <text v-if="item.point">+{{item.point || 0}}积分</text> -->
                    </text>
                    <text>¥{{item.mktprice}}</text>
                </view>
                <view>
                    <text>已售{{item.buy_count}}件</text>
                    <text>{{item.grade}}%好评</text>
                </view>
            </view>
        </view>
        <uni-load-more :status="loadStatus"></uni-load-more>
    </view>
</template>
 
<script>
    import {
        getGoodsList
    } from '@/api/goods.js';
    export default {
        data() {
            return {
                loadStatus: 'more',
                params: {
                    pageNumber: 1,
                    pageSize: 10,
                    keyword: ''
                },
                goods: {},
                goodsList: [],
                nomsg: false,
            };
        },
        methods: {
            getList() {
                uni.showLoading({
                    title: "加载中"
                })
                this.params.keyword = this.goods.goodsName;
                getGoodsList(this.params).then(res => {
                     if (this.$store.state.isShowToast){ uni.hideLoading() }
                    if (res.statusCode == 200) {
                        let data = res.data;
                        if (data.data_total == 0) {
                            // this.nomsg = true;
                            this.loadStatus = 'noMore';
                        } else if (data.data_total < 10) {
                            this.loadStatus = 'noMore'
                            this.goodsList.push(...data.data)
                        } else {
                            this.goodsList.push(...data.data);
                            if (data.data.length < 10) this.loadStatus = 'noMore'
                        }
                    }
                })
            },
            goDetail(item) {
                uni.navigateTo({
                    url: '/pages/product/goods?id=' + item.id + "&goodsId=" +item.goodsId
                })
            },
            loadData() {
                if(this.loadStatus!='noMore'){
                    this.params.pageNumber++;
                    this.getList()
                }
            },
        },
        onLoad(option) {
            this.goods = JSON.parse(decodeURIComponent(option.goods))
            
            this.getList()
        },
        onReachBottom() { //触底事件,页面整个滚动使用
            this.loadData()
        }
    }
</script>
 
<style lang="scss" scoped>
    @import './collect.scss';
 
    .title {
        height: 110rpx;
        line-height: 110rpx;
        text-align: center;
        color: #333;
        background-color: #F1F1F1;
        margin-top: 20rpx;
        font-size: $font-base;
    }
 
    .goods {
        padding: 0 30rpx;
    }
 
    .scroll-con {
        width: 750rpx;
        flex-wrap: wrap;
 
        .con {
            width: 345rpx;
            margin: 20rpx 0 0 20rpx;
            background-color: #FFFFFF;
            border-radius: 10rpx;
            box-sizing: border-box;
            display: inline-block;
            font-size: $font-sm;
 
            // line-height: 1.5em;
            image {
                width: 100%;
                height: 320rpx;
                border-radius: 8rpx 8rpx 0 0;
            }
            view{
                padding: 0 20rpx;
                &::after{
                    content: '';
                    display: block;
                    clear: right;
                }
                text {
                    display: inline-block;
                    color: #999;
                }
                
                text:nth-child(2) {
                    float: right;
                    text-align: right;
                }
            }
            view:last-child{
                margin-bottom: 20rpx;
            }
            .nowrap {
                position: relative;
                line-height: 1.4em;
                max-height: 2.8em; //height是line-height的整数倍,防止文字显示不全
                overflow: hidden;
            }
 
            
 
            view:nth-child(2) {
                font-size: 26rpx;
            }
 
            view:nth-child(3) {
                margin-top: 10rpx;
                font-weight: bold;
 
                text:nth-child(1) {
                    color: #f56c6c;
                }
 
                text:nth-child(2) {
                    color: #d7d7d7;
                    text-decoration: line-through;
                }
            }
 
            view:nth-child(4) {
                margin-top: 10rpx;
            }
 
        }
    }
</style>