diff --git a/api/request.js b/api/request.js
index 8f90955..357b9aa 100644
--- a/api/request.js
+++ b/api/request.js
@@ -20,7 +20,7 @@ function request(url, method = 'GET', data = {}) {
header,
success(res) {
if (res.data.code) {
- if (res.data.code == 10103) {
+ if (res.data.code == 10103 || res.data.code == 10104) {
wx.removeStorageSync('access_token');
// wx.navigateTo({
// url: '/pages/login/login',
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 8892cd7..0358835 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -500,6 +500,8 @@ export default {
}
.shop-cart {
+
+ color: #fff;
flex: 3;
margin-left: 30rpx;
// color: #fff;
diff --git a/pages/my/index.vue b/pages/my/index.vue
index 5cd1518..f8c14ca 100644
--- a/pages/my/index.vue
+++ b/pages/my/index.vue
@@ -101,31 +101,37 @@
查看全部
-
+
- {{ order.no }}
+ {{ order.order_id || '-' }}
- {{ order.type }}
- {{ order.status }}
+
+ {{ order.statusText }}
- {{ order.date }}
+ {{ order.displayDate }}
- 60x60
+
+
+ 60x60
+
- {{ order.product }}
- {{ order.spec }}
+ {{ order.productName }}
+ {{ order.productSpec }}
@@ -319,41 +325,7 @@ export default {
{ icon: '📄', title: '隐私政策', desc: '查看隐私条款' },
{ icon: '❓', title: '帮助中心', desc: '常见问题解答' }
],
- orders: [
- {
- no: 'ORD20250402001',
- type: '拼团订单',
- status: '已完成',
- statusClass: 'success',
- date: '2025-04-02',
- product: '经典玫瑰香水30ml',
- spec: '¥199 × 1',
- amount: '¥199.00',
- actions: [{ label: '查看详情' }, { label: '再次购买' }]
- },
- {
- no: 'ORD20250401001',
- type: '秒杀订单',
- status: '待收货',
- statusClass: 'warning',
- date: '2025-04-01',
- product: '小样体验包',
- spec: '¥1 × 1',
- amount: '¥1.00',
- actions: [{ label: '查看详情' }]
- },
- {
- no: 'ORD20250328001',
- type: '普通订单',
- status: '待付款',
- statusClass: 'pending',
- date: '2025-03-28',
- product: '薰衣草精油礼盒',
- spec: '¥299 × 1',
- amount: '¥299.00',
- actions: [{ label: '查看详情' }]
- }
- ]
+ orders: []
};
},
computed: {
@@ -381,6 +353,42 @@ export default {
}
},
methods: {
+ async handleOrderAction(action, order) {
+ if (!order) return;
+
+ if (action.label === '查看详情') {
+ const orderId = order.order_id || order.id || order.order_no || order.no;
+ if (!orderId) {
+ console.warn('缺少订单ID,无法跳转详情', order);
+ return;
+ }
+ uni.navigateTo({
+ url: `/pages/order/detail?id=${orderId}`
+ });
+ } else if (action.label === '加入购物车') {
+ const skuList = order.product_list || order.productList || [];
+ if (!Array.isArray(skuList) || !skuList.length) {
+ console.warn('订单中没有商品列表,无法加入购物车', order);
+ return;
+ }
+
+ for (const sku of skuList) {
+ try {
+ await request('xcx/cart', 'POST', {
+ product_id: sku.product_id || order.product_id,
+ sku_id: sku.sku_id,
+ quantity: sku.quantity || 1
+ });
+ } catch (error) {
+ console.error('加入购物车失败', error);
+ }
+ }
+ uni.showToast({
+ title: '已加入购物车',
+ icon: 'success'
+ });
+ }
+ },
handleImageError(e) {
// 图片加载失败时,使用默认头像
console.log('头像加载失败,使用默认头像', e);
@@ -413,60 +421,139 @@ export default {
// 只取前三条
orderList = orderList.slice(0, 3);
+ // 订单状态映射(后端:1待支付 2支付失败 3待发货 4待收货 5已完成 6已取消 7已退款)
+ const statusMap = {
+ // 兼容旧的字符串状态
+ 'pending': { text: '待支付', class: 'pending' },
+ 'paid': { text: '待发货', class: 'warning' },
+ 'shipped': { text: '待收货', class: 'warning' },
+ 'completed': { text: '已完成', class: 'success' },
+ 'cancelled': { text: '已取消', class: 'cancelled' },
+ 'refunded': { text: '已退款', class: 'cancelled' },
+ // 数字状态(你提供的规范)
+ '1': { text: '待支付', class: 'pending' },
+ '2': { text: '支付失败', class: 'cancelled' },
+ '3': { text: '待发货', class: 'warning' },
+ '4': { text: '待收货', class: 'warning' },
+ '5': { text: '已完成', class: 'success' },
+ '6': { text: '已取消', class: 'cancelled' },
+ '7': { text: '已退款', class: 'cancelled' }
+ };
+
+ const formatPrice = (price) => {
+ if (price === null || price === undefined || price === '') return '0.00';
+ const numericPrice = Number(price);
+ if (Number.isNaN(numericPrice)) return '0.00';
+ // if (numericPrice >= 1000 && numericPrice % 100 === 0) {
+ // return (numericPrice / 100).toFixed(2);
+ // }
+ return (numericPrice / 100).toFixed(2);
+ };
+
+ const formatDate = (dateStr) => {
+ if (!dateStr) return '';
+ const date = new Date(dateStr.replace(/-/g, '/'));
+ if (Number.isNaN(date.getTime())) {
+ return dateStr.split(' ')[0] || dateStr;
+ }
+ const year = date.getFullYear();
+ const month = this.padZero(date.getMonth() + 1);
+ const day = this.padZero(date.getDate());
+ return `${year}-${month}-${day}`;
+ };
+
+ const getActions = (status) => {
+ const statusNumber = typeof status === 'number' ? status : parseInt(status, 10);
+
+ // 1: 待支付
+ if (status === 'pending' || statusNumber === 1) {
+ return [{ label: '查看详情' }, { label: '立即付款' }];
+ }
+ // 4: 待收货
+ if (status === 'shipped' || statusNumber === 4) {
+ return [{ label: '查看详情' }, { label: '确认收货' }];
+ }
+ // 5: 已完成
+ if (status === 'completed' || statusNumber === 5) {
+ return [{ label: '查看详情' }, { label: '加入购物车' }];
+ }
+ // 其他状态统一只有「查看详情」
+ return [{ label: '查看详情' }];
+ };
+
+ const getFirstProduct = (order) => {
+ if (Array.isArray(order.product_list) && order.product_list.length) {
+ return order.product_list[0];
+ }
+ if (Array.isArray(order.productList) && order.productList.length) {
+ return order.productList[0];
+ }
+ if (Array.isArray(order.items) && order.items.length) {
+ return order.items[0];
+ }
+ return order || {};
+ };
+
+ const getFirstValidNumber = (...values) => {
+ for (let i = 0; i < values.length; i++) {
+ const value = values[i];
+ if (value !== undefined && value !== null && value !== '') {
+ return value;
+ }
+ }
+ return 0;
+ };
+
// 转换为页面需要的格式
this.orders = orderList.map(order => {
- // 获取第一个商品信息
- const firstItem = (order.items && order.items.length > 0) ? order.items[0] : order;
+ const firstItem = getFirstProduct(order);
+ const orderId = order.order_id || order.orderId || order.order_no || order.no || order.id || '';
- // 格式化状态
- const statusMap = {
- 'pending': { text: '待付款', class: 'pending' },
- 'paid': { text: '待发货', class: 'warning' },
- 'shipped': { text: '待收货', class: 'warning' },
- 'completed': { text: '已完成', class: 'success' },
- 'cancelled': { text: '已取消', class: 'cancelled' },
- 'refunded': { text: '已退款', class: 'cancelled' }
+ // 兼容多种后端状态字段:status / order_status / orderStatus / state / order_state
+ const rawStatus =
+ order.status !== undefined && order.status !== null
+ ? order.status
+ : (order.order_status !== undefined && order.order_status !== null
+ ? order.order_status
+ : (order.orderStatus !== undefined && order.orderStatus !== null
+ ? order.orderStatus
+ : (order.state !== undefined && order.state !== null
+ ? order.state
+ : (order.order_state !== undefined && order.order_state !== null
+ ? order.order_state
+ : ''))));
+ const statusKey = rawStatus !== '' && rawStatus !== undefined && rawStatus !== null ? String(rawStatus) : '';
+ const statusInfo = statusMap[statusKey] || statusMap[rawStatus] || {
+ text: rawStatus === '' || rawStatus === undefined || rawStatus === null ? '未知状态' : String(rawStatus),
+ class: ''
};
- const statusInfo = statusMap[order.status] || { text: order.status || '未知', class: '' };
+ const quantity = firstItem && firstItem.quantity ? firstItem.quantity : (order.quantity || 1);
+ const skuLabel = firstItem && (firstItem.sku_name || firstItem.spec) ? (firstItem.sku_name || firstItem.spec) : '';
+ const specParts = [];
+ if (skuLabel) {
+ specParts.push(skuLabel);
+ }
+ specParts.push(`x${quantity}`);
- // 格式化价格
- const formatPrice = (price) => {
- if (!price && price !== 0) return '0.00';
- if (price < 1000) return parseFloat(price).toFixed(2);
- return (price / 100).toFixed(2);
- };
-
- // 格式化日期
- const formatDate = (dateStr) => {
- if (!dateStr) return '';
- const date = new Date(dateStr);
- const year = date.getFullYear();
- const month = this.padZero(date.getMonth() + 1);
- const day = this.padZero(date.getDate());
- return `${year}-${month}-${day}`;
- };
-
- // 获取操作按钮
- const getActions = (status) => {
- if (status === 'pending') {
- return [{ label: '查看详情' }, { label: '立即付款' }];
- } else if (status === 'shipped') {
- return [{ label: '查看详情' }, { label: '确认收货' }];
- } else if (status === 'completed') {
- return [{ label: '查看详情' }, { label: '再次购买' }];
- }
- return [{ label: '查看详情' }];
- };
+ const amountSource = getFirstValidNumber(
+ order.payable_amount,
+ order.total_amount,
+ order.final_price,
+ order.total_price,
+ order.amount
+ );
return {
- no: order.order_no || order.no || order.id,
- type: order.order_type || '普通订单',
- status: statusInfo.text,
+ ...order,
+ order_id: orderId,
+ typeLabel: (firstItem && firstItem.category_name) || order.order_type || '普通订单',
+ statusText: statusInfo.text,
statusClass: statusInfo.class,
- date: formatDate(order.created_at || order.date),
- product: firstItem.product_name || firstItem.name || order.product_name || '商品',
- spec: firstItem.sku_name || firstItem.spec || `¥${formatPrice(firstItem.price || order.price)} × ${firstItem.quantity || order.quantity || 1}`,
- amount: `¥${formatPrice(order.final_price || order.total_price || order.amount)}`,
+ displayDate: formatDate(order.created_at || order.date),
+ productName: (firstItem && (firstItem.product_name || firstItem.name)) || order.product_name || '商品',
+ productSpec: specParts.join(' · '),
+ productImage: (firstItem && (firstItem.product_main_image_url || firstItem.image_url)) || '',
+ amountText: formatPrice(amountSource),
actions: getActions(order.status)
};
});
@@ -1552,6 +1639,11 @@ export default {
color: #5a3b00;
}
+.order-tag.status.cancelled {
+ background-color: #c9ced8;
+ color: #ffffff;
+}
+
.order-date {
margin-left: auto;
font-size: 24rpx;
@@ -1575,6 +1667,12 @@ export default {
color: #8c94a3;
}
+.order-thumb image {
+ width: 100%;
+ height: 100%;
+ border-radius: 16rpx;
+}
+
.order-info {
display: flex;
flex-direction: column;
diff --git a/pages/order/detail.vue b/pages/order/detail.vue
index 4691f47..f13abfa 100644
--- a/pages/order/detail.vue
+++ b/pages/order/detail.vue
@@ -16,7 +16,7 @@
应付金额
- ¥{{ orderInfo.payableAmount }}
+ ¥{{ formatPrice(orderInfo.payableAmount) }}
@@ -47,7 +47,7 @@
{{ item.skuName }}
{{ item.desc }}
- ¥{{ item.price }}
+ ¥{{ formatPrice(item.price) }}
x{{ item.quantity }}
@@ -93,19 +93,19 @@
商品总额
- ¥{{ orderInfo.originalAmount }}
+ ¥{{ formatPrice(orderInfo.originalAmount) }}
优惠券抵扣
- -¥{{ orderInfo.couponAmount }}
+ -¥{{ formatPrice(orderInfo.couponAmount) }}
积分抵扣({{ orderInfo.pointsUsed }}积分)
- -¥{{ orderInfo.pointsAmount }}
+ -¥{{ formatPrice(orderInfo.pointsAmount) }}
实付金额
- ¥{{ orderInfo.payableAmount }}
+ ¥{{ formatPrice(orderInfo.payableAmount) }}
@@ -137,10 +137,10 @@ const STATUS_META = {
};
const SHIPPING_STATUS_META = {
- 0: '待发货',
- 1: '已发货',
- 2: '运输中',
- 3: '派送中',
+ 1: '待发货',
+ 2: '已发货',
+ 3: '运输中',
+ // 4: '派送中',
4: '已签收'
};
@@ -192,6 +192,19 @@ export default {
this.clearCountdown();
},
methods: {
+ // 格式化价格(分转元)
+ formatPrice(value) {
+ if (!value && value !== 0) {
+ return '0.00';
+ }
+ // 如果已经是元为单位,直接返回
+ // if (value < 1000) {
+ // return parseFloat(value).toFixed(2);
+ // }
+ // 分转换为元
+ value = value / 100;
+ return value.toFixed(2);
+ },
async loadOrderDetail(orderId) {
try {
const res = await request(`xcx/order/${orderId}`, 'get');
diff --git a/pages/order/index.vue b/pages/order/index.vue
index 5419537..9f9854b 100644
--- a/pages/order/index.vue
+++ b/pages/order/index.vue
@@ -163,9 +163,9 @@ export default {
return '0.00';
}
// 如果已经是元为单位,直接返回
- if (value < 1000) {
- return parseFloat(value).toFixed(2);
- }
+ // if (value < 1000) {
+ // return parseFloat(value).toFixed(2);
+ // }
// 分转换为元
value = value / 100;
return value.toFixed(2);