coupon-list-sheet.vue
4.08 KB
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
<template>
<action-sheet @hidden="onHidden" @hide="onHide" ref="popup">
<div class="activity-sheet">
<h3>领取优惠券</h3>
<div class="list">
<cube-scroll ref="couponListScroll" :data="list">
<ul>
<li v-for="(item, index) in list" :key="index">
<div class="item-wrapper">
<div class="left-wrapper">
<div class="coupon-price"><i>¥</i>{{item.couponAmount}}</div>
<div class="coupon-name">{{item.couponName}}</div>
<div class="sub">{{item.receiveStartTime}} - {{item.receiveEndTime}}</div>
</div>
<div :class="['item-button', item.receive === 'N' ? 'active' : '']" @click="clickButton(item)">
{{item.receive === 'N' ? '已领取' : '立即领取'}}</div>
</div>
</li>
</ul>
</cube-scroll>
</div>
</div>
</action-sheet>
</template>
<script>
import { Scroll, Button } from 'cube-ui';
import ActionSheet from './action-sheet';
import { createNamespacedHelpers } from 'vuex';
const {mapActions} = createNamespacedHelpers('activitys/limitTimeCoupon');
export default {
name: 'CouponListSheet',
props: {
list: {
type: Array,
required: true,
}
},
data() {
return {
isLogin: false,
};
},
components: {
'cube-scroll': Scroll,
'cube-button': Button,
'action-sheet': ActionSheet
},
watch: {
'yoho.context.isLogin': function(val) {
this.isLogin = val;
}
},
mounted() {
this.$refs.popup.show(() => {
this.$refs.couponListScroll.refresh();
});
},
methods: {
...mapActions(['getProductCoupon']),
onHidden() {
this.$emit('hidden');
},
onHide() {
this.$emit('hide');
},
async clickButton(item) {
let couponToken = item.couponToken;
if (item.receive === 'N') { // 是否可以领取 N:否,Y:是
return;
}
const user = await this.$yoho.auth();
if (user && user.uid) {
this.getProductCoupon({couponTokens: couponToken}).then(result => {
this.$createDialog({
type: 'alert',
title: result.code === 200 ? '领取优惠券成功' : result.message,
icon: result.code === 200 ? 'cubeic-ok' : 'cubeic-warn'
}).show();
if (result.code === 200) { // 领取成功刷新一下领取状态
this.$emit('updateCoupon');
}
});
}
}
},
};
</script>
<style lang="scss" scoped>
.activity-sheet {
display: flex;
flex-direction: column;
height: 800px;
h3 {
text-align: center;
font-size: 32px;
line-height: 3;
font-weight: bold;
color: #333;
}
.list {
flex: 1;
overflow: scroll;
}
ul {
list-style: none;
line-height: 2;
color: #000;
}
li {
padding: 30px 40px;
border-bottom: 1px solid #eee;
}
.item-wrapper {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.item-button {
width: 180px;
height: 80px;
border-radius: 40px;
background: #002B47;
color: #fff;
line-height: 80px;
text-align: center;
font-size: 24px;
&.active {
background-color: #fff;
color: #999;
border: 1px solid #ccc;
}
}
.left-wrapper {
max-width: calc(100%- 20px- 180px);
overflow: hidden;
}
.coupon-price {
@include num;
font-weight: bold;
font-size: 56px;
line-height: 64px;
height: 64px;
i {
font-style: normal;
font-size: 40px;
vertical-align: baseline;
}
}
.coupon-name {
margin-top: 10px;
font-size: 28px;
line-height: 40px;
font-weight: bold;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.sub {
margin-top: 10px;
color: #999;
font-size: 24px;
line-height: 34px;
}
}
</style>