HomeLease/pages/myOrder/OrderDetail.vue

485 lines
13 KiB
Vue
Raw Normal View History

2025-08-25 12:01:38 +08:00
<script setup>
import { ref, onMounted } from 'vue'
import { getOrderDetail } from '@/api/order/myOrder.js'
import { onLoad } from '@dcloudio/uni-app'
2025-08-22 15:59:01 +08:00
2025-08-25 12:01:38 +08:00
const orderDetail = ref(null)
const loading = ref(false)
const orderId = ref('')
2025-08-22 15:59:01 +08:00
2025-08-25 12:01:38 +08:00
// 页面加载时获取参数
2025-08-25 14:12:27 +08:00
onLoad(options => {
2025-08-25 12:01:38 +08:00
if (options.id) {
orderId.value = options.id
loadOrderDetail()
} else {
uni.showToast({
title: '订单ID不能为空',
2025-08-25 14:12:27 +08:00
icon: 'none',
2025-08-25 12:01:38 +08:00
})
setTimeout(() => {
uni.navigateBack()
}, 1500)
}
})
/**
* 订单状态/物流状态映射工具
* @param {string} type - 'status'订单状态 'logistic'物流状态
* @param {string|number} value - 状态值数字或中文
* @returns {string|number} 转换后的值
*/
function mapOrderStatus(type, value) {
const maps = {
status: {
2025-08-25 14:12:27 +08:00
1: '未支付',
2: '支付成功',
3: '退款',
未支付: '1',
支付成功: '2',
退款: '3',
2025-08-25 12:01:38 +08:00
},
logistic: {
2025-08-25 14:12:27 +08:00
1: '未签收',
2: '已签收',
3: '已归还',
未签收: '1',
已签收: '2',
已归还: '3',
2025-08-25 12:01:38 +08:00
},
}
return maps[type]?.[value] || '未知状态'
}
/**
* 获取订单状态样式类
* @param {string} status - 状态值
* @returns {string} 样式类名
*/
function getStatusClass(status) {
const statusMap = {
2025-08-25 14:12:27 +08:00
1: 'status-pending',
2: 'status-success',
3: 'status-refund',
2025-08-25 12:01:38 +08:00
}
return statusMap[status] || 'status-unknown'
}
/**
* 获取物流状态样式类
* @param {string} status - 状态值
* @returns {string} 样式类名
*/
function getLogisticClass(status) {
const statusMap = {
2025-08-25 14:12:27 +08:00
1: 'logistic-pending',
2: 'logistic-success',
3: 'logistic-returned',
2025-08-25 12:01:38 +08:00
}
return statusMap[status] || 'logistic-unknown'
}
/**
* 格式化时间
* @param {string} timeStr - 时间字符串
* @returns {string} 格式化后的时间
*/
function formatTime(timeStr) {
if (!timeStr) return '--'
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
try {
// 处理iOS兼容性问题将 "yyyy-MM-dd HH:mm:ss" 转换为 "yyyy/MM/dd HH:mm:ss"
let normalizedTimeStr = timeStr
if (typeof timeStr === 'string' && timeStr.includes('-') && timeStr.includes(' ')) {
// 将 "2027-08-22 17:17:01" 转换为 "2027/08/22 17:17:01"
normalizedTimeStr = timeStr.replace(/-/g, '/')
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
const date = new Date(normalizedTimeStr)
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
// 检查日期是否有效
if (isNaN(date.getTime())) {
return timeStr
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
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')
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
return `${year}-${month}-${day} ${hours}:${minutes}`
} catch (error) {
console.error('时间格式化错误:', error, '原始时间:', timeStr)
return timeStr
}
}
/**
* 加载订单详情
*/
const loadOrderDetail = async () => {
if (!orderId.value) return
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
try {
loading.value = true
const res = await getOrderDetail(orderId.value)
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
if (res.code === 200 && res.data) {
orderDetail.value = res.data
console.log('订单详情:', orderDetail.value)
} else {
throw new Error(res.msg || '获取订单详情失败')
}
} catch (error) {
console.error('获取订单详情失败:', error)
uni.showToast({
title: error.message || '获取订单详情失败',
icon: 'none',
})
orderDetail.value = null
} finally {
loading.value = false
}
}
</script>
<template>
<view class="container">
<!-- 加载状态 -->
<view v-if="loading" class="loading-container">
<text class="loading-text">正在加载订单详情...</text>
</view>
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
<!-- 订单详情内容 -->
<view v-else-if="orderDetail" class="detail-content">
<!-- 订单状态卡片 -->
<view class="status-card">
<view class="status-header">
<text class="status-title">订单状态</text>
2025-08-25 14:12:27 +08:00
<text :class="getStatusClass(orderDetail.status)" class="status-value">
2025-08-25 12:01:38 +08:00
{{ mapOrderStatus('status', orderDetail.status) }}
</text>
</view>
<view class="status-info">
<text class="order-number">订单号{{ orderDetail.orderNumber }}</text>
<text class="create-time">创建时间{{ formatTime(orderDetail.createTime) }}</text>
</view>
</view>
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
<!-- 设备信息卡片 -->
<view class="info-card">
<view class="card-title">
<text class="title-text">设备信息</text>
</view>
<view class="card-content">
<view class="info-item">
<text class="label">设备类型</text>
<text class="value">{{ orderDetail.typeName }}</text>
</view>
<view class="info-item">
<text class="label">租赁套餐</text>
<text class="value">{{ orderDetail.suitName }}</text>
</view>
<view class="info-item">
<text class="label">租赁天数</text>
<text class="value">{{ orderDetail.suitDay }}</text>
</view>
<view class="info-item">
<text class="label">租赁时间</text>
<text class="value">{{ formatTime(orderDetail.leaseTime) }}</text>
</view>
<view class="info-item">
<text class="label">到期时间</text>
<text class="value">{{ formatTime(orderDetail.expirationTime) }}</text>
</view>
</view>
</view>
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
<!-- 用户信息卡片 -->
<view class="info-card">
<view class="card-title">
<text class="title-text">用户信息</text>
</view>
<view class="card-content">
<view class="info-item">
<text class="label">用户姓名</text>
<text class="value">{{ orderDetail.name || '--' }}</text>
</view>
<view class="info-item">
<text class="label">联系电话</text>
<text class="value">{{ orderDetail.phone || '--' }}</text>
</view>
<view class="info-item">
<text class="label">安装地址</text>
<text class="value">{{ orderDetail.address || '--' }}</text>
</view>
2025-08-25 14:12:27 +08:00
<view v-if="orderDetail.detailed" class="info-item">
2025-08-25 12:01:38 +08:00
<text class="label">详细地址</text>
<text class="value">{{ orderDetail.detailed }}</text>
</view>
</view>
</view>
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
<!-- 支付信息卡片 -->
<view class="info-card">
<view class="card-title">
<text class="title-text">支付信息</text>
</view>
<view class="card-content">
<view class="info-item">
<text class="label">订单金额</text>
<text class="value amount">¥{{ orderDetail.amount?.toFixed(2) || '0.00' }}</text>
</view>
<view class="info-item">
<text class="label">支付状态</text>
2025-08-25 14:12:27 +08:00
<text :class="getStatusClass(orderDetail.status)" class="value">
2025-08-25 12:01:38 +08:00
{{ mapOrderStatus('status', orderDetail.status) }}
</text>
</view>
2025-09-11 08:52:24 +08:00
<!-- <view class="info-item">-->
<!-- <text class="label">物流状态</text>-->
<!-- <text :class="getLogisticClass(orderDetail.logisticStatus)" class="value">-->
<!-- {{ mapOrderStatus('logistic', orderDetail.logisticStatus) }}-->
<!-- </text>-->
<!-- </view>-->
2025-08-25 14:12:27 +08:00
<view v-if="orderDetail.payId" class="info-item">
2025-08-25 12:01:38 +08:00
<text class="label">支付单号</text>
<text class="value">{{ orderDetail.payId }}</text>
</view>
</view>
</view>
2025-08-25 14:12:27 +08:00
<view class="info-card">
<view class="card-title">
<text class="title-text">配送师傅信息</text>
</view>
<view class="card-content">
<view class="info-item">
<text class="label">师傅姓名</text>
<text class="value">{{ orderDetail.maserName }}</text>
</view>
<view class="info-item">
<text class="label">师傅电话</text>
<text class="value">{{ orderDetail.maserPhone }}</text>
</view>
</view>
</view>
2025-08-25 12:01:38 +08:00
<!-- 其他信息卡片 -->
<view class="info-card">
<view class="card-title">
<text class="title-text">其他信息</text>
</view>
<view class="card-content">
<view class="info-item">
<text class="label">应用名称</text>
<text class="value">{{ orderDetail.appName || '--' }}</text>
</view>
<view class="info-item">
<text class="label">是否续租</text>
<text class="value">{{ orderDetail.renew ? '是' : '否' }}</text>
</view>
2025-08-25 14:12:27 +08:00
<view v-if="orderDetail.remark" class="info-item">
2025-08-25 12:01:38 +08:00
<text class="label">备注信息</text>
<text class="value">{{ orderDetail.remark }}</text>
</view>
</view>
</view>
</view>
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
<!-- 错误状态 -->
<view v-else class="error-container">
<view class="error-icon"></view>
<text class="error-text">订单详情加载失败</text>
<button class="retry-btn" @click="loadOrderDetail">重新加载</button>
</view>
</view>
</template>
<style lang="scss" scoped>
.container {
min-height: 100vh;
background-color: #f5f5f5;
padding: 20rpx;
}
.loading-container {
display: flex;
justify-content: center;
align-items: center;
height: 400rpx;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.loading-text {
font-size: 28rpx;
color: #666;
}
}
.error-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 400rpx;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.error-icon {
font-size: 80rpx;
margin-bottom: 20rpx;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.error-text {
font-size: 28rpx;
color: #999;
margin-bottom: 30rpx;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.retry-btn {
background-color: #007aff;
color: #fff;
border: none;
border-radius: 8rpx;
padding: 20rpx 40rpx;
font-size: 28rpx;
}
}
.detail-content {
.status-card {
2025-08-25 14:12:27 +08:00
background: linear-gradient(135deg, #f15a04 0%, #f15a04 100%);
2025-08-25 12:01:38 +08:00
border-radius: 16rpx;
padding: 40rpx 30rpx;
margin-bottom: 20rpx;
color: #fff;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.status-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.status-title {
font-size: 32rpx;
font-weight: 600;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.status-value {
font-size: 26rpx;
padding: 8rpx 16rpx;
border-radius: 20rpx;
background-color: rgba(255, 255, 255, 0.2);
font-weight: 500;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.status-pending {
background-color: rgba(250, 140, 22, 0.8);
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.status-success {
background-color: rgba(82, 196, 26, 0.8);
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.status-refund {
background-color: rgba(255, 77, 79, 0.8);
}
}
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.status-info {
.order-number {
display: block;
font-size: 26rpx;
margin-bottom: 10rpx;
opacity: 0.9;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.create-time {
display: block;
font-size: 24rpx;
opacity: 0.8;
}
}
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.info-card {
background-color: #fff;
border-radius: 16rpx;
margin-bottom: 20rpx;
overflow: hidden;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.card-title {
background-color: #f8f9fa;
padding: 20rpx 30rpx;
border-bottom: 1rpx solid #f0f0f0;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.title-text {
font-size: 30rpx;
font-weight: 600;
color: #333;
}
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.card-content {
padding: 30rpx;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.info-item {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 20rpx;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&:last-child {
margin-bottom: 0;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.label {
font-size: 28rpx;
color: #666;
min-width: 160rpx;
flex-shrink: 0;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
.value {
font-size: 28rpx;
color: #333;
flex: 1;
text-align: right;
word-break: break-all;
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.amount {
font-size: 32rpx;
color: #f15a04;
font-weight: bold;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.status-pending {
color: #fa8c16;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.status-success {
color: #52c41a;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.status-refund {
color: #ff4d4f;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.logistic-pending {
color: #fa8c16;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.logistic-success {
color: #52c41a;
}
2025-08-25 14:12:27 +08:00
2025-08-25 12:01:38 +08:00
&.logistic-returned {
color: #1890ff;
}
}
}
}
}
}
</style>