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
<template>
    <view class="groupbuy-order" :data-theme='theme()'>
        <view class="order-tabs">
            <view class="tab-item" 
                  v-for="(tab, index) in tabs" 
                  :key="index"
                  :class="{ active: activeTab === index }"
                  @click="switchTab(index)">
                <text class="tab-text">{{ tab.name }}</text>
                <text v-if="tab.count > 0" class="tab-badge">{{ tab.count }}</text>
            </view>
        </view>
        
        <view class="order-list">
            <view class="order-item" v-for="(order, index) in orderList" :key="index">
                <view class="order-header">
                    <text class="order-id">订单号:{{ order.order_no }}</text>
                    <text class="order-status" :class="'status-' + order.status">{{ order.statusText }}</text>
                </view>
                
                <view class="order-product" @click="goToProduct(order.product_id)">
                    <image :src="order.product_image" class="product-image" mode="aspectFill"></image>
                    <view class="product-info">
                        <view class="product-name">{{ order.product_name }}</view>
                        <view class="product-spec">{{ order.spec_info }}</view>
                        <view class="product-price">
                            <text class="price">¥{{ order.price }}</text>
                            <text class="quantity">x{{ order.quantity }}</text>
                        </view>
                    </view>
                </view>
                
                <view class="order-summary">
                    <view class="summary-item">
                        <text class="label">共{{ order.quantity }}件商品</text>
                        <text class="value">合计:¥{{ order.total_price }}</text>
                    </view>
                </view>
                
                <view class="order-actions" v-if="order.status === 0">
                    <button class="btn-cancel" @click="cancelOrder(order.order_id)">取消订单</button>
                    <button class="btn-pay" @click="payOrder(order.order_id)">立即支付</button>
                </view>
                <view class="order-actions" v-else-if="order.status === 1">
                    <button class="btn-view" @click="viewGroupProgress(order.order_id)">查看团购进度</button>
                </view>
            </view>
        </view>
        
        <view class="empty-state" v-if="orderList.length === 0">
            <text class="empty-text">暂无{{ tabs[activeTab].name }}订单</text>
        </view>
    </view>
</template>
 
<script>
export default {
    data() {
        return {
            activeTab: 0,
            tabs: [
                { name: '全部', count: 0, status: null },
                { name: '待支付', count: 0, status: 0 },
                { name: '团购中', count: 0, status: 1 },
                { name: '已完成', count: 0, status: 2 },
                { name: '已取消', count: 0, status: -1 }
            ],
            orderList: [],
            page: 1,
            hasMore: true
        };
    },
    onLoad() {
        this.loadOrderList();
    },
    onReachBottom() {
        if (this.hasMore) {
            this.loadMore();
        }
    },
    methods: {
        switchTab(index) {
            this.activeTab = index;
            this.page = 1;
            this.orderList = [];
            this.loadOrderList();
        },
        loadOrderList() {
            const status = this.tabs[this.activeTab].status;
            
            this._get('plus.groupbuy.bill/userBills', {
                status: status,
                page: this.page,
                list_rows: 10
            }, (res) => {
                const orders = res.data.list.data || [];
                
                // 格式化订单数据
                const formattedOrders = orders.map(order => {
                    return {
                        ...order,
                        statusText: this.getStatusText(order.status),
                        product_image: order.product?.product?.image?.[0]?.file_path || '',
                        product_name: order.product?.product?.product_name || '',
                        product_id: order.product?.product?.product_id || 0
                    };
                });
                
                this.orderList = [...this.orderList, ...formattedOrders];
                this.hasMore = res.data.list.current_page < res.data.list.last_page;
            });
        },
        loadMore() {
            this.page++;
            this.loadOrderList();
        },
        getStatusText(status) {
            const statusMap = {
                -1: '已取消',
                0: '待支付',
                1: '团购中',
                2: '已完成'
            };
            return statusMap[status] || '未知状态';
        },
        goToProduct(productId) {
            this.gotoPage(`/pages/product/detail/detail?product_id=${productId}`);
        },
        cancelOrder(orderId) {
            uni.showModal({
                title: '确认取消',
                content: '确定要取消这个订单吗?',
                success: (res) => {
                    if (res.confirm) {
                        // 取消订单逻辑
                        this._post('order.cancel/cancel', {
                            order_id: orderId
                        }, (res) => {
                            uni.showToast({
                                title: '订单已取消',
                                icon: 'success'
                            });
                            this.refreshList();
                        });
                    }
                }
            });
        },
        payOrder(orderId) {
            // 跳转到支付页面
            this.gotoPage(`/pages/order/pay-h5/pay-h5?order_id=${orderId}`);
        },
        viewGroupProgress(orderId) {
            // 查看团购进度
            this._get('plus.groupbuy.bill/detail', {
                groupbuy_bill_id: orderId
            }, (res) => {
                const billDetail = res.data.bill;
                uni.showModal({
                    title: '团购进度',
                    content: `当前参团人数:${billDetail.actual_people}/${billDetail.groupbuy_num}人`,
                    showCancel: false
                });
            });
        },
        refreshList() {
            this.page = 1;
            this.orderList = [];
            this.loadOrderList();
        }
    }
};
</script>
 
