绿满眶商城微信小程序-uniapp
zxl
4 天以前 c9928dd4f6d25e2339ea1400f59ec58674a927a7
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
<template>
    <view class="list">
        <view class='uni-list--waterfall'>
            <view class="uni-list ">
                <!-- 通过 uni-list--waterfall 类决定页面布局方向 -->
                <!-- to 属性携带参数跳转详情页面,当前只为参考 -->
                <view :border="!formData.waterfall" class="uni-list-item--waterfall" title="自定义商品列表"
                    v-for="item in data" :key="item.id" @click="toggle(item)">
                    <!-- 通过header插槽定义列表左侧图片 -->
 
                    <view class="uni-thumb shop-picture" :class="{ 'shop-picture-column': formData.waterfall }">
                        <image :src="item.thumbnail" mode="aspectFill"></image>
                    </view>
                    <view class="shop">
                        <view>
                            <view class="uni-title">
                                <text class="uni-ellipsis-2">{{ item.goodsName }}</text>
                            </view>
                            <!-- <view>
                                    <text class="uni-tag hot-tag">{{ item.goods_tip }}</text>
                                    <text v-for="tag in item.tag" :key="tag" class="uni-tag">{{ tag }}</text>
                                </view> -->
                        </view>
                        <view>
                            <view class="shop-price">
                                <text>¥</text>
                                <text class="shop-price-text">{{ item.price }}</text>
                                <text>.00</text>
                            </view>
                            <view class="uni-flex-row">
                                <view class="uni-note">{{ item.commentNum || 0 }}条评论 月销量 {{
                                    item.buyCount || 0 }}
                                </view>
                                <view class="uni-note ellipsis">
                                    <text :class="item.marketEnable == 'DOWN' ? 'market-down' : 'market-up'">{{
                                        item.marketEnable == 'DOWN' ? "已下架" : "已上架" }}</text>
 
                                    <!--<text class="uni-link" style="color:red;">删除</text> -->
                                </view>
                            </view>
                        </view>
                    </view>
                    <!-- 通过body插槽定义商品布局 -->
 
                </view>
            </view>
            <view style="height: 80px;"></view>
        </view>
 
        <button type="default" class="btn" @click="addGoods('')">
            <u-icon name="plus-circle"></u-icon>
            添加商品
        </button>
        <!-- 通过 loadMore 组件实现上拉加载效果,如需自定义显示内容,可参考:https://ext.dcloud.net.cn/plugin?id=29 -->
        <uni-load-more v-if="loading || formData.status === 'noMore'" :status="formData.status" />
        <view>
            <!-- 普通弹窗 -->
            <uni-popup ref="popup" background-color="#fff">
                <view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
 
                    <button type="default" @click="underOrup">{{ selectGoods.marketEnable == 'DOWN' ? '上架' : "下架"
                    }}</button>
 
                    <button type="default" @click="stocks">调整库存</button>
                </view>
            </uni-popup>
        </view>
 
    </view>
</template>
 
<script>
 
import '@/components/uview-components/uview-ui';
 
import * as API_GOODS from "@/api/goods.js";
 
