本项目是一个公众号,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>