diff --git a/pages/category/category.vue b/pages/category/category.vue index 3c360ef..4542964 100644 --- a/pages/category/category.vue +++ b/pages/category/category.vue @@ -26,9 +26,9 @@ - - - {{ sub.son_name }} + + + {{ sub.cate_name.trim() }} @@ -111,15 +111,20 @@ }, getCategoryTabs() { uni.request({ - url: 'https://api.cmspro.haodanku.com/index/category?cid=qOstW90', + url: 'https://api.cmspro.haodanku.com/index/superCategory?is_get_second=1&cid=qOstW90', success: (res) => { if (res.data && res.data.code === 200) { - // 与首页 navList 保持一致的结构 - this.navList = [{ name: '首页', cat_id: 0 }, { name: '推荐', cat_id: -1 }, ...res.data.data.category]; + // 映射为与首页一致的 navList 结构 + const categories = res.data.data.map(item => ({ + name: item.name, + cat_id: item.cat_id, + second: item.second || [] + })); + this.navList = [{ name: '首页', cat_id: 0 }, { name: '推荐', cat_id: -1 }, ...categories]; const currentCat = this.navList.find(c => c.cat_id == this.currentCatId); - if (currentCat && currentCat.son) { - this.subCategories = currentCat.son; + if (currentCat && currentCat.second) { + this.subCategories = currentCat.second; } } } @@ -134,21 +139,24 @@ if (this.loading || this.finished) return; this.loading = true; - let sortParam = this.sortType; - if (this.sortType === 3) { - sortParam = this.priceOrder === 'asc' ? 3 : 4; + // 构建 allItemList 排序参数 (0:综合, 3:销量, 8:券后价低到高, 9:券后价高到低) + let sortParam = 0; + if (this.sortType === 2) { + sortParam = 3; + } else if (this.sortType === 3) { + sortParam = this.priceOrder === 'asc' ? 8 : 9; } uni.request({ - url: `https://api.cmspro.haodanku.com/category/category_items?cat_id=${this.currentCatId}&son_category=${this.currentSonId}&page=${this.page}&sort=${sortParam}&cid=qOstW90`, + url: `https://api.cmspro.haodanku.com/find/allItemList?category_id=${this.currentCatId}&page=${this.page}&sort=${sortParam}&page_size=20&cid=qOstW90`, success: (res) => { - if (res.data && res.data.code === 200) { - const list = res.data.data.map(item => ({ + if (res.data && res.data.code === 200 && res.data.data && res.data.data.item_info) { + const list = res.data.data.item_info.map(item => ({ id: item.id, image: item.itempic, title: item.itemshorttitle, finalPrice: item.itemendprice, - couponValue: item.couponmoney, + couponValue: item.couponmoney || 0, sales: item.itemsale >= 10000 ? (item.itemsale / 10000).toFixed(1) + '万' : item.itemsale, shopType: item.shoptype === 'B' ? '天猫' : '淘宝' })); @@ -156,8 +164,13 @@ if (list.length === 0) { this.finished = true; } else { + // 翻页添加数据 this.goodsList = [...this.goodsList, ...list]; this.page++; + // 如果返回的数量小于请求的数量,说明已到最后一页 + if (list.length < 20) { + this.finished = true; + } } } else { this.finished = true; @@ -177,7 +190,7 @@ this.currentCatId = item.cat_id; this.currentSonId = 0; - this.subCategories = item.son || []; + this.subCategories = item.second || []; this.getProducts(true); }, selectSub(sonId) {