import React, { useState, useEffect } from 'react' import { View, Text, ScrollView, Image } from '@tarojs/components' import Taro from '@tarojs/taro' import { getShopEvaluation, likeShopEvaluation } from '@/api/shop/shopEvaluation' import type { ShopEvaluation } from '@/api/shop/shopEvaluation/model' definePageConfig({ navigationBarTitleText: '评价详情', }) const EvaluateDetailPage: React.FC = () => { const { id } = Taro.getCurrentInstance().router?.params || {} const [evaluation, setEvaluation] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { if (id) { fetchDetail(Number(id)) } }, [id]) const fetchDetail = async (evalId: number) => { try { const data = await getShopEvaluation(evalId) setEvaluation(data) } catch (err: any) { Taro.showToast({ title: err.message || '加载失败', icon: 'none' }) } finally { setLoading(false) } } // 渲染星星 const renderStars = (score: number) => { const stars = [] for (let i = 1; i <= 5; i++) { stars.push( ) } return stars } // 处理点赞 const handleLike = async () => { if (!evaluation) return try { await likeShopEvaluation({ evaluationId: evaluation.id, isLiked: !evaluation.isLiked }) setEvaluation(prev => prev ? { ...prev, isLiked: !prev.isLiked, likes: prev.isLiked ? prev.likes - 1 : prev.likes + 1, } : prev) } catch (err: any) { Taro.showToast({ title: err.message || '操作失败', icon: 'none' }) } } // 图片预览 const handleImagePreview = (index: number) => { if (!evaluation?.images?.length) return Taro.previewImage({ current: evaluation.images[index], urls: evaluation.images, }) } if (loading) { return ( 加载中... ) } if (!evaluation) { return ( 评价不存在 ) } return ( {/* 用户信息 */} {evaluation.userAvatar ? ( ) : ( {evaluation.isAnonymous ? '匿' : evaluation.userName[0]} )} {evaluation.userName} {renderStars(evaluation.score)} {evaluation.createTime.split(' ')[0]} {/* 商品信息 */} Taro.navigateTo({ url: `/pages/shop/product-detail?id=${evaluation.goodsId}` })} > {evaluation.goodsImage ? ( ) : ( 🛍️ )} {evaluation.goodsName} 查看商品详情 {/* 评价内容 */} {evaluation.content} {/* 评价图片 */} {evaluation.images && evaluation.images.length > 0 && ( {evaluation.images.map((img, index) => ( handleImagePreview(index)} > ))} )} {/* 商家回复 */} {evaluation.reply && ( 商家回复 官方 {evaluation.replyTime && ( {evaluation.replyTime} )} {evaluation.reply} )} {/* 底部操作栏 */} {evaluation.isLiked ? '❤️' : '🤍'} {evaluation.likes} Taro.navigateTo({ url: `/pages/shop/product-detail?id=${evaluation.goodsId}` })} > 查看商品 ) } export default EvaluateDetailPage