shop_uniapp/pages/community/components/lists.vue
2024-06-06 09:55:01 +08:00

94 lines
3.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="">
<mescroll-uni ref="mescrollRef" top="0" bottom="200rpx" :height="height" @init="mescrollInit"
@down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
<u-waterfall ref="uWaterfall" v-model="lists" :add-time="50">
<template v-slot:left="{leftList}">
<view style="padding:0 9rpx 0 30rpx">
<community-list width="336rpx" type="waterfall" :list="leftList"></community-list>
</view>
</template>
<template v-slot:right="{rightList}">
<view style="padding:0 30rpx 0 9rpx;">
<community-list width="336rpx" type="waterfall" :list="rightList"></community-list>
</view>
</template>
</u-waterfall>
</mescroll-uni>
</view>
</template>
<script>
import {
getCommunityArticleLists
} from '@/api/community.js';
import {
trottle
} from "@/utils/tools.js"
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
export default {
mixins: [MescrollMixin, MescrollMoreItemMixin],
props: {
cateId: {
type: [String, Number]
}
},
data() {
return {
height: '',
upOption: {
empty: {
icon: '/static/images/news_null.png',
tip: '暂无任何内容...',
fixed: true,
top: "0",
}
},
lists: []
}
},
mounted() {
uni.$on('changeItem', (event) => {
const index = this.lists.findIndex(el => el.id == event.id)
if (index == -1) return
this.$refs.uWaterfall.modify(event.id, 'like', event.like)
this.$refs.uWaterfall.modify(event.id, 'is_like', event.is_like)
})
uni.getSystemInfo({
success: (res) => {
this.height = res.windowHeight - 46 + 'px';
}
});
},
methods: {
async upCallback(page) {
const pageNum = page.num
const pageSize = page.size
getCommunityArticleLists({
cate_id: this.cateId,
page_no: pageNum,
page_size: pageSize,
}).then(res => {
if (pageNum == 1) {
this.$refs.uWaterfall.clear()
this.lists = []
}
const hasNext = !!res.data.more;
// 异步:让vue能够监听到数据改变过了
// has_new 是通知父组件将关注右上角的是否新更新小点显示或隐藏
uni.$emit('hasNew', res.data.has_new)
setTimeout(() => {
this.lists = [...this.lists, ...res.data.list]
}, 0)
this.mescroll.endSuccess(res.data.list.length, hasNext);
})
}
}
}
</script>