diff --git a/config/env.ts b/config/env.ts index c92883b..152eae3 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,7 +2,8 @@ export const ENV_CONFIG = { // 开发环境 development: { - API_BASE_URL: 'https://cms-api.websoft.top/api', + API_BASE_URL: 'http://127.0.0.1:9200/api', + // API_BASE_URL: 'https://cms-api.websoft.top/api', APP_NAME: '开发环境', DEBUG: 'true', }, diff --git a/src/api/afterSale.ts b/src/api/afterSale.ts index e285647..faf03f5 100644 --- a/src/api/afterSale.ts +++ b/src/api/afterSale.ts @@ -117,7 +117,7 @@ export const STATUS_COLOR_MAP = { // 申请售后 export const applyAfterSale = async (params: AfterSaleApplyParams): Promise => { try { - const response = await request({ + const response = await request({ url: '/api/after-sale/apply', method: 'POST', data: params @@ -136,7 +136,7 @@ export const getAfterSaleDetail = async (params: { afterSaleId?: string }): Promise => { try { - const response = await request({ + const response = await request({ url: '/api/after-sale/detail', method: 'GET', data: params @@ -154,7 +154,7 @@ export const getAfterSaleDetail = async (params: { // 查询售后列表 export const getAfterSaleList = async (params: AfterSaleListParams): Promise => { try { - const response = await request({ + const response = await request({ url: '/api/after-sale/list', method: 'GET', data: params @@ -170,7 +170,7 @@ export const getAfterSaleList = async (params: AfterSaleListParams): Promise => { try { - const response = await request({ + const response = await request<{ success: boolean; message?: string }>({ url: '/api/after-sale/cancel', method: 'POST', data: { afterSaleId } @@ -312,11 +312,9 @@ export const getAfterSaleSteps = (type: AfterSaleType, status: AfterSaleStatus) // 根据类型调整步骤 if (type === 'return' || type === 'exchange') { - baseSteps.splice(2, 1, - { title: '寄回商品', description: '请将商品寄回指定地址' }, - { title: '处理中', description: '收到商品,正在处理' } - ) + baseSteps.splice(2, 0, { title: '等待收货', description: '等待用户寄回商品' }) + baseSteps.splice(3, 0, { title: '确认收货', description: '商家确认收到退回商品' }) } return baseSteps -} +} \ No newline at end of file diff --git a/src/shop/orderDetail/index.tsx b/src/shop/orderDetail/index.tsx index c51595e..7bb5b00 100644 --- a/src/shop/orderDetail/index.tsx +++ b/src/shop/orderDetail/index.tsx @@ -40,6 +40,33 @@ const OrderDetail = () => { } }; + // 申请退款 + const handleApplyRefund = async () => { + if (order) { + try { + // 更新订单状态为"退款申请中" + await updateShopOrder({ + orderId: order.orderId, + orderStatus: 4 // 退款申请中 + }); + + // 更新本地状态 + setOrder(prev => prev ? {...prev, orderStatus: 4} : null); + + // 跳转到退款申请页面 + Taro.navigateTo({ + url: `/user/order/refund/index?orderId=${order.orderId}&orderNo=${order.orderNo}` + }); + } catch (error) { + console.error('更新订单状态失败:', error); + Taro.showToast({ + title: '操作失败,请重试', + icon: 'none' + }); + } + } + }; + const getOrderStatusText = (order: ShopOrder) => { // 优先检查订单状态 if (order.orderStatus === 2) return '已取消'; @@ -162,7 +189,7 @@ const OrderDetail = () => { {!order.payStatus && } {!order.payStatus && } - {order.orderStatus === 1 && } + {order.orderStatus === 1 && } {order.deliveryStatus === 20 && } diff --git a/src/user/order/components/OrderList.tsx b/src/user/order/components/OrderList.tsx index b7d9015..4ec73fe 100644 --- a/src/user/order/components/OrderList.tsx +++ b/src/user/order/components/OrderList.tsx @@ -316,11 +316,30 @@ function OrderList(props: OrderListProps) { }; // 申请退款 (待发货状态) - const applyRefund = (order: ShopOrder) => { - // 跳转到退款申请页面 - Taro.navigateTo({ - url: `/user/order/refund/index?orderId=${order.orderId}&orderNo=${order.orderNo}` - }); + const applyRefund = async (order: ShopOrder) => { + try { + // 更新订单状态为"退款申请中" + await updateShopOrder({ + orderId: order.orderId, + orderStatus: 4 // 退款申请中 + }); + + // 更新本地状态 + setDataSource(prev => prev.map(item => + item.orderId === order.orderId ? {...item, orderStatus: 4} : item + )); + + // 跳转到退款申请页面 + Taro.navigateTo({ + url: `/user/order/refund/index?orderId=${order.orderId}&orderNo=${order.orderNo}` + }); + } catch (error) { + console.error('更新订单状态失败:', error); + Taro.showToast({ + title: '操作失败,请重试', + icon: 'none' + }); + } }; // 查看物流 (待收货状态) @@ -738,12 +757,12 @@ function OrderList(props: OrderListProps) { )} {/* 待发货状态:显示申请退款 */} - {/*{item.payStatus && item.deliveryStatus === 10 && item.orderStatus !== 2 && item.orderStatus !== 4 && (*/} - {/* */} - {/*)}*/} + {item.payStatus && item.deliveryStatus === 10 && item.orderStatus !== 2 && item.orderStatus !== 4 && ( + + )} {/* 待收货状态:显示查看物流和确认收货 */} {item.deliveryStatus === 20 && item.orderStatus !== 2 && ( @@ -770,10 +789,10 @@ function OrderList(props: OrderListProps) { {/* e.stopPropagation();*/} {/* evaluateGoods(item);*/} {/*}}>评价商品*/} - {/**/} + )} diff --git a/src/user/order/refund/index.tsx b/src/user/order/refund/index.tsx index da16d92..b484c09 100644 --- a/src/user/order/refund/index.tsx +++ b/src/user/order/refund/index.tsx @@ -13,6 +13,8 @@ import { Empty, InputNumber } from '@nutui/nutui-react-taro' +import { applyAfterSale } from '@/api/afterSale' +import { updateShopOrder } from '@/api/shop/shopOrder' import './index.scss' // 订单商品信息 @@ -232,23 +234,55 @@ const RefundPage: React.FC = () => { setSubmitting(true) - // 模拟API调用 - await new Promise(resolve => setTimeout(resolve, 2000)) + // 构造请求参数 + const params = { + orderId: orderId || '', + type: 'refund' as const, + reason: refundApp.refundReason, + description: refundApp.refundDescription, + amount: refundApp.refundAmount, + contactPhone: refundApp.contactPhone, + evidenceImages: refundApp.evidenceImages, + goodsItems: refundApp.refundGoods.filter(item => item.refundNum > 0).map(item => ({ + goodsId: item.goodsId, + quantity: item.refundNum + })) + } - Taro.showToast({ - title: '退款申请提交成功', - icon: 'success' - }) + // 调用API提交退款申请 + const result = await applyAfterSale(params) + + if (result.success) { + // 更新订单状态为"退款申请中" + if (orderId) { + try { + await updateShopOrder({ + orderId: parseInt(orderId), + orderStatus: 4 // 退款申请中 + }) + } catch (updateError) { + console.error('更新订单状态失败:', updateError) + // 即使更新订单状态失败,也继续执行后续操作 + } + } - // 延迟返回上一页 - setTimeout(() => { - Taro.navigateBack() - }, 1500) + Taro.showToast({ + title: '退款申请提交成功', + icon: 'success' + }) + + // 延迟返回上一页 + setTimeout(() => { + Taro.navigateBack() + }, 1500) + } else { + throw new Error(result.message || '提交失败') + } } catch (error) { console.error('提交退款申请失败:', error) Taro.showToast({ - title: '提交失败,请重试', + title: error instanceof Error ? error.message : '提交失败,请重试', icon: 'none' }) } finally { @@ -420,4 +454,4 @@ const RefundPage: React.FC = () => { ) } -export default RefundPage +export default RefundPage \ No newline at end of file