import React, { useState } from 'react' import { View, Text, Textarea, ScrollView, Radio, RadioGroup, Checkbox, Input } from '@tarojs/components' import Taro from '@tarojs/taro' import { applyAfterSale } from '@/api/shop/shopAfterSale' import type { AfterSaleType } from '@/api/shop/shopAfterSale' definePageConfig({ navigationBarTitleText: '申请售后', }) const AfterSaleApplyPage: React.FC = () => { const params = Taro.getCurrentInstance().router?.params || {} const orderId = params.orderId || '' const [orderGoods, setOrderGoods] = useState>([]) const [saleType, setSaleType] = useState(1) // 1:退款, 2:退货退款, 3:换货 const [submitting, setSubmitting] = useState(false) const [reason, setReason] = useState('') const [amount, setAmount] = useState('') const [description, setDescription] = useState('') const [images, setImages] = useState([]) // 退款原因选项 const refundReasons = ['商品质量问题', '商品与描述不符', '商品破损/缺陷', '物流问题', '其他'] const returnReasons = ['商品质量问题', '商品与描述不符', '商品破损/缺陷', '尺码/颜色不合适', '不喜欢/不想要', '其他'] const exchangeReasons = ['商品质量问题', '商品与描述不符', '商品破损/缺陷', '尺码/颜色不合适', '其他'] // 获取当前原因列表 const getCurrentReasons = () => { if (saleType === 1) return refundReasons if (saleType === 2) return returnReasons return exchangeReasons } // 处理商品选择 const handleGoodsCheck = (id: number) => { setOrderGoods(prev => prev.map(g => g.id === id ? { ...g, checked: !g.checked } : g) ) } // 选择图片 const handleChooseImage = () => { if (images.length >= 6) { Taro.showToast({ title: '最多上传6张图片', icon: 'none' }) return } Taro.chooseImage({ count: 6 - images.length, success: (res) => { setImages(prev => [...prev, ...res.tempFilePaths]) } }) } // 删除图片 const handleDeleteImage = (index: number) => { setImages(prev => prev.filter((_, i) => i !== index)) } // 提交申请 const handleSubmit = () => { const checkedGoods = orderGoods.filter(g => g.checked) if (!reason) { Taro.showToast({ title: '请选择原因', icon: 'none' }) return } if (saleType === 1 && !amount) { Taro.showToast({ title: '请输入退款金额', icon: 'none' }) return } const typeMap: Record = { 1: 'refund', 2: 'return', 3: 'exchange', } Taro.showModal({ title: '确认提交', content: '确定提交售后申请吗?', confirmColor: '#0e932e', success: async (res) => { if (res.confirm) { setSubmitting(true) Taro.showLoading({ title: '提交中...' }) try { await applyAfterSale({ orderId, type: typeMap[saleType], reason, description, amount: saleType === 1 ? Number(amount) : undefined, evidenceImages: images, goodsItems: checkedGoods.map(g => ({ goodsId: String(g.id), quantity: g.num })), }) Taro.hideLoading() Taro.showToast({ title: '提交成功', icon: 'success' }) setTimeout(() => Taro.navigateBack(), 1500) } catch (err: any) { Taro.hideLoading() Taro.showToast({ title: err.message || '提交失败', icon: 'none' }) } finally { setSubmitting(false) } } } }) } return ( {/* 订单商品 */} 选择商品 {orderGoods.map(goods => ( handleGoodsCheck(goods.id)} > 🛍️ {goods.name} ¥{goods.price} × {goods.num} ))} {/* 售后类型 */} 售后类型 setSaleType(parseInt(e.detail.value))}> 仅退款 退货退款 换货 {/* 退款金额 */} {saleType === 1 && ( 退款金额 ¥ setAmount(e.detail.value)} placeholder='请输入退款金额' className='flex-1' /> 最多可退 ¥134.00 )} {/* 售后原因 */} 售后原因 {getCurrentReasons().map((r, index) => ( setReason(r)} > {r} ))} {/* 问题描述 */} 问题描述