|
@@ -17,6 +17,10 @@ export default function GoodsListPage() {
|
|
|
const [activeCategory, setActiveCategory] = useState('all')
|
|
const [activeCategory, setActiveCategory] = useState('all')
|
|
|
const { addToCart } = useCart()
|
|
const { addToCart } = useCart()
|
|
|
|
|
|
|
|
|
|
+ // 获取URL参数中的分类ID
|
|
|
|
|
+ const params = Taro.getCurrentInstance().router?.params
|
|
|
|
|
+ const categoryId = params?.cateId || ''
|
|
|
|
|
+
|
|
|
const categories = [
|
|
const categories = [
|
|
|
{ id: 'all', name: '全部' },
|
|
{ id: 'all', name: '全部' },
|
|
|
{ id: 'hot', name: '热销' },
|
|
{ id: 'hot', name: '热销' },
|
|
@@ -31,14 +35,20 @@ export default function GoodsListPage() {
|
|
|
hasNextPage,
|
|
hasNextPage,
|
|
|
refetch
|
|
refetch
|
|
|
} = useInfiniteQuery({
|
|
} = useInfiniteQuery({
|
|
|
- queryKey: ['goods-infinite', searchKeyword],
|
|
|
|
|
|
|
+ queryKey: ['goods-infinite', searchKeyword, categoryId],
|
|
|
queryFn: async ({ pageParam = 1 }) => {
|
|
queryFn: async ({ pageParam = 1 }) => {
|
|
|
|
|
+ // 构建筛选条件
|
|
|
|
|
+ const filters: any = { state: 1 } // 只显示可用的商品
|
|
|
|
|
+ if (categoryId) {
|
|
|
|
|
+ filters.categoryId1 = categoryId
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const response = await goodsClient.$get({
|
|
const response = await goodsClient.$get({
|
|
|
query: {
|
|
query: {
|
|
|
page: pageParam,
|
|
page: pageParam,
|
|
|
pageSize: 10,
|
|
pageSize: 10,
|
|
|
keyword: searchKeyword,
|
|
keyword: searchKeyword,
|
|
|
- filters: JSON.stringify({ state: 1 }) // 只显示可用的商品
|
|
|
|
|
|
|
+ filters: JSON.stringify(filters)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
if (response.status !== 200) {
|
|
if (response.status !== 200) {
|