MrShi
13 小时以前 6ebeddfe87542e4b3abfbe1adeb9187204f63ba8
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<template>
    <view class="combo-page">
        <view class="combo-toolbar">
            <picker class="source-picker" mode="selector" :range="sourceOptions" :value="sourceIndex" @change="handleSourceChange">
                <view class="source-picker__inner">
                    <text class="source-picker__text">{{ currentSource }}</text>
                    <image class="source-picker__icon" src="/static/icon/ar_drop@2x.png" mode="aspectFit"></image>
                </view>
            </picker>
            <view class="search-box">
                <image class="search-box__icon" src="/static/icon/ic_search@2x.png" mode="aspectFit"></image>
                <input
                    v-model="keyword"
                    class="search-box__input"
                    type="text"
                    placeholder="搜索套餐名称"
                    placeholder-class="search-box__placeholder"
                    confirm-type="search"
                    @input="handleKeywordInput"
                    @confirm="handleKeywordConfirm"
                />
            </view>
        </view>
 
        <view class="combo-tabs">
            <view
                v-for="item in tabs"
                :key="item.value"
                :class="activeTab === item.value ? 'combo-tabs__item active' : 'combo-tabs__item'"
                @click="handleTabChange(item.value)"
            >
                {{ item.label }}
            </view>
        </view>
 
        <view class="combo-list" v-if="list.length">
            <view class="combo-card" v-for="item in list" :key="item.id">
                <view class="combo-card__head">
                    <view class="combo-card__title u-line-1">{{ item.name || '-' }}</view>
                    <view :class="Number(item.status) === 0 ? 'combo-card__status is-normal' : 'combo-card__status is-invalid'">
                        {{ item.statusText }}
                    </view>
                </view>
 
                <view class="combo-card__info">适用范围:{{ item.scope }}</view>
                <view class="combo-card__info">骑行限制:{{ item.limit }}</view>
                <view class="combo-card__info">购买渠道:{{ item.source }}</view>
                <view class="combo-card__info">购买时间:{{ item.buyTime }}</view>
 
                <view class="combo-card__foot">
                    <view class="combo-card__date">有效期:{{ item.validDate }}</view>
                    <view class="combo-card__price">¥{{ item.price }}</view>
                </view>
            </view>
            <view class="combo-list__tips" v-if="loading">加载中...</view>
            <view class="combo-list__tips" v-else-if="finished">没有更多了</view>
        </view>
 
        <view class="combo-empty" v-else>
            <text>{{ loading ? '加载中...' : '暂无套餐数据' }}</text>
        </view>
    </view>
</template>
 
<script>
    export default {
        onLoad() {
            this.getList(true)
        },
        onPullDownRefresh() {
            this.getList(true)
        },
        onReachBottom() {
            if (!this.loading && !this.finished) {
                this.getList()
            }
        },
        data() {
            return {
                keyword: '',
                keywordTimer: null,
                sourceIndex: 0,
                activeTab: 0,
                page: 1,
                capacity: 10,
                loading: false,
                finished: false,
                sourceOptions: ['订单来源', '小程序端', '抖音端'],
                tabs: [
                    { label: '正常', value: 0 },
                    { label: '作废', value: 1 }
                ],
                list: []
            };
        },
        computed: {
            currentSource() {
                return this.sourceOptions[this.sourceIndex] || this.sourceOptions[0]
            }
        },
        beforeDestroy() {
            if (this.keywordTimer) {
                clearTimeout(this.keywordTimer)
                this.keywordTimer = null
            }
        },
        methods: {
            handleSourceChange(event) {
                this.sourceIndex = Number(event.detail.value)
                this.getList(true)
            },
            handleKeywordInput() {
                if (this.keywordTimer) {
                    clearTimeout(this.keywordTimer)
                }
                this.keywordTimer = setTimeout(() => {
                    this.getList(true)
                }, 300)
            },
            handleKeywordConfirm() {
                if (this.keywordTimer) {
                    clearTimeout(this.keywordTimer)
                    this.keywordTimer = null
                }
                this.getList(true)
            },
            handleTabChange(value) {
                if (this.activeTab === value) {
                    return
                }
                this.activeTab = value
                this.getList(true)
            },
            formatScope(item) {
                const scopes = []
                if (Number(item.iselecbike) === 1) {
                    scopes.push('电动车')
                }
                if (Number(item.isbike) === 1) {
                    scopes.push('自行车')
                }
                return scopes.length ? scopes.join(' | ') : '-'
            },
            formatLimit(limitType) {
                return Number(limitType) === 1 ? '限制' : '不限'
            },
            formatChannel(channel) {
                return Number(channel) === 1 ? '抖音团购' : '小程序端'
            },
            formatDateRange(start, end) {
                if (!start && !end) {
                    return '-'
                }
                return `${start || '-'} 至 ${end || '-'}`
            },
            formatPrice(price) {
                const value = Number(price)
                if (Number.isNaN(value)) {
                    return '0.00'
                }
                return value.toFixed(2)
            },
            formatStatus(status) {
                return Number(status) === 1 ? '作废' : '正常'
            },
            mapList(list) {
                return (list || []).map((item, index) => ({
                    ...item,
                    id: item.id || `${this.page}-${index}-${item.createDate || ''}`,
                    scope: this.formatScope(item),
                    limit: this.formatLimit(item.limitType),
                    source: this.formatChannel(item.channel),
                    buyTime: item.createDate || '-',
                    validDate: this.formatDateRange(item.useStartDate, item.useEndDate),
                    price: this.formatPrice(item.price),
                    statusText: this.formatStatus(item.status)
                }))
            },
            async getList(reset = false) {
                if (this.loading) {
                    return
                }
 
                if (reset) {
                    this.page = 1
                    this.finished = false
                    this.list = []
                }
 
                this.loading = true
                try {
                    const model = {
                        status: this.activeTab
                    }
                    if (this.sourceIndex > 0) {
                        model.channel = this.sourceIndex - 1
                    }
                    if (this.keyword.trim()) {
                        model.name = this.keyword.trim()
                    }
 
                    const res = await this.$u.api.memberDiscountPage({
                        capacity: this.capacity,
                        page: this.page,
                        model
                    })
 
                    if (res.code === 200) {
                        const records = this.mapList(res.data.records)
                        this.list = reset ? records : this.list.concat(records)
                        this.finished = records.length < this.capacity
                        if (!this.finished) {
                            this.page += 1
                        }
                    }
                } finally {
                    this.loading = false
                    uni.stopPullDownRefresh()
                }
            }
        }
    }
