Files
peiwan-uniapp/pages/trend/city/list.vue

159 lines
4.7 KiB
Vue
Raw Normal View History

2025-01-21 01:46:34 +08:00
<template>
<view class="page-app theme-light main-green font-1">
<!-- 如果页面中的cell高度是固定不变的则不需要设置cell-height-mode如果页面中高度是动态改变的则设置cell-height-mode="dynamic" -->
<!-- 原先的v-model修改为@virtualListChange="virtualListChange"并赋值处理后的虚拟列表 -->
<z-paging ref="paging" :auto="true" use-virtual-list auto-show-back-to-top :force-close-inner-list="true" :paging-style="{ paddingTop: 0 + 'px', paddingBottom: paddingBottom + 'rpx' }" cell-height-mode="dynamic" @scroll="scroll" @virtualListChange="virtualListChange" @query="queryList">
<!-- 需要固定在顶部不滚动的view放在slot="top"的view中如果需要跟着滚动则不要设置slot="top" -->
<template #top>
<su-navbar color="var(--ui-BG-Main)" :title="queryParams.city" statusBar></su-navbar>
</template>
<!-- :id="`zp-id-${item.zp_index}`":key="item.zp_index" 必须写必须写 -->
<!-- 这里for循环的index不是数组中真实的index了请使用item.zp_index获取真实的index -->
<view class="main-box">
<view class="tab-box">
<view class="right">
<tui-tabs :size="24" :tabs="tabs" :unlined="true" width="140" :height="55" :currentTab="currentTab" :sliderWidth="120" :sliderHeight="55"
bottom="50%" color="#888" selectedColor="var(--ui-BG-Main)" :bold="true" sliderBgColor="#7ea19e21" @change="change">
</tui-tabs>
</view>
</view>
<order-list :virtualList="virtualList"></order-list>
</view>
<!-- 自定义返回顶部view -->
<template #backToTop>
<custom-back-to-top></custom-back-to-top>
</template>
</z-paging>
<s-menu-tools />
<s-auth-modal />
</view>
</template>
<script>
import tuiTabs from "@/components/thorui/tui-tabs/tui-tabs.vue"
import OrderList from '@/pages/trend/city/components/orderList.vue';
import TrendApi from '@/sheep/api/worker/trend';
import sheep from '@/sheep';
export default {
components: {
tuiTabs,
OrderList,
},
props: {
},
data() {
return {
// 虚拟列表数组,通过@virtualListChange监听获得最新数组
virtualList: [],
scrollTop: 0,
paddingTop: 0,
paddingBottom: 0,
height: 0,
queryParams: {
pageNo: 1,
pageSize: 10,
userId: null,
city: '',
queryType: '2',
},
currentTab: 0,
tabs: [{
name: "最新",
value: '2',
}, {
name: "最热",
value: '1',
}],
}
},
// 分享小程序
onShareAppMessage(res) {
return {
title: this.shareInfo.title,
path: this.shareInfo.path,
imageUrl: this.shareInfo.image,
};
},
onShareTimeline() {
return {
title: this.shareInfo.title,
path: this.shareInfo.path,
imageUrl: this.shareInfo.image,
}
},
onLoad(options) {
this.queryParams.city = options.city;
},
computed: {
userInfo: {
get() {
return sheep.$store('user').userInfo;
},
},
shareInfo() {
return sheep.$platform.share.getShareInfo();
},
},
methods: {
scroll(e) {
this.scrollTop = e.detail.scrollTop;
},
// 监听虚拟列表数组改变并赋值给virtualList进行重新渲染
virtualListChange(vList) {
this.virtualList = vList;
},
queryList(pageNo, pageSize) {
// 组件加载时会自动触发此方法,因此默认页面加载时会自动触发,无需手动调用
// 这里的pageNo和pageSize会自动计算好直接传给服务器即可
// 模拟请求服务器获取分页数据,请替换成自己的网络请求
this.queryParams.pageNo = pageNo;
this.queryParams.pageSize = pageSize;
this.queryParams.queryType = this.tabs[this.currentTab].value;
this.queryParams.userId = this.userInfo.id;
TrendApi.getTrendPage(this.queryParams).then(res => {
// 将请求的结果数组传递给z-paging
this.$refs.paging.complete(res.data.list);
}).catch(res => {
// 如果请求失败写this.$refs.paging.complete(false);
// 注意每次都需要在catch中写这句话很麻烦z-paging提供了方案可以全局统一处理
// 在底层的网络请求抛出异常时写uni.$emit('z-paging-error-emit');即可
this.$refs.paging.complete(false);
})
},
//切换tab逻辑请自行处理
change(e) {
this.currentTab = e.index
this.$refs.paging.reload();
},
}
}
</script>
<style lang="scss" scoped>
.page-app {
background-color: #fff;
padding-bottom: 140rpx;
height: calc(100vh);
padding-bottom: env(safe-area-inset-bottom);
}
.main-box {
.tab-box {
display: flex;
justify-content: end;
.right {
}
}
}
</style>