|
@@ -15,7 +15,6 @@ type Goods = GoodsResponse['data'][0]
|
|
|
|
|
|
|
|
export default function GoodsListPage() {
|
|
export default function GoodsListPage() {
|
|
|
const [searchKeyword, setSearchKeyword] = useState('')
|
|
const [searchKeyword, setSearchKeyword] = useState('')
|
|
|
- const [activeCategory, setActiveCategory] = useState('all')
|
|
|
|
|
const { addToCart } = useCart()
|
|
const { addToCart } = useCart()
|
|
|
|
|
|
|
|
// 使用useRouter钩子获取路由参数
|
|
// 使用useRouter钩子获取路由参数
|
|
@@ -24,11 +23,6 @@ export default function GoodsListPage() {
|
|
|
const categoryId = params?.cateId || ''
|
|
const categoryId = params?.cateId || ''
|
|
|
const fromPage = params?.from || ''
|
|
const fromPage = params?.from || ''
|
|
|
|
|
|
|
|
- const categories = [
|
|
|
|
|
- { id: 'all', name: '全部' },
|
|
|
|
|
- { id: 'hot', name: '热销' },
|
|
|
|
|
- { id: 'new', name: '新品' },
|
|
|
|
|
- ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
@@ -57,6 +51,12 @@ export default function GoodsListPage() {
|
|
|
sortOrder: 'DESC' // 倒序排列
|
|
sortOrder: 'DESC' // 倒序排列
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ // console.log("categoryId:",categoryId);
|
|
|
|
|
+ // console.log("goodslistresponse:",response);
|
|
|
|
|
+ // console.debug("categoryId:",categoryId);
|
|
|
|
|
+ // console.debug("goodslistresponse:",response);
|
|
|
|
|
+
|
|
|
if (response.status !== 200) {
|
|
if (response.status !== 200) {
|
|
|
throw new Error('获取商品失败')
|
|
throw new Error('获取商品失败')
|
|
|
}
|
|
}
|
|
@@ -77,7 +77,7 @@ export default function GoodsListPage() {
|
|
|
// 分享功能 - 分享给好友
|
|
// 分享功能 - 分享给好友
|
|
|
useShareAppMessage(() => {
|
|
useShareAppMessage(() => {
|
|
|
// 如果有商品数据,使用第一个商品的图片作为分享图片
|
|
// 如果有商品数据,使用第一个商品的图片作为分享图片
|
|
|
- const shareImageUrl = allGoods.length > 0 ? allGoods[0]?.imageFile?.fullUrl || '' : '';
|
|
|
|
|
|
|
+ const shareImageUrl = allGoods.length > 0 ? (allGoods[0] as any)?.imageFile?.fullUrl || '' : '';
|
|
|
|
|
|
|
|
// 构建分享标题
|
|
// 构建分享标题
|
|
|
let shareTitle = '商品分类 - 发现好物';
|
|
let shareTitle = '商品分类 - 发现好物';
|
|
@@ -97,7 +97,7 @@ export default function GoodsListPage() {
|
|
|
// 分享到朋友圈功能
|
|
// 分享到朋友圈功能
|
|
|
useShareTimeline(() => {
|
|
useShareTimeline(() => {
|
|
|
// 朋友圈分享需要图片,使用第一个商品的图片
|
|
// 朋友圈分享需要图片,使用第一个商品的图片
|
|
|
- const shareImageUrl = allGoods.length > 0 ? allGoods[0]?.imageFile?.fullUrl || '' : '';
|
|
|
|
|
|
|
+ const shareImageUrl = allGoods.length > 0 ? (allGoods[0] as any)?.imageFile?.fullUrl || '' : '';
|
|
|
|
|
|
|
|
// 朋友圈分享标题
|
|
// 朋友圈分享标题
|
|
|
let shareTitle = '发现好物,快来选购!';
|
|
let shareTitle = '发现好物,快来选购!';
|
|
@@ -246,14 +246,14 @@ export default function GoodsListPage() {
|
|
|
const hasSpecOptions = goods.spuId === 0 && childGoodsIds && childGoodsIds.length > 0
|
|
const hasSpecOptions = goods.spuId === 0 && childGoodsIds && childGoodsIds.length > 0
|
|
|
// parentGoodsId: 如果是父商品,parentGoodsId = goods.id;如果是子商品,parentGoodsId = goods.spuId
|
|
// parentGoodsId: 如果是父商品,parentGoodsId = goods.id;如果是子商品,parentGoodsId = goods.spuId
|
|
|
const parentGoodsId = goods.spuId === 0 ? goods.id : goods.spuId
|
|
const parentGoodsId = goods.spuId === 0 ? goods.id : goods.spuId
|
|
|
- const imageUrl = goods.imageFile?.fullUrl || ''
|
|
|
|
|
|
|
+ const imageUrl = (goods as any).imageFile?.fullUrl || ''
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
- id: goods.id.toString(),
|
|
|
|
|
|
|
+ id: String(goods.id),
|
|
|
name: goods.name,
|
|
name: goods.name,
|
|
|
cover_image: imageUrl,
|
|
cover_image: imageUrl,
|
|
|
price: goods.price,
|
|
price: goods.price,
|
|
|
- originPrice: goods.originPrice,
|
|
|
|
|
|
|
+ originPrice: (goods as any).originPrice,
|
|
|
tags: goods.stock <= 0 ? ['已售罄'] : goods.salesNum > 100 ? ['热销'] : [],
|
|
tags: goods.stock <= 0 ? ['已售罄'] : goods.salesNum > 100 ? ['热销'] : [],
|
|
|
hasSpecOptions,
|
|
hasSpecOptions,
|
|
|
parentGoodsId,
|
|
parentGoodsId,
|
|
@@ -262,7 +262,7 @@ export default function GoodsListPage() {
|
|
|
quantity: 1 // 默认数量为1
|
|
quantity: 1 // 默认数量为1
|
|
|
}
|
|
}
|
|
|
})}
|
|
})}
|
|
|
- onClick={(goods) => handleGoodsClick(allGoods.find(g => g.id.toString() === goods.id)!)}
|
|
|
|
|
|
|
+ onClick={(goods) => handleGoodsClick(allGoods.find(g => String(g.id) === goods.id)!)}
|
|
|
onAddCart={(goods) => handleAddToCart(goods)}
|
|
onAddCart={(goods) => handleAddToCart(goods)}
|
|
|
/>
|
|
/>
|
|
|
|
|
|