<style lang="scss">
.groupbuy-order {
    background: #f5f5f5;
    min-height: 100vh;
    padding-top: 20rpx;
    
    .order-tabs {
        display: flex;
        background: #fff;
        position: sticky;
        top: 0;
        z-index: 10;
        
        .tab-item {
            flex: 1;
            text-align: center;
            padding: 30rpx 0;
            position: relative;
            
            .tab-text {
                font-size: 28rpx;
                color: #666;
            }
            
            .tab-badge {
                position: absolute;
                top: 15rpx;
                right: 30rpx;
                background: #e74748;
                color: #fff;
                font-size: 20rpx;
                border-radius: 20rpx;
                padding: 4rpx 10rpx;
                min-width: 30rpx;
                text-align: center;
                line-height: 1;
            }
            
            &.active {
                .tab-text {
                    color: #e74748;
                    font-weight: bold;
                }
                
                &::after {
                    content: '';
                    position: absolute;
                    bottom: 0;
                    left: 50%;
                    transform: translateX(-50%);
                    width: 60rpx;
                    height: 6rpx;
                    background: #e74748;
                    border-radius: 3rpx;
                }
            }
        }
    }
    
    .order-list {
        padding: 20rpx;
        
        .order-item {
            background: #fff;
            border-radius: 20rpx;
            margin-bottom: 20rpx;
            overflow: hidden;
            
            .order-header {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 30rpx;
                border-bottom: 1rpx solid #f0f0f0;
                
                .order-id {
                    font-size: 26rpx;
                    color: #666;
                }
                
                .order-status {
                    font-size: 24rpx;
                    color: #e74748;
                    padding: 5rpx 15rpx;
                    border: 1rpx solid #e74748;
                    border-radius: 20rpx;
                    
                    &.status--1 {
                        color: #999;
                        border-color: #999;
                    }
                    
                    &.status-2 {
                        color: #19be6b;
                        border-color: #19be6b;
                    }
                }
            }
            
            .order-product {
                display: flex;
                padding: 30rpx;
                cursor: pointer;
                
                .product-image {
                    width: 180rpx;
                    height: 180rpx;
                    border-radius: 10rpx;
                    margin-right: 20rpx;
                }
                
                .product-info {
                    flex: 1;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    
                    .product-name {
                        font-size: 28rpx;
                        color: #333;
                        margin-bottom: 10rpx;
                    }
                    
                    .product-spec {
                        font-size: 24rpx;
                        color: #999;
                        margin-bottom: 10rpx;
                    }
                    
                    .product-price {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        
                        .price {
                            font-size: 32rpx;
                            color: #e74748;
                            font-weight: bold;
                        }
                        
                        .quantity {
                            font-size: 24rpx;
                            color: #999;
                        }
                    }
                }
            }
            
            .order-summary {
                padding: 0 30rpx 30rpx;
                border-top: 1rpx solid #f0f0f0;
                
                .summary-item {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    padding: 20rpx 0;
                    
                    .label {
                        font-size: 24rpx;
                        color: #999;
                    }
                    
                    .value {
                        font-size: 26rpx;
                        color: #333;
                        font-weight: bold;
                    }
                }
            }
            
            .order-actions {
                display: flex;
                justify-content: flex-end;
                padding: 20rpx 30rpx;
                border-top: 1rpx solid #f0f0f0;
                
                button {
                    height: 60rpx;
                    line-height: 60rpx;
                    padding: 0 30rpx;
                    border-radius: 30rpx;
                    font-size: 24rpx;
                    margin-left: 20rpx;
                    border: none;
                }
                
                .btn-cancel {
                    background: #f0f0f0;
                    color: #666;
                }
                
                .btn-pay {
                    background: linear-gradient(to right, #e74748, #f17a5f);
                    color: #fff;
                }
                
                .btn-view {
                    background: #f0f0f0;
                    color: #666;
                }
            }
        }
    }
    
    .empty-state {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 200rpx 0;
        
        .empty-text {
            font-size: 28rpx;
            color: #999;
        }
    }
}
</style>