export default {
    data() {
        return {
            formData: {
                waterfall: false, // 布局方向切换
                status: 'loading', // 加载状态
            },
            params: {
                pageNumber: 1,
                pageSize: 10,
            },
            data: [],
            formData: {
                status: 'loading', // 加载状态
            },
            selectGoods: {},
            tipShow: false // 是否显示顶部提示框
        };
    },
    onLoad() {
    },
    onShow() {
        if (this.$options.filters.tipsToLogin()) {
            this.getGoodsList();
        }
    },
    methods: {
        underOrup() {
            let params = {
                goodsId: this.selectGoods.id,
            };
            this.$refs.popup.close()
            if (this.selectGoods.marketEnable == 'DOWN') {
                API_GOODS.upGoods(params).then((res) => {
                    uni.showLoading({
                        title: '上架成功'
                    });
 
                    setTimeout(function () {
                        uni.hideLoading();
                    }, 2000);
                    this.getGoodsList();
                })
            }
            else {
                API_GOODS.lowGoods(params).then((res) => {
                    uni.showLoading({
                        title: '下架成功'
                    });
 
                    setTimeout(function () {
                        uni.hideLoading();
                    }, 2000);
                    this.getGoodsList();
                })
            }
        },
        stocks() {
            
            this.$refs.popup.close()
            var goodsId = this.selectGoods.id
            uni.navigateTo({
                url: `/pages/goods-manager/updateSkus/updateSkus${"?goodsId=" + goodsId}`,
            });
        },
        toggle(item) {
            this.$refs.popup.open('bottom')
            this.selectGoods = item;
        },
 
        getGoodsList() {
            uni.showLoading();
            API_GOODS.getStoreGoods(
                this.params.pageNumber,
                this.params.pageSize
            ).then((res) => {
                this.data = res.data.result.records;
 
                if (this.$store.state.isShowToast) { uni.hideLoading() };
            });
        },
        addGoods(id) {
            uni.navigateTo({
                url: `/pages/goods-manager/addGoods/addGoods${id ? "?id=" + id : ""}`,
            });
        }
 
    },
    /**
     * 下拉刷新回调函数
     */
    onPullDownRefresh() {
        this.formData.status = 'more'
 
    },
    /**
     * 上拉加载回调函数
     */
    onReachBottom() {
 
    }
};
</script>
 
 
<style lang="scss" scoped>
@import './goodsList.scss';
 
page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #efeff4;
    min-height: 100%;
    height: auto;
}
 
.tips {
    color: #67c23a;
    font-size: 14px;
    line-height: 40px;
    text-align: center;
    background-color: #f0f9eb;
    height: 0;
    opacity: 0;
    transform: translateY(-100%);
    transition: all 0.3s;
}
 
.tips-ani {
    transform: translateY(0);
    height: 40px;
    opacity: 1;
}
 
.shop {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
 
.shop-picture {
    width: 110px;
    height: 110px;
}
 
.shop-picture-column {
    width: 100%;
    height: 170px;
    margin-bottom: 10px;
}
 
.shop-price {
    margin-top: 5px;
    font-size: 12px;
    color: #ff5a5f;
}
 
.shop-price-text {
    font-size: 16px;
}
 
.hot-tag {
    background: #ff5a5f;
    border: none;
    color: #fff;
}
 
.button-box {
    height: 30px;
    line-height: 30px;
    font-size: 12px;
    background: #007AFF;
    color: #fff;
}
 
.uni-flex-row {
    display: flex;
 
}
 
.uni-link {
    flex-shrink: 0;
    margin-right: 10px;
}
 
.ellipsis {
    margin-left: auto;
    display: flex;
    overflow: hidden;
}
 
.uni-ellipsis-1 {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
 
.uni-ellipsis-2 {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
 
 
// 默认加入 scoped ,所以外面加一层提升权重
.list {
    .uni-list--waterfall {
 
        /* #ifndef H5 || APP-VUE */
        // 小程序 编译后会多一层标签,而其他平台没有,所以需要特殊处理一下
        /deep/ .uni-list {
            /* #endif */
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            padding: 5px;
            box-sizing: border-box;
 
            /* #ifdef H5 || APP-VUE */
            // h5 和 app-vue 使用深度选择器,因为默认使用了 scoped ,所以样式会无法穿透
            /deep/
            /* #endif */
            .uni-list-item--waterfall {
                width: 98%;
                display: flex;
                box-sizing: border-box;
                margin-bottom: 10px;
                background-color: white;
                padding: 10px;
 
                .uni-list-item__container {
                    padding: 5px;
                    flex-direction: column;
                }
            }
 
            /* #ifndef H5 || APP-VUE */
        }
 
        /* #endif */
    }
}
 
 
.btn {
    background: $light-color;
    position: fixed;
    width: 690rpx;
    bottom: 60rpx;
    height: 80rpx;
    left: 30rpx;
    font-size: 30rpx;
    line-height: 80rpx;
 
    .u-icon {
        margin-right: 10rpx;
    }
}
 
@mixin flex {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: row;
}
 
@mixin height {
    /* #ifndef APP-NVUE */
    height: 100%;
    /* #endif */
    /* #ifdef APP-NVUE */
    flex: 1;
    /* #endif */
}
 
.popup-content {
    @include flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    height: 150px;
    background-color: #fff;
}
 
.popup-height {
    @include height;
    width: 200px;
}
 
.market-down {
    color: red;
}
 
.market-up {
    color: green;
}
</style>