绿满眶商城微信小程序-uniapp
xiangpei
6 天以前 70738d032bd80f5b13075f8a13045ff4de57c2c3
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
<template>
    <view class="myTracks">
        <u-navbar title="我的足迹">
            <div slot="right">
        <div class="light-color edit" @click="isEdit = !isEdit">{{ !isEdit ? '编辑' : '完成'}}</div>
      </div>
        </u-navbar>
        <u-notice-bar mode="vertical" :list="['右划删除浏览记录']"></u-notice-bar>
        <u-empty text="暂无历史记录" style="margin-top:200rpx;" mode="history" v-if="whetherEmpty"></u-empty>
        <div v-else>
            <view v-for="(item, index) in trackList" :key="index">
                <view class="myTracks-title" @click="navigateToStore(item)">{{item.storeName}}</view>
                <view class="myTracks-items">
 
                    <u-swipe-action style="width: 100%;" :show="item.show" :index="index" :key="item.id"
                        @click="delTracks" @open="open" :options="options">
                        
                        <view class="myTracks-item">
                            <u-checkbox-group v-if="isEdit" class="store-line-check">
                                <u-checkbox shape="circle" :active-color="lightColor" v-model="item.checked"
                @change="checkboxChangeDP(item)"></u-checkbox>
                            </u-checkbox-group>
                            <view class="myTracks-item-img" @click.stop="navigateToDetail(item)">
                                <image :src="item.thumbnail"></image>
                            </view>
                            <view class="myTracks-item-content" @click.stop="navigateToDetail(item)">
                                <view class="myTracks-item-title">
                                    {{ item.goodsName }}
                                    <view class="myTracks-item-title-desc"> </view>
                                </view>
                                <view class="myTracks-item-price">
                                    ¥{{ item.price | unitPrice }}
                                </view>
                            </view>
                        </view>
                    </u-swipe-action>
 
                </view>
                <view class="myTracks-divider"></view>
 
            </view>
            <div @click="handleClickDeleteSelected" v-if="isEdit" class="submit">
                删除所选
            </div>
        </div>
 
    </view>
</template>
 
<script>
    import '@/components/uview-components/uview-ui';
    
    import {
        myTrackList,
        deleteHistoryListId
    } from "@/api/members.js";
 
    export default {
        data() {
            return {
                isEdit:false,
                whetherEmpty: false, //是否数据为空
                params: {
                    pageNumber: 1,
                    pageSize: 10,
                    order: "desc",
                    sort: "updateTime",
                },
                lightColor:this.$lightColor,
                options: [{
                    text: '删除',
                    style: {
                        backgroundColor: '#dd524d'
                    }
                }],
                trackList: [], //足迹列表
            };
        },
 
        /**
         * 滑到底部加载下一页数据
         */
        onReachBottom() {
            this.params.pageNumber++;
            this.getList();
        },
        onShow() {
            this.params.pageNumber = 1
            this.trackList = [];
            this.getList();
        },
        onPullDownRefresh() {
            this.trackList = [];
            this.getList();
        },
        methods: {
            checkboxChangeDP(val){
                console.log(val)
            },
            // 删除所选的数据
            handleClickDeleteSelected(val){
                const ids = this.trackList.filter(item=>item.checked).map(item=>item.goodsId);
                if(!ids.length){
                    uni.showToast({
                        title:"请选择删除数据",
                        icon:"none"
                    })
                }else{
                    this.delTracks(0,ids)
                }
            },
            /**
             * 导航到店铺
             */
            navigateToStore(val) {
                uni.navigateTo({
                    url: "/pages/product/shopPage?id=" + val.storeId,
                });
            },
            open(index) {
                // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
                // 原本为'false',再次设置为'false'会无效
                this.trackList[index].show = true;
                this.trackList.map((val, idx) => {
                    if (index != idx) this.trackList[idx].show = false;
                })
            },
            /**
             * 跳转详情
             */
            navigateToDetail(item) {
                uni.navigateTo({
                    url: "/pages/product/goods?id=" + item.id + "&goodsId=" + item.goodsId,
                });
            },
 
            /**
             * 获取我的足迹列表
             */
            getList() {
                uni.showLoading({
                    title: "加载中",
                });
                myTrackList(this.params).then((res) => {
                    uni.stopPullDownRefresh();
                    uni.hideLoading();
                    if (res.statusCode == 200) {
                        res.data.result.records.length &&
                            res.data.result.records.forEach((item) => {
                                item.show = false;
                                item.checked = false
                            });
 
                        let data = res.data.result.records;
                        if (data.total == 0) {
                            this.whetherEmpty = true;
                        } else {
                            this.trackList.push(...data);
                        }
                    }
                });
            },
 
 
            /**
             * 删除足迹
             */
            delTracks(index,ids) {
                deleteHistoryListId(ids || this.trackList[index].goodsId).then((res) => {
                    if (res.data.code == 200) {
                        this.trackList = [];
                        this.params.pageNumber = 1
                        this.getList();
                    } else {
                        uni.showToast({
                            title: res.data.message,
                            duration: 2000,
                            icon: "none",
                        });
                    }
                });
            },
        },
    };
</script>
 
<style lang="scss" scoped>
    .submit{
        position: fixed;
        bottom: 20rpx;
        left: 10%;
        width: 80%;
        height: 80rpx;
        color: #fff;
        border-radius: 100px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: $light-color;
    }
    .myTracks {
        width: 100%;
        padding-top: 2rpx;
    }
 
    .myTracks-title {
        width: 100%;
        height: 110rpx;
        padding-left: 20rpx;
        font-size: 28rpx;
        color: #666;
        font-weight: bold;
        background-color: #fff;
        align-items: center;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
    }
 
    .myTracks-items {
        padding-top: 2rpx;
        align-items: center;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
    }
 
    .myTracks-item {
        width: 100%;
        height: 226rpx;
        padding-left: 20rpx;
        padding-right: 20rpx;
        margin-bottom: 2rpx;
        // border-radius: 6/@px;
        background-color: #fff;
        position: relative;
        align-items: center;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
    }
 
    .myTracks-item-img {
        margin-right: 20rpx;
        border-radius: 8rpx;
 
        image {
            width: 130rpx;
            height: 130rpx;
            border-radius: 8rpx;
        }
    }
 
    .myTracks-item-title {
        font-size: 28rpx;
        color: #333;
    }
 
    .myTracks-item-title-desc {
        font-size: 28rpx;
        color: #999;
    }
 
    .myTracks-item-price {
        font-size: 28rpx;
        color: $light-color;
        padding: 10rpx 0 0 0;
    }
 
    .myTracks-action {
        display: flex;
        justify-content: space-between;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: #fff;
        height: 75rpx;
        align-items: center;
        padding: 0 32rpx;
    }
 
    .myTracks-action-btn {
        width: 130rpx;
        height: 60rpx;
        line-height: 60rpx;
    }
 
    .myTracks-divider {
        width: 100%;
        height: 20rpx;
    }
 
 
 
    .myTracks-action-check {
        align-items: center;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
    }
    .edit{
      padding-right: 32rpx;
    }
</style>