<template> <view class="pages"> <u-navbar title="演出资讯" :placeholder="true" :autoBack="false" @leftClick="leftClick" :safeAreaInsetTop="true" > </u-navbar> <view class="search-wrap"> <u-search placeholder="请输入关键词" :clearabled="true" :showAction="true" height="80rpx" @search="search" @custom="search" @clear="reloadList" bgColor="#EAEAEA" borderColor="#EAEAEA" v-model="params.keyword"> </u-search> </view> <view class="page-wrap"> <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"> <!-- :down="downOption" :up="upOption" --> <view class="list"> <view v-for="(item,index) in dataList" class="item u-flex" :class="{ show: show }" @click="itemClick(item)" :key="item.id"> <view class="text"> <view class="title u-line-1">{{ item.title }}</view> <view class="con u-line-2">{{item.infoSnapshot}}</view> <view class="time">{{ $u.timeFormat(item.onlineTime, 'yyyy-mm-dd') }}</view> </view> <image class="img" :src="item.mainImg" mode=""></image> </view> </view> </mescroll-body> </view> </view> </template> <script> // 引入mescroll-mixins.js import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"; export default { mixins: [MescrollMixin], // 使用mixin components: { }, data() { return { staticUrl:this.$commonConfig.staticUrl, // // 下拉刷新的配置(可选, 绝大部分情况无需配置) // downOption: { // }, // // 上拉加载的配置(可选, 绝大部分情况无需配置) upOption: { page: { size: 10 // 每页数据的数量,默认10 }, noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示 empty: { tip: '暂无相关资讯,请重新搜索' } }, params:{ keyword:'' }, dataList:[], observer: null, show:false, } }, onShow() { }, onLoad() { this.observer = uni.createIntersectionObserver(this,{observeAll: true}); }, onReady() { this.observer.relativeToViewport().observe('.item', res => { if (res.intersectionRatio > 0) { console.log('resres',res); // 当元素出现在视口时执行动画 // this.showAnimation(res); this.show = true; } }) }, onUnload() { if (this.observer) { this.observer.disconnect() } }, methods: { leftClick(e){ let pages = getCurrentPages(); if(pages.length==1){ uni.$u.route('/pages/index/index') }else{ uni.navigateBack() }; }, /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认) downCallback(){ this.mescroll.resetUpScroll(); }, /*上拉加载的回调*/ upCallback(page) { // 此处可以继续请求其他接口 // if(page.num == 1){ // // 请求其他接口... // } // 如果希望先请求其他接口,再触发upCallback,可参考以下写法 // if(!this.hasTypeId){ // // this.getid(); // this.mescroll.endErr();//没有接口暂时不调用 // return // 此处return,先获取xx // } let pageNum = page.num; // 页码, 默认从1开始 let pageSize = page.size; // 页长, 默认每页10条 let params = { pageNum : page.num, pageSize : page.size, title:this.params.keyword, status:1 } // console.log('this.params',params); this.$u.api.newsList(params).then(data => { this.hasfetch = true; // console.log('data',JSON.parse(JSON.stringify(data))); // 接口返回的当前页数据列表 (数组) let curPageData = data.data.rows; // console.log('curPageData',JSON.parse(JSON.stringify(curPageData))); // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8) let curPageLen = curPageData.length; // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3) // let totalPage = data.data.data.totalPage; // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26) let totalSize = data.data.total; // 接口返回的是否有下一页 (true/false) // let hasNext = data.xxx; // console.log('totalPage',totalPage,'curPageLen',curPageLen); //设置列表数据 if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表 this.dataList = this.dataList.concat(curPageData); //追加新数据 // 请求成功,隐藏加载状态 //方法一(推荐): 后台接口有返回列表的总页数 totalPage // this.mescroll.endByPage(curPageLen, totalPage); //方法二(推荐): 后台接口有返回列表的总数据量 totalSize this.mescroll.endBySize(curPageLen, totalSize); }).catch(err => { this.mescroll.endErr() console.log(err) }); }, /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/ reloadList() { this.mescroll.resetUpScroll(); }, search(e){ this.reloadList(); }, itemClick(item){ // console.log('itemClick',item); uni.$u.route('/pages/newsdetails', { id: item.id, type:'news' }); } } } </script> <style> page{ background-color: #F9FAFD; } </style> <style lang="scss" scoped> .search-wrap{ padding: 20rpx 34rpx; } .list{ .item{ &.show{ animation: slide-top 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; } background-color: #fff; border-radius: 24rpx; margin-bottom: 24rpx; overflow: hidden; .img{ border-radius: 12rpx; width: 220rpx; height: 200rpx; } .text{ height: 200rpx; box-sizing: border-box; padding:24rpx 28rpx; // flex: 1; width: calc( 100% - 220rpx ); .title{ font-size: 28rpx; font-weight: bold; color: #333333; margin-bottom: 16rpx; } .con{ font-size: 24rpx; font-weight: 400; color: #6B6B6B; line-height: 36rpx; margin-bottom: 20rpx; } .time{ font-size: 20rpx; font-weight: 400; color: #C0C0C0; line-height: 22rpx; } } } } </style>