移动系统liao
2024-05-09 5d6cb15ac86d9174393cb9d1538d69b567e2c26c
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
<template>
    <view class="content">
        <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>
        <view>
            <view class="coreshop-padding-left-15 coreshop-padding-right-15 coreshop-padding-top-15">
                <u-subsection :list="items" :current="current" :animation="true" @change="onClickItem" active-color="#ff9900"></u-subsection>
            </view>
            <view class="coreshop-coupon" v-if="listData.length > 0">
                <view v-for="(item, key) in listData" :key="key">
                    <view class="coreshop-coupon-card-view" :class="item.isExpire || item.isUsed ?' grayscale':''">
                        <view class="card-price-view">
                            <view class="coreshop-text-red price-left-view">
                                <image class="icon" src="/static/images/coupon/coupon-element.png" mode=""></image>
                            </view>
                            <view class="name-content-view">
                                <view class="u-line-1 coreshop-text-red">{{item.couponName}}</view>
                                <view class="coreshop-font-xs">
                                    说明:<text v-for="(itemResult, index) in item.results" :key="index">{{itemResult}}</text>
                                </view>
                                <view class="coreshop-font-xs">有效期:{{item.stime}} - {{item.etime}}</view>
                            </view>
                            <view class="btn-right-view">
                                <u-button type="success" shape="circle" size="mini" @click="goIndex" v-if="current == 0">去使用</u-button>
                                <u-button type="default" shape="circle" size="mini" v-if="item.isUsed==true">已使用</u-button>
                                <u-button type="default" shape="circle" size="mini" v-if="item.isExpire && !item.isUsed">已失效</u-button>
                            </view>
                        </view>
                        <view class="card-num-view coreshop-flex coreshop-flex-direction-row  coreshop-justify-between">
                            <view class="coreshop-font-xs coreshop-flex-direction-row coreshop-basis-9 u-line-1">
                                <text v-for="(itemCondition, index) in item.conditions" :key="index">【{{itemCondition}}】</text>
                            </view>
                            <view class="coreshop-width-fit-content">
                                <u-icon name="arrow-down-fill" class="coreshop-float-right" size="14"></u-icon>
                            </view>
                        </view>
                    </view>
                </view>
                <u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" margin-top="20" margin-bottom="20" />
            </view>
            <!-- 无数据时默认显示 -->
            <view class="coreshop-emptybox" v-else>
                <u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/coupon.png'" icon-size="150" text="暂无此类优惠券" mode="list"></u-empty>
            </view>
        </view>
    </view>
 
</template>
 
<script>
    export default {
        data() {
            return {
                items: ['未使用', '已使用', '已失效'],
                current: 0,
                page: 1,
                limit: 10,
                listData: [],
                status: 'loadmore',
                iconType: 'flower',
                loadText: {
                    loadmore: '轻轻上拉',
                    loading: '努力加载中',
                    nomore: '实在没有了'
                }
            }
        },
        onLoad() {
            this.getData();
        },
        onReachBottom() {
            if (this.status === 'loadmore') {
                this.getData();
            }
        },
        methods: {
            // tab点击切换
            onClickItem(index) {
                if (this.current !== index) {
                    this.current = index;
                    this.page = 1;
                    this.listData = [];
                    this.getData();
                }
            },
            //获取优惠券列表
            getData() {
                this.status = 'loading'
                let data = {
                    page: this.page,
                    limit: this.limit
                }
                if (this.current == 0) {
                    data['display'] = 'noUsed';
                }
                if (this.current == 1) {
                    data['display'] = 'yesUsed';
                }
                if (this.current == 2) {
                    data['display'] = 'invalid';
                }
                this.$u.api.userCoupon(data).then(res => {
                    if (res.status) {
                        let nowType = 'noUsed';
                        if (this.current == 1) {
                            nowType = 'yesUsed';
                        }
                        if (this.current == 2) {
                            nowType = 'invalid';
                        }
                        if (nowType == res.data.display) {
                            if (res.data.page >= this.page) {
                                let newList = this.listData.concat(res.data.list);
                                this.listData = newList;
                                if (res.data.count > this.listData.length) {
                                    this.page++
                                    this.status = 'loadmore'
                                } else {
                                    this.status = 'nomore'
                                }
                            }
                        }
                    } else {
                        this.$u.toast(res.msg);
                    }
                });
            },
            //跳转首页
            goIndex() {
                this.$u.route({
                    type: 'switchTab',
                    url: '/pages/index/default/default'
                });
            }
        }
    }
</script>
<style lang="scss">
    @import 'index.scss';
</style>