订单页面分页加载的完善

This commit is contained in:
WindowBird 2025-08-25 14:12:27 +08:00
parent 8f2434e592
commit 757777de50
3 changed files with 129 additions and 136 deletions

View File

@ -8,14 +8,14 @@ const loading = ref(false)
const orderId = ref('')
//
onLoad((options) => {
onLoad(options => {
if (options.id) {
orderId.value = options.id
loadOrderDetail()
} else {
uni.showToast({
title: '订单ID不能为空',
icon: 'none'
icon: 'none',
})
setTimeout(() => {
uni.navigateBack()
@ -32,20 +32,20 @@ onLoad((options) => {
function mapOrderStatus(type, value) {
const maps = {
status: {
'1': '未支付',
'2': '支付成功',
'3': '退款',
'未支付': '1',
'支付成功': '2',
'退款': '3',
1: '未支付',
2: '支付成功',
3: '退款',
未支付: '1',
支付成功: '2',
退款: '3',
},
logistic: {
'1': '未签收',
'2': '已签收',
'3': '已归还',
'未签收': '1',
'已签收': '2',
'已归还': '3',
1: '未签收',
2: '已签收',
3: '已归还',
未签收: '1',
已签收: '2',
已归还: '3',
},
}
@ -59,9 +59,9 @@ function mapOrderStatus(type, value) {
*/
function getStatusClass(status) {
const statusMap = {
'1': 'status-pending',
'2': 'status-success',
'3': 'status-refund'
1: 'status-pending',
2: 'status-success',
3: 'status-refund',
}
return statusMap[status] || 'status-unknown'
}
@ -73,9 +73,9 @@ function getStatusClass(status) {
*/
function getLogisticClass(status) {
const statusMap = {
'1': 'logistic-pending',
'2': 'logistic-success',
'3': 'logistic-returned'
1: 'logistic-pending',
2: 'logistic-success',
3: 'logistic-returned',
}
return statusMap[status] || 'logistic-unknown'
}
@ -87,7 +87,7 @@ function getLogisticClass(status) {
*/
function formatTime(timeStr) {
if (!timeStr) return '--'
try {
// iOS "yyyy-MM-dd HH:mm:ss" "yyyy/MM/dd HH:mm:ss"
let normalizedTimeStr = timeStr
@ -95,20 +95,20 @@ function formatTime(timeStr) {
// "2027-08-22 17:17:01" "2027/08/22 17:17:01"
normalizedTimeStr = timeStr.replace(/-/g, '/')
}
const date = new Date(normalizedTimeStr)
//
if (isNaN(date.getTime())) {
return timeStr
}
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}`
} catch (error) {
console.error('时间格式化错误:', error, '原始时间:', timeStr)
@ -121,11 +121,11 @@ function formatTime(timeStr) {
*/
const loadOrderDetail = async () => {
if (!orderId.value) return
try {
loading.value = true
const res = await getOrderDetail(orderId.value)
if (res.code === 200 && res.data) {
orderDetail.value = res.data
console.log('订单详情:', orderDetail.value)
@ -151,14 +151,14 @@ const loadOrderDetail = async () => {
<view v-if="loading" class="loading-container">
<text class="loading-text">正在加载订单详情...</text>
</view>
<!-- 订单详情内容 -->
<view v-else-if="orderDetail" class="detail-content">
<!-- 订单状态卡片 -->
<view class="status-card">
<view class="status-header">
<text class="status-title">订单状态</text>
<text class="status-value" :class="getStatusClass(orderDetail.status)">
<text :class="getStatusClass(orderDetail.status)" class="status-value">
{{ mapOrderStatus('status', orderDetail.status) }}
</text>
</view>
@ -167,7 +167,7 @@ const loadOrderDetail = async () => {
<text class="create-time">创建时间{{ formatTime(orderDetail.createTime) }}</text>
</view>
</view>
<!-- 设备信息卡片 -->
<view class="info-card">
<view class="card-title">
@ -196,7 +196,7 @@ const loadOrderDetail = async () => {
</view>
</view>
</view>
<!-- 用户信息卡片 -->
<view class="info-card">
<view class="card-title">
@ -215,13 +215,13 @@ const loadOrderDetail = async () => {
<text class="label">安装地址</text>
<text class="value">{{ orderDetail.address || '--' }}</text>
</view>
<view class="info-item" v-if="orderDetail.detailed">
<view v-if="orderDetail.detailed" class="info-item">
<text class="label">详细地址</text>
<text class="value">{{ orderDetail.detailed }}</text>
</view>
</view>
</view>
<!-- 支付信息卡片 -->
<view class="info-card">
<view class="card-title">
@ -234,23 +234,23 @@ const loadOrderDetail = async () => {
</view>
<view class="info-item">
<text class="label">支付状态</text>
<text class="value" :class="getStatusClass(orderDetail.status)">
<text :class="getStatusClass(orderDetail.status)" class="value">
{{ mapOrderStatus('status', orderDetail.status) }}
</text>
</view>
<view class="info-item">
<text class="label">物流状态</text>
<text class="value" :class="getLogisticClass(orderDetail.logisticStatus)">
<text :class="getLogisticClass(orderDetail.logisticStatus)" class="value">
{{ mapOrderStatus('logistic', orderDetail.logisticStatus) }}
</text>
</view>
<view class="info-item" v-if="orderDetail.payId">
<view v-if="orderDetail.payId" class="info-item">
<text class="label">支付单号</text>
<text class="value">{{ orderDetail.payId }}</text>
</view>
</view>
</view>
<!-- 其他信息卡片 -->
<view class="info-card">
<view class="card-title">
@ -265,14 +265,14 @@ const loadOrderDetail = async () => {
<text class="label">是否续租</text>
<text class="value">{{ orderDetail.renew ? '是' : '否' }}</text>
</view>
<view class="info-item" v-if="orderDetail.remark">
<view v-if="orderDetail.remark" class="info-item">
<text class="label">备注信息</text>
<text class="value">{{ orderDetail.remark }}</text>
</view>
</view>
</view>
</view>
<!-- 错误状态 -->
<view v-else class="error-container">
<view class="error-icon"></view>
@ -294,7 +294,7 @@ const loadOrderDetail = async () => {
justify-content: center;
align-items: center;
height: 400rpx;
.loading-text {
font-size: 28rpx;
color: #666;
@ -307,18 +307,18 @@ const loadOrderDetail = async () => {
justify-content: center;
align-items: center;
height: 400rpx;
.error-icon {
font-size: 80rpx;
margin-bottom: 20rpx;
}
.error-text {
font-size: 28rpx;
color: #999;
margin-bottom: 30rpx;
}
.retry-btn {
background-color: #007aff;
color: #fff;
@ -331,44 +331,44 @@ const loadOrderDetail = async () => {
.detail-content {
.status-card {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
background: linear-gradient(135deg, #f15a04 0%, #f15a04 100%);
border-radius: 16rpx;
padding: 40rpx 30rpx;
margin-bottom: 20rpx;
color: #fff;
.status-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
.status-title {
font-size: 32rpx;
font-weight: 600;
}
.status-value {
font-size: 26rpx;
padding: 8rpx 16rpx;
border-radius: 20rpx;
background-color: rgba(255, 255, 255, 0.2);
font-weight: 500;
&.status-pending {
background-color: rgba(250, 140, 22, 0.8);
}
&.status-success {
background-color: rgba(82, 196, 26, 0.8);
}
&.status-refund {
background-color: rgba(255, 77, 79, 0.8);
}
}
}
.status-info {
.order-number {
display: block;
@ -376,7 +376,7 @@ const loadOrderDetail = async () => {
margin-bottom: 10rpx;
opacity: 0.9;
}
.create-time {
display: block;
font-size: 24rpx;
@ -384,79 +384,79 @@ const loadOrderDetail = async () => {
}
}
}
.info-card {
background-color: #fff;
border-radius: 16rpx;
margin-bottom: 20rpx;
overflow: hidden;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
.card-title {
background-color: #f8f9fa;
padding: 20rpx 30rpx;
border-bottom: 1rpx solid #f0f0f0;
.title-text {
font-size: 30rpx;
font-weight: 600;
color: #333;
}
}
.card-content {
padding: 30rpx;
.info-item {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 20rpx;
&:last-child {
margin-bottom: 0;
}
.label {
font-size: 28rpx;
color: #666;
min-width: 160rpx;
flex-shrink: 0;
}
.value {
font-size: 28rpx;
color: #333;
flex: 1;
text-align: right;
word-break: break-all;
&.amount {
font-size: 32rpx;
color: #f15a04;
font-weight: bold;
}
&.status-pending {
color: #fa8c16;
}
&.status-success {
color: #52c41a;
}
&.status-refund {
color: #ff4d4f;
}
&.logistic-pending {
color: #fa8c16;
}
&.logistic-success {
color: #52c41a;
}
&.logistic-returned {
color: #1890ff;
}

View File

@ -4,32 +4,32 @@
<view v-if="loading" class="loading-container">
<text class="loading-text">正在加载...</text>
</view>
<!-- 空数据状态 -->
<view v-else-if="list.length === 0 && !loading" class="empty-container">
<view class="empty-icon">📋</view>
<text class="empty-text">暂无订单数据</text>
</view>
<!-- 订单列表 -->
<view v-else>
<view v-for="item in list" :key="item.id" class="order-item" @click="onClick(item)">
<view class="order-header">
<view class="order-title">
<text class="title-text">{{ item.typeName || '订单详情' }}</text>
<text class="status-text" :class="getStatusClass(item.status)">
<text :class="getStatusClass(item.status)" class="status-text">
{{ mapOrderStatus('status', item.status) }}
</text>
</view>
<text class="order-time">{{ formatTime(item.createTime) }}</text>
</view>
<view class="order-content">
<view class="order-info">
<text class="order-id">订单号{{ item.orderNumber || item.id }}</text>
<text class="order-amount">¥{{ item.amount || '0.00' }}</text>
</view>
<view class="order-details">
<view class="detail-item">
<text class="label">租赁套餐</text>
@ -45,14 +45,14 @@
</view>
<view class="detail-item">
<text class="label">物流状态</text>
<text class="value" :class="getLogisticClass(item.logisticStatus)">
<text :class="getLogisticClass(item.logisticStatus)" class="value">
{{ mapOrderStatus('logistic', item.logisticStatus) }}
</text>
</view>
</view>
</view>
</view>
<!-- 加载更多状态 -->
<view v-if="noData && list.length > 0" class="load-more">
<text class="no-more-text">没有更多数据了</text>
@ -79,20 +79,20 @@ const loading = ref(false)
function mapOrderStatus(type, value) {
const maps = {
status: {
'1': '未支付',
'2': '支付成功',
'3': '退款',
'未支付': '1',
'支付成功': '2',
'退款': '3',
1: '未支付',
2: '支付成功',
3: '退款',
未支付: '1',
支付成功: '2',
退款: '3',
},
logistic: {
'1': '未签收',
'2': '已签收',
'3': '已归还',
'未签收': '1',
'已签收': '2',
'已归还': '3',
1: '未签收',
2: '已签收',
3: '已归还',
未签收: '1',
已签收: '2',
已归还: '3',
},
}
@ -106,9 +106,9 @@ function mapOrderStatus(type, value) {
*/
function getStatusClass(status) {
const statusMap = {
'1': 'status-pending',
'2': 'status-success',
'3': 'status-refund'
1: 'status-pending',
2: 'status-success',
3: 'status-refund',
}
return statusMap[status] || 'status-unknown'
}
@ -120,9 +120,9 @@ function getStatusClass(status) {
*/
function getLogisticClass(status) {
const statusMap = {
'1': 'logistic-pending',
'2': 'logistic-success',
'3': 'logistic-returned'
1: 'logistic-pending',
2: 'logistic-success',
3: 'logistic-returned',
}
return statusMap[status] || 'logistic-unknown'
}
@ -134,7 +134,7 @@ function getLogisticClass(status) {
*/
function formatTime(timeStr) {
if (!timeStr) return '--'
try {
// iOS "yyyy-MM-dd HH:mm:ss" "yyyy/MM/dd HH:mm:ss"
let normalizedTimeStr = timeStr
@ -142,20 +142,20 @@ function formatTime(timeStr) {
// "2027-08-22 17:17:01" "2027/08/22 17:17:01"
normalizedTimeStr = timeStr.replace(/-/g, '/')
}
const date = new Date(normalizedTimeStr)
//
if (isNaN(date.getTime())) {
return timeStr
}
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}`
} catch (error) {
console.error('时间格式化错误:', error, '原始时间:', timeStr)
@ -183,7 +183,7 @@ onReachBottom(() => {
//
const getList = async () => {
if (loading.value) return
try {
loading.value = true
let res = await getMyOrder(queryParams)
@ -198,10 +198,10 @@ const getList = async () => {
list.value = [...list.value, ...newData]
}
if (newData.length < queryParams.pageSize) {
if (queryParams.pageNum * queryParams.pageSize >= res.total) {
noData.value = true
}
console.log('订单列表:', list.value)
} catch (error) {
console.error('获取订单列表失败:', error)
@ -215,11 +215,11 @@ const getList = async () => {
}
//
const onClick = (item) => {
const onClick = item => {
console.log('点击订单:', item)
//
uni.navigateTo({
url: `/pages/myOrder/orderDetail?id=${item.id}`
url: `/pages/myOrder/orderDetail?id=${item.id}`,
})
}
@ -244,7 +244,7 @@ onUnload(() => {
justify-content: center;
align-items: center;
height: 200rpx;
.loading-text {
font-size: 28rpx;
color: #666;
@ -257,12 +257,12 @@ onUnload(() => {
justify-content: center;
align-items: center;
height: 400rpx;
.empty-icon {
font-size: 80rpx;
margin-bottom: 20rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
@ -275,7 +275,7 @@ onUnload(() => {
margin-bottom: 20rpx;
padding: 30rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
&:active {
background-color: #f8f8f8;
}
@ -283,47 +283,47 @@ onUnload(() => {
.order-header {
margin-bottom: 20rpx;
.order-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10rpx;
.title-text {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.status-text {
font-size: 24rpx;
padding: 6rpx 12rpx;
border-radius: 20rpx;
font-weight: 500;
&.status-pending {
background-color: #fff7e6;
color: #fa8c16;
}
&.status-success {
background-color: #f6ffed;
color: #52c41a;
}
&.status-refund {
background-color: #fff2f0;
color: #ff4d4f;
}
&.status-unknown {
background-color: #f5f5f5;
color: #999;
}
}
}
.order-time {
font-size: 24rpx;
color: #999;
@ -338,49 +338,49 @@ onUnload(() => {
margin-bottom: 20rpx;
padding-bottom: 15rpx;
border-bottom: 1rpx solid #f0f0f0;
.order-id {
font-size: 26rpx;
color: #666;
}
.order-amount {
font-size: 32rpx;
color: #f15a04;
font-weight: bold;
}
}
.order-details {
.detail-item {
display: flex;
justify-content: space-between;
margin-bottom: 12rpx;
.label {
font-size: 26rpx;
color: #666;
min-width: 140rpx;
}
.value {
font-size: 26rpx;
color: #333;
flex: 1;
text-align: right;
&.logistic-pending {
color: #fa8c16;
}
&.logistic-success {
color: #52c41a;
}
&.logistic-returned {
color: #1890ff;
}
&.logistic-unknown {
color: #999;
}
@ -392,7 +392,7 @@ onUnload(() => {
.load-more {
margin-top: 20rpx;
text-align: center;
.no-more-text {
font-size: 24rpx;
color: #999;

View File

@ -98,13 +98,13 @@
</view>
<text class="function-text">申请代理</text>
</view>
<view class="function-item" @click="goToAgentBenefits">
<view class="function-item" @click="goToMyOrderList">
<view class="function-icon">
<image :src="commonEnum.AGENCY_INTERESTS" class="function-img" mode="aspectFit"></image>
</view>
<text class="function-text">我的订单</text>
</view>
<view class="function-item" @click="goToCustomerService">
<view class="function-item" @click="goToMyOrderList">
<view class="function-icon">
<image
:src="commonEnum.ONLINE_CUSTOMER_SERVICE"
@ -287,16 +287,9 @@ export default {
url: '/pages/agents/agents',
})
},
goToAgentBenefits() {
uni.showToast({
title: '我的订单',
icon: 'none',
})
},
goToCustomerService() {
uni.showToast({
title: '在线客服',
icon: 'none',
goToMyOrderList() {
uni.navigateTo({
url: '/pages/myOrder/myOrder',
})
},
goToIncomeExpense() {