hookehuyr

feat(订单管理): 实现订单删除功能并优化评价提交

refactor: 重构订单列表数据结构和加载逻辑
docs: 添加API接口文档和README说明
style: 移除不必要的padding-bottom样式
# 订单管理 API 接口文档
本文档描述了车辆订单管理相关的API接口使用方法和集成指南。
## 文件结构
```
src/api/
├── orders.js # 订单相关API接口
├── index.js # 通用API接口
├── fn.js # API工具函数
└── README.md # 本文档
```
## 订单API接口 (orders.js)
### 主要功能
- ✅ 获取我的订单列表
- ✅ 获取订单详情
- ✅ 删除订单
- ✅ 取消订单
- ✅ 确认收货
- ✅ 提交评价
- ✅ 申请退款
### 使用示例
#### 1. 删除订单
```javascript
import { deleteOrderAPI } from '@/api/orders'
// 删除订单
const handleDeleteOrder = async (orderId) => {
try {
const response = await deleteOrderAPI({ orderId })
if (response.success) {
console.log('删除成功:', response.message)
// 更新UI状态
}
} catch (error) {
console.error('删除失败:', error.message)
}
}
```
#### 2. 提交评价
```javascript
import { submitReviewAPI } from '@/api/orders'
// 提交评价
const handleSubmitReview = async (orderData) => {
try {
const response = await submitReviewAPI({
orderId: orderData.id,
rating: 5,
comment: '车况很好,推荐!',
images: [] // 可选
})
if (response.success) {
console.log('评价提交成功:', response.message)
}
} catch (error) {
console.error('评价提交失败:', error.message)
}
}
```
## 集成真实API的步骤
### 1. 更新API端点
`orders.js` 文件中,将 `OrderApi` 对象中的端点URL替换为真实的后端API地址:
```javascript
const OrderApi = {
DELETE_ORDER: 'https://your-api-domain.com/api/orders/delete',
SUBMIT_REVIEW: 'https://your-api-domain.com/api/orders/review',
// ... 其他端点
};
```
### 2. 取消注释API调用代码
在页面组件中(如 `myOrders/index.vue`),找到相关方法并取消注释真实API调用的代码:
```javascript
// 在 performDeleteOrder 方法中
const response = await deleteOrderAPI({ orderId })
if (response.success) {
// 处理成功响应
} else {
throw new Error(response.message || '删除失败')
}
```
### 3. 错误处理
确保处理以下常见错误情况:
- 网络连接错误
- 服务器错误 (5xx)
- 客户端错误 (4xx)
- 权限验证失败
- 数据验证失败
### 4. 响应格式标准化
建议后端API返回统一的响应格式:
```javascript
// 成功响应
{
success: true,
message: '操作成功',
data: { /* 具体数据 */ }
}
// 错误响应
{
success: false,
message: '错误描述',
error: {
code: 'ERROR_CODE',
details: '详细错误信息'
}
}
```
## 安全注意事项
1. **权限验证**: 确保用户只能操作自己的订单
2. **数据验证**: 在前端和后端都要进行数据验证
3. **防重复提交**: 避免用户重复提交相同的操作
4. **敏感信息**: 不要在前端暴露敏感的API密钥
5. **HTTPS**: 生产环境必须使用HTTPS协议
## 测试建议
1. **单元测试**: 为每个API方法编写单元测试
2. **集成测试**: 测试API与UI组件的集成
3. **错误场景测试**: 测试网络错误、服务器错误等异常情况
4. **性能测试**: 测试API响应时间和并发处理能力
## 开发模式 vs 生产模式
当前代码支持开发模式(使用模拟数据)和生产模式(使用真实API)的切换:
- **开发模式**: 注释掉真实API调用,使用模拟数据和延迟
- **生产模式**: 取消注释真实API调用,注释掉模拟代码
建议使用环境变量来控制模式切换,例如:
```javascript
const isDevelopment = process.env.NODE_ENV === 'development'
if (isDevelopment) {
// 使用模拟数据
} else {
// 使用真实API
}
```
## 更新日志
- **v1.0.0**: 初始版本,包含基础的订单管理API接口
- 支持删除订单、提交评价等核心功能
- 提供完整的使用示例和集成指南
\ No newline at end of file
/*
* @Date: 2024-01-01 00:00:00
* @LastEditors:
* @LastEditTime: 2024-01-01 00:00:00
* @FilePath: /jgdl/src/api/orders.js
* @Description: 车辆订单相关API接口
*/
import { fn, fetch } from './fn';
// API 端点定义
const OrderApi = {
// 获取我的订单列表
GET_MY_ORDERS: '/api/orders/my-orders',
// 获取订单详情
GET_ORDER_DETAIL: '/api/orders/detail',
// 删除订单
DELETE_ORDER: '/api/orders/delete',
// 取消订单
CANCEL_ORDER: '/api/orders/cancel',
// 确认收货
CONFIRM_ORDER: '/api/orders/confirm',
// 提交评价
SUBMIT_REVIEW: '/api/orders/review',
// 申请退款
REQUEST_REFUND: '/api/orders/refund',
};
/**
* @description: 获取我的订单列表
* @param {Object} params
* @param {string} params.type - 订单类型 'bought' | 'sold'
* @param {number} params.page - 页码
* @param {number} params.limit - 每页数量
* @param {string} params.status - 订单状态筛选(可选)
* @returns {Promise}
*/
export const getMyOrdersAPI = (params) => {
// TODO: 替换为真实的API调用
return fn(fetch.get(OrderApi.GET_MY_ORDERS, params));
};
/**
* @description: 获取订单详情
* @param {Object} params
* @param {string} params.orderId - 订单ID
* @returns {Promise}
*/
export const getOrderDetailAPI = (params) => {
// TODO: 替换为真实的API调用
return fn(fetch.get(OrderApi.GET_ORDER_DETAIL, params));
};
/**
* @description: 删除订单
* @param {Object} params
* @param {string} params.orderId - 订单ID
* @returns {Promise}
*
* @example
* // 使用示例:
* try {
* const response = await deleteOrderAPI({ orderId: 'ORDER_123' });
* if (response.success) {
* console.log('删除成功:', response.message);
* }
* } catch (error) {
* console.error('删除失败:', error.message);
* }
*
* @apiResponse
* {
* success: true,
* message: '订单删除成功',
* data: null
* }
*/
export const deleteOrderAPI = (params) => {
// TODO: 替换为真实的API调用
// 当集成真实API时,请确保:
// 1. 处理网络错误和超时
// 2. 验证用户权限(只能删除自己的订单)
// 3. 检查订单状态(只有特定状态的订单才能删除)
// 4. 返回统一的响应格式
return fn(fetch.delete(OrderApi.DELETE_ORDER, params));
};
/**
* @description: 取消订单
* @param {Object} params
* @param {string} params.orderId - 订单ID
* @param {string} params.reason - 取消原因(可选)
* @returns {Promise}
*/
export const cancelOrderAPI = (params) => {
// TODO: 替换为真实的API调用
return fn(fetch.post(OrderApi.CANCEL_ORDER, params));
};
/**
* @description: 确认收货/完成交易
* @param {Object} params
* @param {string} params.orderId - 订单ID
* @returns {Promise}
*/
export const confirmOrderAPI = (params) => {
// TODO: 替换为真实的API调用
return fn(fetch.post(OrderApi.CONFIRM_ORDER, params));
};
/**
* @description: 提交订单评价
* @param {Object} params
* @param {string} params.orderId - 订单ID
* @param {number} params.rating - 评分 (1-5)
* @param {string} params.comment - 评价内容
* @param {Array} params.images - 评价图片(可选)
* @returns {Promise}
*
* @example
* // 使用示例:
* try {
* const response = await submitReviewAPI({
* orderId: 'ORDER_123',
* rating: 5,
* comment: '车况很好,卖家服务态度也很棒!',
* images: ['image1.jpg', 'image2.jpg'] // 可选
* });
* if (response.success) {
* console.log('评价提交成功:', response.message);
* }
* } catch (error) {
* console.error('评价提交失败:', error.message);
* }
*
* @apiResponse
* {
* success: true,
* message: '评价提交成功',
* data: {
* reviewId: 'REVIEW_123',
* createdAt: '2024-01-01T12:00:00Z'
* }
* }
*/
export const submitReviewAPI = (params) => {
// TODO: 替换为真实的API调用
// 当集成真实API时,请确保:
// 1. 验证评分范围(1-5)
// 2. 验证评价内容长度限制
// 3. 处理图片上传(如果有)
// 4. 检查订单状态(只有已完成的订单才能评价)
// 5. 防止重复评价
return fn(fetch.post(OrderApi.SUBMIT_REVIEW, params));
};
/**
* @description: 申请退款
* @param {Object} params
* @param {string} params.orderId - 订单ID
* @param {string} params.reason - 退款原因
* @param {number} params.amount - 退款金额
* @param {Array} params.evidence - 退款凭证(可选)
* @returns {Promise}
*/
export const requestRefundAPI = (params) => {
// TODO: 替换为真实的API调用
return fn(fetch.post(OrderApi.REQUEST_REFUND, params));
};
// 导出所有API
export default {
getMyOrdersAPI,
getOrderDetailAPI,
deleteOrderAPI,
cancelOrderAPI,
confirmOrderAPI,
submitReviewAPI,
requestRefundAPI,
};
\ No newline at end of file
......@@ -103,7 +103,7 @@
/* 订单列表 */
.order-list {
flex: 1;
padding-bottom: 160rpx;
// padding-bottom: 160rpx;
}
/* 滚动列表 */
......@@ -311,7 +311,7 @@
.rate-score-section {
margin-bottom: 40rpx;
.score-label {
display: block;
font-size: 30rpx;
......@@ -319,18 +319,18 @@
margin-bottom: 20rpx;
font-weight: 500;
}
.rate-stars {
margin-bottom: 16rpx;
}
.score-text {
font-size: 26rpx;
color: #666;
margin-left: 16rpx;
}
}
.rate-input-section {
.input-label {
display: block;
......@@ -339,7 +339,7 @@
margin-bottom: 20rpx;
font-weight: 500;
}
.rate-textarea {
width: 100%;
min-height: 200rpx;
......@@ -348,18 +348,18 @@
padding: 20rpx;
font-size: 28rpx;
line-height: 1.5;
&:focus {
border-color: #ff6b35;
}
&.readonly {
background-color: #f8f9fa;
border-color: #e9ecef;
color: #666;
}
}
.review-date {
display: block;
font-size: 24rpx;
......
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-03 16:56:05
* @LastEditTime: 2025-07-03 17:29:31
* @FilePath: /jgdl/src/pages/myOrders/index.vue
* @Description: 订单管理页面
-->
......@@ -98,8 +98,9 @@
<!-- 已取消状态 -->
<template v-if="order.status === 'cancelled'">
<nut-button type="default" size="small" @click="deleteOrder(order.id)">
删除订单
<nut-button type="default" size="small" @click="deleteOrder(order.id)"
:loading="deletingOrderId === order.id" :disabled="deletingOrderId === order.id">
{{ deletingOrderId === order.id ? '删除中...' : '删除订单' }}
</nut-button>
</template>
</view>
......@@ -270,14 +271,16 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
import { showToast } from '@nutui/nutui-taro'
import Taro from '@tarojs/taro'
// import { deleteOrderAPI, submitReviewAPI } from '@/api/orders' // 预留真实API调用
import './index.less'
import { $ } from '@tarojs/extend'
import payCard from '@/components/payCard.vue'
// NutUI组件已全局注册,无需单独导入Rate
const scrollStyle = ref({
height: 'calc(100vh)'
height: ''
})
// 页面状态
......@@ -305,11 +308,11 @@ const isReadOnlyMode = ref(false)
const showOrderDetailPopup = ref(false)
const currentOrderDetail = ref(null)
// 模拟订单数据
// 模拟订单数据 - 我买的车
const boughtOrders = ref([
{
id: '1',
price: 999,
id: 'B001',
price: 3999,
date: '2023-11-15 14:30',
status: 'pending',
vehicle: {
......@@ -322,74 +325,153 @@ const boughtOrders = ref([
}
},
{
id: '2',
price: 999,
id: 'B002',
price: 5299,
date: '2023-10-28 09:15',
status: 'completed',
vehicle: {
name: '雅迪 G5',
year: '2021年',
name: '雅迪 DE2',
year: '2023年',
mileage: '续航80km',
batteryCapacity: '电池容量:1.2kWh',
price: 2599,
imageUrl: 'https://images.unsplash.com/photo-1558981403-c5f9899a28bc?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
price: 5299,
imageUrl: 'https://images.unsplash.com/photo-1571068316344-75bc76f77890?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
},
// 已评价信息
review: {
rating: 4,
content: '车子质量不错,续航也很给力,卖家服务态度很好,推荐购买!',
date: '2023-10-30 10:20'
content: '车子质量不错,续航也够用,就是充电时间有点长。',
date: '2023-10-30 16:20'
}
},
{
id: '3',
price: 999,
date: '2023-09-05 16:45',
id: 'B003',
price: 2899,
date: '2023-09-20 11:30',
status: 'cancelled',
vehicle: {
name: '绿源 MN5',
name: '台铃 小狮子',
year: '2021年',
mileage: '续航65km',
batteryCapacity: '电池容量:1.0kWh',
price: 2899,
imageUrl: 'https://images.unsplash.com/photo-1544191696-15693072b5a5?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
},
{
id: 'B004',
price: 4599,
date: '2023-08-15 15:45',
status: 'completed',
vehicle: {
name: '九号 E80C',
year: '2023年',
mileage: '续航100km',
batteryCapacity: '电池容量:1.8kWh',
price: 4299,
imageUrl: 'https://images.unsplash.com/photo-1567922045116-2a00fae2ed03?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
mileage: '续航80km',
batteryCapacity: '电池容量:1.44kWh',
price: 4599,
imageUrl: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
},
review: {
rating: 5,
content: '非常满意!车况很好,卖家服务态度也很棒,推荐!',
date: '2023-08-18 10:30'
}
},
{
id: 'B005',
price: 1899,
date: '2023-07-22 13:20',
status: 'pending',
vehicle: {
name: '绿源 MH5',
year: '2020年',
mileage: '续航50km',
batteryCapacity: '电池容量:0.9kWh',
price: 1899,
imageUrl: 'https://images.unsplash.com/photo-1571068316344-75bc76f77890?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
}
])
// 模拟订单数据 - 我卖的车
const soldOrders = ref([
{
id: '4',
price: 999,
date: '2023-11-10 11:20',
id: 'S001',
price: 3200,
date: '2023-11-10 16:45',
status: 'completed',
vehicle: {
name: '爱玛 小蜜豆',
year: '2021年',
mileage: '续航60km',
batteryCapacity: '电池容量:0.8kWh',
price: 3200,
imageUrl: 'https://images.unsplash.com/photo-1544191696-15693072b5a5?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
},
review: {
rating: 5,
content: '买家很爽快,交易很顺利,车子也很满意!',
date: '2023-11-12 14:20'
}
},
{
id: 'S002',
price: 2800,
date: '2023-10-05 10:30',
status: 'pending',
vehicle: {
name: '爱玛 A3',
name: '小刀 长征版',
year: '2022年',
mileage: '续航90km',
batteryCapacity: '电池容量:1.3kWh',
price: 3299,
imageUrl: 'https://images.unsplash.com/photo-1591637333184-19aa84b3e01f?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
mileage: '续航70km',
batteryCapacity: '电池容量:1.1kWh',
price: 2800,
imageUrl: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
},
{
id: '5',
price: 999,
date: '2023-10-15 13:45',
status: 'completed',
id: 'S003',
price: 4200,
date: '2023-09-18 14:15',
status: 'cancelled',
vehicle: {
name: '台铃 战速',
name: '立马 威风',
year: '2023年',
mileage: '续航110km',
mileage: '续航90km',
batteryCapacity: '电池容量:1.6kWh',
price: 3599,
imageUrl: 'https://images.unsplash.com/photo-1558980664-3a031cf67ea8?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
price: 4200,
imageUrl: 'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
},
{
id: 'S004',
price: 1650,
date: '2023-08-28 09:45',
status: 'completed',
vehicle: {
name: '新日 XC1',
year: '2020年',
mileage: '续航45km',
batteryCapacity: '电池容量:0.7kWh',
price: 1650,
imageUrl: 'https://images.unsplash.com/photo-1571068316344-75bc76f77890?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
},
{
id: 'S005',
price: 3800,
date: '2023-07-12 16:20',
status: 'completed',
vehicle: {
name: '哈啰 A80',
year: '2022年',
mileage: '续航85km',
batteryCapacity: '电池容量:1.3kWh',
price: 3800,
imageUrl: 'https://images.unsplash.com/photo-1544191696-15693072b5a5?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
},
// 已评价信息
review: {
rating: 5,
content: '非常满意的一次购买体验,车辆性能超出预期,卖家很专业,物流也很快!',
date: '2023-10-18 16:30'
rating: 4,
content: '车子成色不错,买家也很好沟通,交易愉快!',
date: '2023-07-15 11:30'
}
}
])
......@@ -417,8 +499,9 @@ const filteredOrders = computed(() => {
*/
const setViewMode = (mode) => {
viewMode.value = mode
// 重置列表加载状态
resetListState()
// 重置加载更多的状态
hasMore.value = true
}
/**
......@@ -431,11 +514,13 @@ const setActiveTab = (tab) => {
}
/**
* 重置列表加载状态
* 重置列表状态
*/
const resetListState = () => {
loading.value = false
hasMore.value = true
// 重置加载索引,但不重置已加载的数据
// 这样切换标签时不会重复加载数据,但切换视图模式时会重置
}
/**
......@@ -445,6 +530,107 @@ const scroll = (e) => {
// 可以在这里处理滚动事件
}
// 模拟更多数据池 - 买车订单
const moreBoughtOrders = [
{
id: 'B006',
price: 2299,
date: '2023-06-18 14:30',
status: 'completed',
vehicle: {
name: '小鸟 V1',
year: '2019年',
mileage: '续航55km',
batteryCapacity: '电池容量:0.8kWh',
price: 2299,
imageUrl: 'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
},
review: {
rating: 3,
content: '车子还行,就是电池续航有点短,价格还算合理。',
date: '2023-06-20 09:15'
}
},
{
id: 'B007',
price: 3599,
date: '2023-05-25 16:45',
status: 'cancelled',
vehicle: {
name: '速珂 TC Max',
year: '2022年',
mileage: '续航100km',
batteryCapacity: '电池容量:1.8kWh',
price: 3599,
imageUrl: 'https://images.unsplash.com/photo-1571068316344-75bc76f77890?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
},
{
id: 'B008',
price: 4899,
date: '2023-04-12 11:20',
status: 'pending',
vehicle: {
name: '小牛 NGT',
year: '2023年',
mileage: '续航130km',
batteryCapacity: '电池容量:2.0kWh',
price: 4899,
imageUrl: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
}
]
// 模拟更多数据池 - 卖车订单
const moreSoldOrders = [
{
id: 'S006',
price: 2100,
date: '2023-06-08 13:15',
status: 'completed',
vehicle: {
name: '绿佳 FDT',
year: '2020年',
mileage: '续航50km',
batteryCapacity: '电池容量:0.9kWh',
price: 2100,
imageUrl: 'https://images.unsplash.com/photo-1544191696-15693072b5a5?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
},
{
id: 'S007',
price: 3500,
date: '2023-05-20 10:30',
status: 'pending',
vehicle: {
name: '雅迪 G5 Pro',
year: '2022年',
mileage: '续航85km',
batteryCapacity: '电池容量:1.4kWh',
price: 3500,
imageUrl: 'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
},
{
id: 'S008',
price: 1800,
date: '2023-04-15 15:45',
status: 'cancelled',
vehicle: {
name: '爱玛 麦',
year: '2019年',
mileage: '续航40km',
batteryCapacity: '电池容量:0.6kWh',
price: 1800,
imageUrl: 'https://images.unsplash.com/photo-1571068316344-75bc76f77890?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
}
}
]
// 记录已加载的数据索引
const loadedBoughtIndex = ref(0)
const loadedSoldIndex = ref(0)
/**
* 加载更多数据
*/
......@@ -453,11 +639,37 @@ const loadMore = () => {
loading.value = true
// 模拟加载更多数据
// 模拟加载延迟
setTimeout(() => {
const currentOrders = viewMode.value === 'bought' ? boughtOrders : soldOrders
const moreOrders = viewMode.value === 'bought' ? moreBoughtOrders : moreSoldOrders
const loadedIndex = viewMode.value === 'bought' ? loadedBoughtIndex : loadedSoldIndex
// 每次加载2条数据
const batchSize = 2
const startIndex = loadedIndex.value
const endIndex = Math.min(startIndex + batchSize, moreOrders.length)
if (startIndex < moreOrders.length) {
// 添加新数据
const newOrders = moreOrders.slice(startIndex, endIndex)
currentOrders.value.push(...newOrders)
// 更新已加载索引
if (viewMode.value === 'bought') {
loadedBoughtIndex.value = endIndex
} else {
loadedSoldIndex.value = endIndex
}
// 检查是否还有更多数据
hasMore.value = endIndex < moreOrders.length
} else {
// 没有更多数据了
hasMore.value = false
}
loading.value = false
// 这里可以添加实际的加载更多逻辑
// 如果没有更多数据,设置 hasMore.value = false
}, 1000)
}
......@@ -593,81 +805,159 @@ const closeRatePopup = () => {
*/
const submitRate = async () => {
if (!rateContent.value.trim()) {
Taro.showToast({
showToast({
title: '请输入评价内容',
icon: 'none'
})
return
}
if (rateScore.value < 1 || rateScore.value > 5) {
Taro.showToast({
title: '请选择评分',
icon: 'none'
type: 'fail'
})
return
}
submittingRate.value = true
try {
// 模拟提交评价
await new Promise(resolve => setTimeout(resolve, 1500))
submittingRate.value = true
// 更新订单评价信息
if (currentRateOrder.value) {
const currentDate = new Date()
const dateStr = `${currentDate.getFullYear()}-${String(currentDate.getMonth() + 1).padStart(2, '0')}-${String(currentDate.getDate()).padStart(2, '0')} ${String(currentDate.getHours()).padStart(2, '0')}:${String(currentDate.getMinutes()).padStart(2, '0')}`
// 真实的API调用(当前注释掉,使用模拟数据)
// const response = await submitReviewAPI({
// orderId: currentRateOrder.value.id,
// rating: rateScore.value,
// comment: rateContent.value
// })
// if (response.success) {
// // API提交成功后的处理
// const currentOrders = viewMode.value === 'bought' ? boughtOrders : soldOrders
// const order = currentOrders.value.find(o => o.id === currentRateOrder.value.id)
// if (order) {
// order.review = {
// rating: rateScore.value,
// content: rateContent.value,
// date: new Date().toLocaleString('zh-CN')
// }
// order.status = 'completed'
// }
// showToast({
// title: response.message || '评价提交成功',
// type: 'success'
// })
// closeRatePopup()
// } else {
// throw new Error(response.message || '提交失败')
// }
// 模拟API调用延迟(开发阶段使用)
await new Promise(resolve => setTimeout(resolve, 1500))
currentRateOrder.value.review = {
// 更新本地数据
const currentOrders = viewMode.value === 'bought' ? boughtOrders : soldOrders
const order = currentOrders.value.find(o => o.id === currentRateOrder.value.id)
if (order) {
order.review = {
rating: rateScore.value,
content: rateContent.value,
date: dateStr
date: new Date().toLocaleString('zh-CN')
}
order.status = 'completed'
}
Taro.showToast({
showToast({
title: '评价提交成功',
icon: 'success'
type: 'success'
})
// 关闭弹窗
closeRatePopup()
// TODO: 这里可以添加实际的API调用逻辑
// await api.submitOrderRate({
// orderId: currentRateOrder.value.id,
// rating: rateScore.value,
// content: rateContent.value
// })
} catch (error) {
Taro.showToast({
title: '提交失败,请重试',
icon: 'none'
// console.error('提交评价失败:', error)
showToast({
title: error.message || '提交失败,请重试',
type: 'fail'
})
} finally {
submittingRate.value = false
}
}
// 删除订单相关状态
const deletingOrderId = ref('')
/**
* 删除订单
* @param {string} orderId - 订单ID
*/
const deleteOrder = (orderId) => {
Taro.showModal({
title: '确认删除',
content: '确定要删除这个订单吗?',
success: (res) => {
if (res.confirm) {
// TODO: 实现删除订单逻辑
Taro.showToast({
title: '订单已删除',
icon: 'success'
})
}
const deleteOrder = async (orderId) => {
try {
const result = await Taro.showModal({
title: '确认删除',
content: '确定要删除这个订单吗?删除后无法恢复。',
confirmText: '删除',
cancelText: '取消'
})
if (result.confirm) {
await performDeleteOrder(orderId)
}
})
} catch (error) {
// 用户取消删除或其他错误
// console.log('删除操作被取消或出错:', error)
}
}
/**
* 执行删除订单操作
* @param {string} orderId - 订单ID
*/
const performDeleteOrder = async (orderId) => {
// 设置删除状态,用于显示加载效果
deletingOrderId.value = orderId
try {
// 真实的API调用(当前注释掉,使用模拟数据)
// const response = await deleteOrderAPI({ orderId })
// if (response.success) {
// // API删除成功后的处理
// const orders = viewMode.value === 'bought' ? boughtOrders : soldOrders
// const orderIndex = orders.value.findIndex(order => order.id === orderId)
// if (orderIndex !== -1) {
// orders.value.splice(orderIndex, 1)
// }
// Taro.showToast({
// title: response.message || '订单删除成功',
// icon: 'success',
// duration: 2000
// })
// } else {
// throw new Error(response.message || '删除失败')
// }
// 模拟API调用延迟(开发阶段使用)
await new Promise(resolve => setTimeout(resolve, 1000))
// 从本地数据中移除订单
const orders = viewMode.value === 'bought' ? boughtOrders : soldOrders
const orderIndex = orders.value.findIndex(order => order.id === orderId)
if (orderIndex !== -1) {
orders.value.splice(orderIndex, 1)
Taro.showToast({
title: '订单删除成功',
icon: 'success',
duration: 2000
})
} else {
throw new Error('订单不存在')
}
} catch (error) {
// console.error('删除订单失败:', error)
Taro.showToast({
title: error.message || '删除失败,请重试',
icon: 'none',
duration: 2000
})
} finally {
// 清除删除状态
deletingOrderId.value = ''
}
}
// 页面加载时的初始化
......