首页产品列表按上架时间或点赞量排列以及上拉加载更多数据
This commit is contained in:
@@ -34,7 +34,10 @@
|
||||
</u-tabs>
|
||||
</view>
|
||||
<!-- 产品 -->
|
||||
<products ref="getProductsByTime"></products>
|
||||
<productsByTime v-if="tabCurrent==0" ref="productsByTime" @getTimeLength="getTimeLength">
|
||||
</productsByTime>
|
||||
<productsByThumb v-if="tabCurrent==1" ref="productsByThumb" @getThumbLength="getThumbLength">
|
||||
</productsByThumb>
|
||||
<view style="font-size: 24rpx;color: #A3A3A3;text-align: center;padding: 26rpx 0;"
|
||||
v-show="reachBottomLength===0">
|
||||
没有更多数据了</view>
|
||||
@@ -60,15 +63,16 @@
|
||||
imgUrl: '',
|
||||
swiperList: [],
|
||||
reachBottomLength: '',
|
||||
productList: [],
|
||||
pageNum: 1,
|
||||
sortType: ''
|
||||
}
|
||||
},
|
||||
onReachBottom() {
|
||||
this.pageNum += 1
|
||||
if (this.reachBottomLength !== 0) {
|
||||
this.getNewProducts()
|
||||
if (this.tabCurrent == 0 && this.reachBottomLength !== 0) {
|
||||
this.$refs.productsByTime.pageNum++
|
||||
this.$refs.productsByTime.getProductsByTime()
|
||||
}
|
||||
if (this.tabCurrent == 1 && this.reachBottomLength !== 0) {
|
||||
this.$refs.productsByThumb.pageNum++
|
||||
this.$refs.productsByThumb.getProductsByThumb()
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
@@ -78,36 +82,23 @@
|
||||
this.imgUrl = uni.getStorageSync('img_url')
|
||||
},
|
||||
methods: {
|
||||
//获取按上架时间排列的产品列表length
|
||||
getTimeLength(e) {
|
||||
this.reachBottomLength = e
|
||||
},
|
||||
//获取按点赞量排列的产品列表length
|
||||
getThumbLength(e) {
|
||||
this.reachBottomLength = e
|
||||
},
|
||||
//点击上架时间和点赞量切换页面
|
||||
tabChange(data) {
|
||||
this.tabCurrent = data.index
|
||||
uni.$emit("getCurrent", data.index);
|
||||
if (data.index == 0) {
|
||||
this.sortType = 1
|
||||
this.$refs.productsByTime.getProductsByTime()
|
||||
} else if (data.index == 1) {
|
||||
this.$refs.getProductsByTime.getProducts()
|
||||
this.sortType = 2
|
||||
this.$refs.productsByThumb.getProductsByThumb()
|
||||
}
|
||||
},
|
||||
//下拉刷新获取新数据
|
||||
getNewProducts() {
|
||||
this.$apiServe.getProducts({
|
||||
sortType: this.sortType,
|
||||
pageSize: 4,
|
||||
pageNum: this.pageNum
|
||||
}).then(res => {
|
||||
let tags = res.data.data
|
||||
for (const item of tags) {
|
||||
let tag = item.tags
|
||||
this.tagsArray = tag.split(',')
|
||||
item.tags = this.tagsArray[0]
|
||||
}
|
||||
if (tags.length === 0) {
|
||||
this.reachBottomLength = tags.length
|
||||
}
|
||||
this.$refs.getProductsByTime.productList.push(...res.data.data)
|
||||
})
|
||||
},
|
||||
//获取一级分类
|
||||
getCategories() {
|
||||
this.$apiServe.getCategories().then(res => {
|
||||
|
||||
Reference in New Issue
Block a user