<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>
|