</script>
 
<style>
    page {
        background: #f6f6f6;
    }
</style>
 
<style lang="scss" scoped>
    .combo-page {
        min-height: 100vh;
        box-sizing: border-box;
    }
 
    .combo-toolbar {
        display: flex;
        align-items: center;
        background-color: #ffffff;
        padding: 12rpx 30rpx;
        box-sizing: border-box;
        position: sticky;
        top: 0;
        left: 0;
        z-index: 9;
    }
 
    .source-picker {
        width: 176rpx;
        flex-shrink: 0;
        margin-right: 16rpx;
    }
 
    .source-picker__inner {
        height: 64rpx;
        padding: 0 22rpx;
        background: #F7F7F7;
        border-radius: 36rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        box-sizing: border-box;
    }
 
    .source-picker__text {
        font-size: 24rpx;
        color: #666666;
    }
 
    .source-picker__icon {
        width: 20rpx;
        height: 12rpx;
        margin-left: 12rpx;
    }
 
    .search-box {
        flex: 1;
        height: 64rpx;
        padding: 0 22rpx;
        background: #F7F7F7;
        border-radius: 32rpx;
        display: flex;
        align-items: center;
        box-sizing: border-box;
    }
 
    .search-box__icon {
        width: 28rpx;
        height: 28rpx;
        margin-right: 12rpx;
        flex-shrink: 0;
    }
 
    .search-box__input {
        flex: 1;
        height: 64rpx;
        font-size: 24rpx;
        color: #333333;
    }
 
    .search-box__placeholder {
        color: #bdbdbd;
        font-size: 24rpx;
    }
 
    .combo-tabs {
        height: 88rpx;
        background-color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 88rpx;
        left: 0;
        z-index: 9;
    }
 
    .combo-tabs__item {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        padding: 0 8rpx 16rpx;
        font-size: 34rpx;
        font-weight: 500;
        color: #666666;
        line-height: 1;
    }
 
    .combo-tabs__item.active {
        color: #01b6ad;
        font-weight: 600;
    }
 
    .combo-tabs__item.active::after {
        content: '';
        position: absolute;
        left: 50%;
        bottom: 0;
        transform: translateX(-50%);
        width: 52rpx;
        height: 6rpx;
        border-radius: 4rpx;
        background: #01b6ad;
    }
 
    .combo-list {
        display: flex;
        padding: 0 20rpx;
        box-sizing: border-box;
        flex-direction: column;
    }
 
    .combo-list__tips {
        padding: 20rpx 0 4rpx;
        text-align: center;
        font-size: 24rpx;
        color: #999999;
    }
 
    .combo-card {
        background: #ffffff;
        border-radius: 20rpx;
        box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.04);
        overflow: hidden;
        margin-top: 20rpx;
    }
 
    .combo-card:last-child {
        margin-bottom: 0;
    }
 
    .combo-card__head {
        padding: 28rpx 24rpx 0;
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
    }
 
    .combo-card__title {
        flex: 1;
        font-size: 34rpx;
        font-weight: 600;
        color: #222222;
        line-height: 48rpx;
        padding-right: 20rpx;
    }
 
    .combo-card__status {
        flex-shrink: 0;
        font-size: 30rpx;
        font-weight: 500;
        line-height: 42rpx;
    }
 
    .combo-card__status.is-normal {
        color: #16c7bd;
    }
 
    .combo-card__status.is-invalid {
        color: #ff7a45;
    }
 
    .combo-card__info {
        padding: 0 24rpx;
        margin-top: 14rpx;
        font-size: 28rpx;
        color: #777777;
        line-height: 40rpx;
    }
 
    .combo-card__foot {
        margin-top: 24rpx;
        padding: 24rpx;
        border-top: 1rpx solid #f0f0f0;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
 
    .combo-card__date {
        flex: 1;
        font-size: 28rpx;
        color: #666666;
        line-height: 40rpx;
        padding-right: 20rpx;
    }
 
    .combo-card__price {
        flex-shrink: 0;
        font-size: 36rpx;
        font-weight: 600;
        color: #222222;
        line-height: 1;
    }
 
    .combo-empty {
        padding-top: 160rpx;
        text-align: center;
        font-size: 28rpx;
        color: #999999;
    }
</style>