Files
device-voice-h5/pages/order-list/order-list.vue
sexygoat dc3a37f60f
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 45s
fix: order-list
2026-04-15 16:22:06 +08:00

226 lines
5.8 KiB
Vue

<template>
<view class="container">
<view class="filter-tabs">
<view
v-for="(item, index) in filterOptions"
:key="index"
class="tab-item"
:class="{ active: filterIndex === index }"
@tap="onFilterChange(index)"
>
{{ item.label }}
</view>
</view>
<view v-if="orderList.length === 0 && !loading" class="empty-state">
<view class="empty-icon">📋</view>
<view class="empty-title">暂无订单</view>
<view class="empty-desc">当前账号下暂无订单信息</view>
</view>
<view v-else class="card order-card" v-for="(item, index) in orderList" :key="index">
<view class="order-header flex-row-sb">
<view class="order-no">{{ item.order_no }}</view>
<view class="tag-apple" :class="getStatusClass(item.payment_status)">{{ item.payment_status_name }}</view>
</view>
<view class="order-info">
<view class="info-row flex-row-sb">
<view class="info-label">下单时间</view>
<view class="info-value">{{ item.created_at }}</view>
</view>
</view>
<view class="divider"></view>
<view class="package-list">
<view class="package-item" v-for="(pkgName, pIndex) in item.package_names" :key="pIndex">
<view class="package-name">{{ pkgName }}</view>
</view>
</view>
<view class="order-footer flex-row-sb">
<view class="total-label">合计</view>
<view class="total-amount">¥{{ formatMoney(item.total_amount) }}</view>
</view>
</view>
<view class="load-more" v-if="orderList.length > 0">
<text v-if="loading">加载中...</text>
<text v-else-if="noMore">没有更多了</text>
<text v-else @tap="loadMore">点击加载更多</text>
</view>
</view>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
import { orderApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
const userStore = useUserStore();
let orderList = reactive([]);
let loading = ref(false);
let noMore = ref(false);
let page = ref(1);
const pageSize = 10;
let filterIndex = ref(0);
let filterOptions = [
{ label: '全部', value: null },
{ label: '待支付', value: 1 },
{ label: '已支付', value: 2 },
{ label: '已取消', value: 3 },
{ label: '已退款', value: 4 }
];
const formatMoney = (amount) => {
if (!amount && amount !== 0) return '0.00';
return (amount / 100).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};
const getStatusClass = (status) => {
const classMap = {
1: 'tag-warning',
2: 'tag-success',
3: 'tag-secondary',
4: 'tag-info'
};
return classMap[status] || '';
};
const onFilterChange = (index) => {
filterIndex.value = index;
page.value = 1;
noMore.value = false;
loadOrderList();
};
const loadOrderList = async (append = false) => {
if (loading.value || noMore.value) return;
loading.value = true;
const paymentStatus = filterOptions[filterIndex.value].value;
try {
const data = await orderApi.getList(
userStore.state.identifier,
page.value,
pageSize,
paymentStatus
);
const newData = (data.items || []).map(item => ({
...item,
payment_status_name: item.payment_status === 1 ? '待支付' : item.payment_status === 2 ? '已支付' : item.payment_status === 3 ? '已取消' : item.payment_status === 4 ? '已退款' : '未知',
created_at: item.created_at ? item.created_at.split('T').join(' ').slice(0, 19) : ''
}));
if (append) {
orderList.push(...newData);
} else {
orderList.splice(0, orderList.length, ...newData);
}
if (newData.length < pageSize) {
noMore.value = true;
} else {
page.value++;
}
} catch (e) {
console.error('加载订单列表失败', e);
}
loading.value = false;
};
const loadMore = () => {
if (!noMore.value) {
loadOrderList(true);
}
};
onMounted(() => {
loadOrderList();
});
</script>
<style lang="scss" scoped>
.container {
.filter-tabs {
display: flex;
padding: var(--space-md) var(--space-lg);
background: var(--bg-card);
border-bottom: 1rpx solid var(--border-light);
.tab-item {
flex: 1;
text-align: center;
font-size: 28rpx;
color: var(--text-secondary);
padding: var(--space-sm) 0;
&.active {
color: var(--primary);
font-weight: 600;
border-bottom: 4rpx solid var(--primary);
}
}
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 40rpx;
min-height: 400rpx;
.empty-icon { font-size: 120rpx; margin-bottom: 30rpx; opacity: 0.6; }
.empty-title { font-size: 32rpx; font-weight: 600; color: var(--text-primary); margin-bottom: 16rpx; }
.empty-desc { font-size: 26rpx; color: var(--text-tertiary); text-align: center; }
}
.order-card {
margin-bottom: var(--space-md);
.order-header {
margin-bottom: var(--space-md);
.order-no { font-size: 28rpx; font-weight: 600; color: var(--text-primary); }
}
.order-info {
.info-row {
padding: var(--space-xs) 0;
.info-label { font-size: 24rpx; color: var(--text-tertiary); }
.info-value { font-size: 24rpx; color: var(--text-primary); }
}
}
.divider {
height: 1rpx;
background: var(--gray-200);
margin: var(--space-md) 0;
}
.package-list {
.package-item {
padding: var(--space-sm) 0;
border-bottom: 1rpx solid var(--gray-100);
&:last-child { border-bottom: none; }
.package-name { font-size: 26rpx; color: var(--text-primary); }
}
}
.order-footer {
margin-top: var(--space-md);
padding-top: var(--space-md);
border-top: 1rpx solid var(--gray-200);
.total-label { font-size: 26rpx; color: var(--text-secondary); }
.total-amount { font-size: 32rpx; font-weight: 700; color: var(--danger); }
}
}
.load-more {
text-align: center;
padding: var(--space-lg);
color: var(--text-tertiary);
font-size: 24rpx;
}
}
</style>