uniapp微信小程序通用,上拉加载,下拉刷新,page分页+筛选条件

本项目是一个公众号,index界面,tab栏实现上拉加载,下拉刷新+筛选功能
在这里插入图片描述

data() {
			return {
				ViewHost:ImageViewHost,
				cityPickerValueDefault: [0, 0, 1],
				pickerText: "",
				banners:[],
				customerId: jwt_decode(uni.getStorageSync('token')).customerId,
				// 公司
				companyData:[],
				page:1,
				// 职位
				optionData:[],
				/* 上拉刷新 */
				loadingType: 0,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				},
				city:'',
				param:{
					positionPage:1,
					positionPageSize:10,
					companyPage:1,
					companyPageSize:10,					
				},
				tabIndex:0,
				currentCompanyData:{
					totalPage:1
				},
				currentPositionData:{
					totalPage:1
				},
				recommendFlag:true,
				newFlag:true,
			};
		},
/*下拉刷新*/
		onPullDownRefresh: function() {
			this.resetParam();  //初始化数据
			this.fetchData(); //遍历数据
		},
		/*上拉加载*/
		onReachBottom:function(){
			console.log('上拉加载');
			if(this.tabIndex == 0){
		    	// 当前页码小于总页码数,page+1
				if(this.param.companyPage < Number(this.currentCompanyData.totalPage)) {
					this.recommendFlag = false;
					this.param.companyPage = this.param.companyPage + 1;
					this.fetchData();
				}else {
					this.recommendFlag = true;
					// uni.showToast({
					// 	title:'已经到底啦'
					// })
				}
			}else if(this.tabIndex == 1) {
				this.newFlag = false;
				if(this.param.positionPage < Number(this.currentPositionData.totalPage)) {
					this.param.positionPage = this.param.positionPage + 1;
					this.fetchData();
				}else {
					this.newFlag = true;
					// uni.showToast({
					// 	title:'已经到底啦'
					// })
				}
			}
		},
//每次都是获取参数,调page分页方法
resetParam(){
			this.param.positionPage=1;
			this.param.positionPageSize=10;
			this.param.companyPage=1;
			this.param.companyPageSize=10;
			this.companyData = [];
			this.optionData = [];
			this.currentCompanyData = {};
			this.currentPositonData = {};
			this.city = '';
		},
fetchData() {
   //  公司推荐
	if(this.tabIndex == 0) {
		this.fetchCompanyData();
	// 职位推荐
	}else if(this.tabIndex == 1) {
		this.fetchPositionData();
	}
},
// 城市筛选
onConfirm(e) {
				this.resetParam();
				this.pickerText = JSON.stringify(e);
				let cityObj = {};
				cityObj.province = e.labelArr[0];
				cityObj.city = e.labelArr[1];
				this.city = JSON.stringify(cityObj);
				this.fetchData();
			},
	// 公司
			getCompanyPage() {
				let that = this;
				that.$myRequest({
					url:'COCREATE-SERVICE/companypage',
					method:'POST',
					data:{
						customerId: that.customerId,
						page: that.param.companyPage,
						pageSize: 10,
						city:that.city,
					}
				}).then(res => {
					that.currentCompanyData = res.data;
					console.log('that.currentCompanyData',that.currentCompanyData)
					console.log('res',res.data.data);
					res.data.data.forEach((item => {
						item.industry = JSON.parse(item.industry);
						item.city = JSON.parse(item.city);
						if(item.label !== ''){
							item.label = JSON.parse(item.label);
						}
					}))
					that.companyData = that.companyData.concat(res.data.data);
					uni.hideNavigationBarLoading();
				    uni.stopPullDownRefresh();	//得到数据后停止下拉刷新
				})
			},
// 职位
			getpositionPage() {
				this.$myRequest({
					url:'COCREATE-SERVICE/professionalpage',
					method:'POST',
					data:{
						customerId: this.customerId,
						page: this.param.positionPage,
						pageSize: 10,
						city:this.city,
					}
				}).then(res => {
					this.currentPositionData = res.data;
					console.log('res',res);
					res.data.data.forEach(item => {
						if(item.label != '' || item.label != null || item.label != undefined) {
							item.label = eval(item.label);
						}
					})
					this.optionData =  this.optionData.concat(res.data.data);
					console.log('this.optionData',this.optionData)
					uni.hideNavigationBarLoading();
					uni.stopPullDownRefresh();	//得到数据后停止下拉刷新
				})
			},
<!-- 上拉刷新 -->
			<view class="loading-text" v-if="this.tabIndex == 0">
					{{recommendFlag ? contentText.contentnomore : contentText.contentdown}}
			</view>
			<view class="loading-text" v-else>
					{{newFlag ? contentText.contentnomore : contentText.contentdown}}
			</view>
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值