移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
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
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="我的足迹" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <block v-if="list.length">
            <u-swipe-action>
                <u-swipe-action-item :index="index" :name="index" v-for="(item, index) in list" :key="item.id" @click="onClick" :options="options">
                    <view class="coreshop-padding-10 coreshop-padding-bottom-0 coreshop-solid-bottom coreshop-display-flex coreshop-flex-nowrap coreshop-percent-100 coreshop-bg-white" @click="goGoodsDetail(item.goodsId)">
                        <u-avatar :src="item.goodImage" shape="square" size="60" class="coreshop-margin-10"></u-avatar>
                        <view class="title-wrap coreshop-padding-left-10">
                            <text class="coreshop-text-left coreshop-font-14  u-line-2">{{ item.goodsName }}</text>
                            <view class="coreshop-margin-top-10">
                                <u-icon name="clock" :label="item.createTime" labelSize="12"></u-icon>
                            </view>
                        </view>
                    </view>
                </u-swipe-action-item>
            </u-swipe-action>
            <u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
        </block>
        <!-- 无数据时默认显示 -->
        <view class="coreshop-emptybox" v-else>
            <u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/collect.png'" icon-size="150" text="暂无足迹" mode="list"></u-empty>
 
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                page: 1,
                limit: 10,
                list: [], // 商品浏览足迹
                loadStatus: 'more',
                options: [
                    {
                        text: '收藏',
                        style: {
                            backgroundColor: '#007aff'
                        }
                    },
                    {
                        text: '删除',
                        style: {
                            backgroundColor: '#dd524d'
                        }
                    }
                ],
                status: 'loadmore',
                iconType: 'flower',
                loadText: {
                    loadmore: '轻轻上拉',
                    loading: '努力加载中',
                    nomore: '实在没有了'
                }
            };
        },
        onLoad() {
            this.goodsBrowsing()
        },
        onReachBottom() {
            if (this.status === 'loading') {
                this.goodsBrowsing();
            }
        },
        methods: {
            goodsBrowsing() {
                let data = {
                    page: this.page,
                    limit: this.limit
                }
                this.status = 'loading'
                this.$u.api.goodsBrowsing(data).then(res => {
                    if (res.status) {
                        let _list = res.data.list
                        _list.forEach(item => {
                            item.show = false;
                        })
                        this.list = [...this.list, ..._list]
                        if (res.data.count > this.list.length) {
                            this.page++
                            this.status = 'loading'
                        } else {
                            this.status = 'nomore'
                        }
                    } else {
                        this.$u.toast(res.msg)
                    }
                })
            },
            onClick(e) {
                let _this = this;
                var goodsId = _this.list[e.name].goodsId;
                var id = _this.list[e.name].id;
                if (e.index == 0) {
                    let data = {
                        id: goodsId
                    }
                    _this.$u.api.goodsCollection(data).then(res => {
                        if (res.status) {
                            _this.$refs.uToast.show({
                                message: res.msg, type: 'success', complete: function () {
                                    _this.$nextTick(() => {
                                        _this.list[e.name].isCollection = !this.list[e.name].isCollection
                                    })
                                }
                            })
                        } else {
                            _this.$u.toast(res.msg)
                        }
                    })
                } else if (e.index == 1) {
                    let data = {
                        id: id
                    }
                    _this.$u.api.delGoodsBrowsing(data).then(res => {
                        if (res.status) {
                            _this.list.splice(e.name, 1)
                            _this.$refs.uToast.show({ message: res.msg, type: 'success' })
 
                            _this.page = 1;
                            _this.list = [];
                            _this.goodsBrowsing();
                        } else {
                            _this.$u.toast(res.msg)
                        }
                    })
 
                }
            },
        }
    };
</script>
 
<style lang="scss" scoped>
    @import "index.scss";
</style>