This commit is contained in:
1173117610@qq.com 2026-05-11 10:52:58 +08:00
parent 0f66524bfa
commit 9f77806743
1 changed files with 29 additions and 16 deletions

View File

@ -26,9 +26,9 @@
<!-- 子分类金刚区 --> <!-- 子分类金刚区 -->
<view class="sub-grid-wrap" v-if="subCategories.length > 0"> <view class="sub-grid-wrap" v-if="subCategories.length > 0">
<view class="sub-grid"> <view class="sub-grid">
<view class="sub-item" v-for="(sub, idx) in subCategories" :key="idx" @click="selectSub(sub.son_category)"> <view class="sub-item" v-for="(sub, idx) in subCategories" :key="idx" @click="selectSub(sub.second_category)">
<image class="sub-icon" :src="sub.img" mode="aspectFit"></image> <image class="sub-icon" :src="sub.img_url" mode="aspectFit"></image>
<text class="sub-text">{{ sub.son_name }}</text> <text class="sub-text">{{ sub.cate_name.trim() }}</text>
</view> </view>
</view> </view>
</view> </view>
@ -111,15 +111,20 @@
}, },
getCategoryTabs() { getCategoryTabs() {
uni.request({ 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) => { success: (res) => {
if (res.data && res.data.code === 200) { if (res.data && res.data.code === 200) {
// navList // navList
this.navList = [{ name: '首页', cat_id: 0 }, { name: '推荐', cat_id: -1 }, ...res.data.data.category]; 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); const currentCat = this.navList.find(c => c.cat_id == this.currentCatId);
if (currentCat && currentCat.son) { if (currentCat && currentCat.second) {
this.subCategories = currentCat.son; this.subCategories = currentCat.second;
} }
} }
} }
@ -134,21 +139,24 @@
if (this.loading || this.finished) return; if (this.loading || this.finished) return;
this.loading = true; this.loading = true;
let sortParam = this.sortType; // allItemList (0:, 3:, 8:, 9:)
if (this.sortType === 3) { let sortParam = 0;
sortParam = this.priceOrder === 'asc' ? 3 : 4; if (this.sortType === 2) {
sortParam = 3;
} else if (this.sortType === 3) {
sortParam = this.priceOrder === 'asc' ? 8 : 9;
} }
uni.request({ 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) => { success: (res) => {
if (res.data && res.data.code === 200) { if (res.data && res.data.code === 200 && res.data.data && res.data.data.item_info) {
const list = res.data.data.map(item => ({ const list = res.data.data.item_info.map(item => ({
id: item.id, id: item.id,
image: item.itempic, image: item.itempic,
title: item.itemshorttitle, title: item.itemshorttitle,
finalPrice: item.itemendprice, finalPrice: item.itemendprice,
couponValue: item.couponmoney, couponValue: item.couponmoney || 0,
sales: item.itemsale >= 10000 ? (item.itemsale / 10000).toFixed(1) + '万' : item.itemsale, sales: item.itemsale >= 10000 ? (item.itemsale / 10000).toFixed(1) + '万' : item.itemsale,
shopType: item.shoptype === 'B' ? '天猫' : '淘宝' shopType: item.shoptype === 'B' ? '天猫' : '淘宝'
})); }));
@ -156,8 +164,13 @@
if (list.length === 0) { if (list.length === 0) {
this.finished = true; this.finished = true;
} else { } else {
//
this.goodsList = [...this.goodsList, ...list]; this.goodsList = [...this.goodsList, ...list];
this.page++; this.page++;
//
if (list.length < 20) {
this.finished = true;
}
} }
} else { } else {
this.finished = true; this.finished = true;
@ -177,7 +190,7 @@
this.currentCatId = item.cat_id; this.currentCatId = item.cat_id;
this.currentSonId = 0; this.currentSonId = 0;
this.subCategories = item.son || []; this.subCategories = item.second || [];
this.getProducts(true); this.getProducts(true);
}, },
selectSub(sonId) { selectSub(sonId) {