|
|
@@ -1,23 +1,25 @@
|
|
|
import { View, ScrollView, Text, RichText } from '@tarojs/components'
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
-import { useState } from 'react'
|
|
|
+import { useState, useEffect } from 'react'
|
|
|
import Taro from '@tarojs/taro'
|
|
|
import { goodsClient } from '@/api'
|
|
|
// import { InferResponseType } from 'hono'
|
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
import { Carousel } from '@/components/ui/carousel'
|
|
|
-import { GoodsSpecSelector } from '@/components/goods-spec-selector'
|
|
|
+// 规格选择功能暂时移除,后端暂无规格API
|
|
|
+// import { GoodsSpecSelector } from '@/components/goods-spec-selector'
|
|
|
import { useCart } from '@/utils/cart'
|
|
|
import './index.css'
|
|
|
|
|
|
// type GoodsResponse = InferResponseType<typeof goodsClient[':id']['$get'], 200>
|
|
|
|
|
|
-interface SelectedSpec {
|
|
|
- name: string
|
|
|
- price: number
|
|
|
- stock: number
|
|
|
-}
|
|
|
+// 规格选择功能暂时移除,后端暂无规格API
|
|
|
+// interface SelectedSpec {
|
|
|
+// name: string
|
|
|
+// price: number
|
|
|
+// stock: number
|
|
|
+// }
|
|
|
|
|
|
interface Review {
|
|
|
id: number
|
|
|
@@ -39,8 +41,9 @@ interface ReviewStats {
|
|
|
|
|
|
export default function GoodsDetailPage() {
|
|
|
const [quantity, setQuantity] = useState(1)
|
|
|
- const [selectedSpec, setSelectedSpec] = useState<SelectedSpec | null>(null)
|
|
|
- const [showSpecModal, setShowSpecModal] = useState(false)
|
|
|
+ // 规格选择功能暂时移除,后端暂无规格API
|
|
|
+ // const [selectedSpec, setSelectedSpec] = useState<SelectedSpec | null>(null)
|
|
|
+ // const [showSpecModal, setShowSpecModal] = useState(false)
|
|
|
const { addToCart } = useCart()
|
|
|
|
|
|
// 模拟评价数据
|
|
|
@@ -107,23 +110,31 @@ export default function GoodsDetailPage() {
|
|
|
description: ''
|
|
|
})) || []
|
|
|
|
|
|
- // 规格选择处理
|
|
|
- const handleSpecSelect = (spec: any, selectedQuantity: number) => {
|
|
|
- setSelectedSpec({
|
|
|
- name: spec.name,
|
|
|
- price: spec.price,
|
|
|
- stock: spec.stock
|
|
|
- })
|
|
|
- setQuantity(selectedQuantity)
|
|
|
- setShowSpecModal(false)
|
|
|
+ // 价格验证逻辑 - 简化版本,移除规格选择
|
|
|
+ const validatePriceConsistency = () => {
|
|
|
+ if (!goods) return
|
|
|
+
|
|
|
+ const displayedPrice = goods.price
|
|
|
+ const apiPrice = goods.price
|
|
|
+
|
|
|
+ // 如果显示价格与API价格不一致,记录警告
|
|
|
+ if (displayedPrice !== apiPrice) {
|
|
|
+ console.warn('价格显示不一致:', { displayedPrice, apiPrice, goodsId: goods.id })
|
|
|
+ // 在实际项目中可以发送错误报告或显示用户提示
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ // 在商品数据变化时验证价格
|
|
|
+ useEffect(() => {
|
|
|
+ validatePriceConsistency()
|
|
|
+ }, [goods])
|
|
|
+
|
|
|
// 添加到购物车
|
|
|
const handleAddToCart = () => {
|
|
|
if (!goods) return
|
|
|
|
|
|
- const currentPrice = selectedSpec?.price || goods.price
|
|
|
- const currentStock = selectedSpec?.stock || goods.stock
|
|
|
+ const currentPrice = goods.price
|
|
|
+ const currentStock = goods.stock
|
|
|
|
|
|
if (quantity > currentStock) {
|
|
|
Taro.showToast({
|
|
|
@@ -140,7 +151,7 @@ export default function GoodsDetailPage() {
|
|
|
image: goods.imageFile?.fullUrl || '',
|
|
|
stock: currentStock,
|
|
|
quantity,
|
|
|
- spec: selectedSpec?.name || ''
|
|
|
+ spec: ''
|
|
|
})
|
|
|
|
|
|
Taro.showToast({
|
|
|
@@ -153,8 +164,8 @@ export default function GoodsDetailPage() {
|
|
|
const handleBuyNow = () => {
|
|
|
if (!goods) return
|
|
|
|
|
|
- const currentPrice = selectedSpec?.price || goods.price
|
|
|
- const currentStock = selectedSpec?.stock || goods.stock
|
|
|
+ const currentPrice = goods.price
|
|
|
+ const currentStock = goods.stock
|
|
|
|
|
|
if (quantity > currentStock) {
|
|
|
Taro.showToast({
|
|
|
@@ -172,7 +183,7 @@ export default function GoodsDetailPage() {
|
|
|
price: currentPrice,
|
|
|
image: goods.imageFile?.fullUrl || '',
|
|
|
quantity,
|
|
|
- spec: selectedSpec?.name || ''
|
|
|
+ spec: ''
|
|
|
},
|
|
|
totalAmount: currentPrice * quantity
|
|
|
})
|
|
|
@@ -224,9 +235,9 @@ export default function GoodsDetailPage() {
|
|
|
<View className="goods-info-section">
|
|
|
<View className="goods-price-row">
|
|
|
<View className="price-container">
|
|
|
- <Text className="current-price">¥{(selectedSpec?.price || goods.price).toFixed(2)}</Text>
|
|
|
+ <Text className="current-price">¥{goods.price.toFixed(2)}</Text>
|
|
|
<Text className="original-price">¥{goods.costPrice.toFixed(2)}</Text>
|
|
|
- {!selectedSpec && <Text className="price-suffix">起</Text>}
|
|
|
+ <Text className="price-suffix">起</Text>
|
|
|
</View>
|
|
|
<View className="sales-info">
|
|
|
<Text className="sales-text">已售{goods.salesNum}件</Text>
|
|
|
@@ -236,24 +247,7 @@ export default function GoodsDetailPage() {
|
|
|
<Text className="goods-title">{goods.name}</Text>
|
|
|
<Text className="goods-description">{goods.instructions || '暂无商品描述'}</Text>
|
|
|
|
|
|
- {/* 规格选择区域 */}
|
|
|
- <View className="spec-section">
|
|
|
- <View className="spec-header">
|
|
|
- <Text className="spec-title">规格</Text>
|
|
|
- <Text className="spec-selected">
|
|
|
- {selectedSpec ? `已选:${selectedSpec.name}` : '请选择规格'}
|
|
|
- </Text>
|
|
|
- </View>
|
|
|
- <View
|
|
|
- className="spec-selector"
|
|
|
- onClick={() => setShowSpecModal(true)}
|
|
|
- >
|
|
|
- <Text className="spec-placeholder">
|
|
|
- {selectedSpec ? selectedSpec.name : '选择规格'}
|
|
|
- </Text>
|
|
|
- <View className="i-heroicons-chevron-right-20-solid spec-arrow" />
|
|
|
- </View>
|
|
|
- </View>
|
|
|
+ {/* 规格选择区域 - 暂时移除,后端暂无规格API */}
|
|
|
</View>
|
|
|
|
|
|
{/* 商品评价区域 */}
|
|
|
@@ -337,7 +331,7 @@ export default function GoodsDetailPage() {
|
|
|
size="sm"
|
|
|
variant="ghost"
|
|
|
className="quantity-btn"
|
|
|
- onClick={() => setQuantity(Math.min(selectedSpec?.stock || goods.stock, quantity + 1))}
|
|
|
+ onClick={() => setQuantity(Math.min(goods.stock, quantity + 1))}
|
|
|
>
|
|
|
+
|
|
|
</Button>
|
|
|
@@ -363,15 +357,7 @@ export default function GoodsDetailPage() {
|
|
|
</View>
|
|
|
</View>
|
|
|
|
|
|
- {/* 规格选择弹窗 */}
|
|
|
- <GoodsSpecSelector
|
|
|
- visible={showSpecModal}
|
|
|
- onClose={() => setShowSpecModal(false)}
|
|
|
- onConfirm={handleSpecSelect}
|
|
|
- goodsId={goodsId}
|
|
|
- currentSpec={selectedSpec?.name}
|
|
|
- currentQuantity={quantity}
|
|
|
- />
|
|
|
+ {/* 规格选择弹窗 - 暂时移除,后端暂无规格API */}
|
|
|
</View>
|
|
|
)
|
|
|
}
|