vue滚动分页加载以及监听事件处理
<template>
<div class="bodyContainer">
<div class="allContent" id="pageTop">
<!-- 经纪人 -->
<div class="brokerBlock" v-show="isBroker && !loading">
<broker :list="brokerInfo" v-show="Object.keys(brokerInfo).length>0" @change="protocolClick" @remove="reomoveBrokerClick"></broker>
</div>
<!-- 我的艺人 -->
<div class="con artistCon" v-show="artistTotal > 0">
<div class="title " :class="{isFixed:!isBroker}" id="artistTitle">
我的艺人<span class="gray">({{artistTotal}}位)</span>
</div>
<ul class="artistList">
<li class="box artistItem" v-for="item of artistInfoList" :key="item.userInfo.userId" >
<div class="personBlock">
<div class="person" @click="openUserClick(item.userInfo.userId)">
<div class="showImg">
<img :src="item.userInfo.userThumUrl" />
<template v-if="item.userInfo.kolFlag">
<div class="icon c_kol" v-if="item.userInfo.kolFlag"></div>
</template>
<template v-else>
<div class="icon c_company" v-if="item.userInfo.upSignType == '1'"></div>
<div class="icon c_person" v-if="item.userInfo.upSignType == '0'"></div>
</template>
</div>
<div class="name" :class="{artistName:item.isRelease || item.status>=1}">{{item.userInfo.nickName}}</div>
<div class="situation" v-if="item.isRelease">关系已解除</div>
<div class="situation" v-if="item.status == 1">帐号已冻结</div>
<div class="situation" v-if="item.status == 2">帐号已暂停</div>
</div>
<div class="action" v-if="item.userInfo">
<em class="chatIcon" v-if="item.userInfo.userId" @click="openChatClick(item.userInfo.userId)"></em>
<em v-if="!item.isRelease" class="revisionIcon" @click="revisionClick(item)"></em>
<em v-if="!item.isRelease" class="removeIcon" @click="removeArtistClick(item.userInfo.hwUserId)"></em>
</div>
</div>
<div v-if="!item.isRelease" class="works">本周作品更新 {{item.weekOpusNum}}</div>
<div class="divideInfo" v-if="!item.isRelease">
<span v-if="item.shareRate">TA的分成占比{{item.shareRate}}</span>
<span v-if="item.shareAmount">· 累计分取 {{regFenToYuan(item.shareAmount)}}</span>
</div>
<div class="divideInfo" v-if="item.isRelease && item.shareAmount">
<span>累计分得{{regFenToYuan(item.shareAmount)}}</span>
</div>
<div v-if="item.isRelease" class="inviteAgainBtn" :class="{active:successInvite.indexOf(item.userInfo.hwUserId) > -1 }" @click="inviteClick(item.userInfo.hwUserId)">重新邀请</div>
<div class="tips" v-if="item.remark">{{item.remark}}</div>
<div v-if="!item.isRelease" class="protocol" @click="protocolClick">合作协议</div>
</li>
</ul>
<!-- 上拉加载 -->
<div class="loadTxt"><em v-if="lock" class="rotate"></em>{{loadTxt}}</div>
</div>
<!-- 全局加载 -->
<div class="loadContainer" v-if="loading"><em class="rotate"></em>正在加载中...</div>
<!-- 数据为空 -->
<empty v-if="Object.keys(brokerInfo).length < 1 && artistTotal < 1 && !loading">
<p class="note">你还没有经纪人和艺人哦</p>
<router-link class="invite" :to="inviteLink">邀请艺人</router-link>
</empty>
</div> <router-link class="rule" :to="ruleLink">查看规则</router-link>
<div class="inviteBlock" v-if="Object.keys(brokerInfo).length > 0 || artistTotal > 0">
<router-link class="inviteArtistBtn" :to="inviteLink">邀请艺人</router-link>
</div>
<!-- 协议弹出层 -->
<pop-up @change="closeLayer" v-if="popuShow">
<template v-if="protocolPopShow">
<h2 class="title">{{protocolTitle}}</h2>
<div class="content" v-html="protocolCon"></div>
<div class="confirmBtn" @click="closeNoClick">确认</div>
</template>
<template v-else-if="actionPopShow">
<h2 class="title">{{protocolTitle}}</h2>
<div class="content" v-html="protocolCon"></div>
<div class="confirmBtn" :class="{active:isActive}" @click="confirmProtocol">{{btntxt}}</div>
<div class="popCloseCon" @click="closeActionClick"></div>
</template>
<template v-else-if="removePopshow">
<div class="content center">
解除关系后经纪人将不再获得艺人的收益分成,对方同意后将在下个结算账期生效
</div>
<div class="action">
<div class="btn confirmRemove" @click="confirmRemoveClick">确认解除</div><div class="btn noConfirmRemove" @click="closeLayer">我再想想</div>
</div>
</template>
</pop-up>
<!-- 比例弹出层 -->
<scale @change="closeScale" @send="sendAjaxClick" :number="scaleCount" :scaleBtn="scaleBtn" :scaleDesc="scaleDesc" v-show="isScale" :userId="userId"></scale>
</div>
</template>
<script>
import broker from './components/broker';
import empty from './components/empty';
import PopUp from './components/PopUp';
import scale from './components/scale';
const pageSize=6;
let t='';
export default {
name: "Index",
data() {
return {
popuShow:false, //弹窗展示
protocolPopShow:false,//经纪人协议
actionPopShow:false,//操作协议层
removePopshow:false,//解除确认操作层
isScale:false,//比例弹出层
ruleLink: '/rule.html',
inviteLink:'/search.html',
userId:'',
isActive:true,//操作协议按钮灰色显示
sencond:5,//秒数
btntxt:'', //操作协议层按钮文字显示
scaleValue:'',//分成比例
scaleDesc:'',//比例弹窗描述
scaleBtn:'',
scaleCount:'50%',
personValue:'',//艺人还是经纪人
brokerInfo:{}, //经纪人列表
artistInfoList:[], //查询艺人列表
artistTotal:0,//查询艺人列表总数
isShow:false, // 是否显示滚动条
successInvite:[],//发送邀请成功的华为id取数
totalPage:1,
paramsValue:[],
searchBarFixed:'',
isBroker:true,
offsetTop:0,
loading: true, //一开始页面就要加载
pageNo:1,//当前页
lock : false, //当在请求数据时,滚动时锁定不能再发送分页请求
loadTxt:'' ,
protocolTitle:'',//协议标题
protocolCon:'' //协议内容
};
},
components:{broker,empty,PopUp,scale},
mounted: function () {
this.protocolAjax();
this.broker();
this.featchData(); window.addEventListener('scroll', this.handleScroll);
},
watch:{
$route(to,from){
window.scrollTo(0,20);
if(to.name == 'index'){
window.addEventListener('scroll', this.handleScroll);
} else {
window.removeEventListener('scroll', this.handleScroll)
}
}
},
methods: {
handleScroll () {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;//滚动条滚动的长度
let _offsetHeight = document.querySelector('#pageTop').offsetHeight; //是指元素内容的高度
let brokeHeight = document.querySelector('.brokerBlock').offsetHeight; //经纪人内容高度
let clientHeightValue = document.documentElement.clientHeight || document.body.clientHeight; console.log("scrollTop",scrollTop,"_offsetHeight",_offsetHeight,"brokeHeight",brokeHeight,"clientHeightValue",clientHeightValue)
if(scrollTop > brokeHeight){ //滚动条滚动的距离超过经纪人的内容高度
this.isBroker = false;
}else{
this.isBroker = true;
}
if(this.pageNo > 1){
//距离底部距离50就加载数据
if(_offsetHeight - clientHeightValue - scrollTop <= 50 ){
if (this.totalPage <= this.pageNo) {
setTimeout(() => {
//mui.toast("已经没有更多了~");
this.loadTxt='当当当~已经到底啦~';
}, 300)
return;
}else{
this.featchData();
}
}
}
},
//获取数据函数
featchData:function (){
//如果已经在加载数据,不可以重复加载
if (this.lock) return;
this.lock = true;
this.loadTxt='正在加载中...';
this.$request.post(_basePath + '/activity/page20191018/queryArtistList.html',{pageNo:this.pageNo,pageSize:pageSize}).then((res) => {
this.artistTotal = res.total; this.totalPage = res.total % pageSize > 0 ? Math.floor(res.total / pageSize + 1) : res.total / pageSize;
let result = [];
res.artistInfoList.forEach((item) =>{
result.push(item.userInfo.hwUserId)
})
this.$request.post(_basePath + '/activity/page20191018/batchQueryUserAccount.html',{userIdList:result}).then((res2) => {
res2.userAccountDetailList.forEach((item,i) =>{
res.artistInfoList[i].status = item.status;
})
this.artistInfoList = res.artistInfoList;
}).catch(() => {}); this.artistInfoList = [...this.artistInfoList, ...res.artistInfoList];
++this.pageNo;
this.lock = false;
this.loading = false;
this.loadTxt='';
}).catch(() => {
this.lock = false;
this.loading = false;
})
},
//查询经纪人列表
broker () {
this.$request.post(_basePath + '/activity/page20191018/queryBroker.html').then((res) => {
let result = [];
result.push(res.brokerInfo.userInfo.hwUserId)
this.$request.post(_basePath + '/activity/page20191018/batchQueryUserAccount.html',{userIdList:result}).then((res2) => {
res.brokerInfo.status = res2.userAccountDetailList[0].status;
this.brokerInfo = res.brokerInfo;
}).catch(() => {});
}).catch(() => {})
},
//点击调起个人主页
openUserClick (item) {
console.log(item)
var userId = item;
mui.openClient({"pageType": "userHome","userId":item});
},
//点击调起聊天窗口
openChatClick (item){
console.log(item)
var userId = item;
mui.openClient({"pageType": "chat","userId":item});
},
//艺人解除关系
removeArtistClick (id) {
//1:艺人,0 – 不是(只是校验是否可以解约
this.userId = id;
this.personValue = 1;
this.releaseRelationship (1,0);
},
//经纪人解除关系
reomoveBrokerClick (id) {
this.userId = id;
this.personValue = 0;
this.releaseRelationship (0,0);
},
//重新调整分成比例
revisionClick (item) {
this.isScale = true;
this.userId = item.userInfo.hwUserId;
this.scaleCount = item.shareRate;
this.scaleDesc = '调整分成需对方确认,选择双方都认可的分成比例可以提高调整成功率哦~';
this.scaleBtn = '确认调整';
},
//重新邀请
inviteClick (id) {
if(this.successInvite.indexOf(id) > -1){
return;
}
this.isScale = true;
this.userId = id;
this.scaleDesc = '邀请成功后你可获取该用户部分收益,选择双方都认可的分成比例可以提高邀请成功率哦~';
this.scaleBtn = '发送邀请';
this.scaleCount = '50%';//邀请比例统一为50%
},
//点击发送邀请
sendAjaxClick (value){ this.scaleValue = value;
this.popuShow = true;
this.actionPopShow = true;//操作协议层展示
this.isScale = false;
this.isActive = true;
this.sencond = 5 ;
this.timer();
},
//5s时间倒计时
timer () {
if (this.sencond > 0) {
if(this.scaleDesc.indexOf("调整") > -1){
this.btntxt="已阅读同意并确认调整("+this.sencond+"s)";
}else{
this.btntxt="已阅读同意并确认邀请("+this.sencond+"s)";
}
this.sencond--;
t=setTimeout(this.timer, 1000);
} else{
this.isActive = false;
this.sencond = 5;
if(this.scaleDesc.indexOf("调整") > -1){
this.btntxt="已阅读同意并确认调整";
}else{
this.btntxt="已阅读同意并确认邀请";
} }
},
//已阅读同意并确认
confirmProtocol () {
if(this.isActive){
return false;
}
if(this.scaleDesc.indexOf("调整") > -1){
//比例调整请求
this.revisionAjax();
}else{
//邀请请求
this.sendAjax();
} },
//发送邀请请求
sendAjax () {
this.$request.post(_basePath + '/activity/page20191018/inviteArtist.html',{userId: this.userId,shareRate:this.scaleValue}).then((res) => {
mui.toast("已发送邀请,对方接受后会通知你哦",2000);
this.successInvite.push(this.userId);
this.closeActionClick();
}).catch(() => {})
},
//调整比例请求
revisionAjax () {
this.$request.post(_basePath + '/activity/page20191018/adjustShareRate.html',{userId: this.userId,shareRate:this.scaleValue}).then((res) => {
mui.toast("已发送调整消息,对方接受后会通知你哦",2000);
this.closeActionClick();
}).catch(() => {})
},
//解除关系操纵请求
releaseRelationship (a,b) {
//a 0:经纪人 1艺人
//b 0:校验 1:可以解约请求
this.$request.post(_basePath + '/activity/page20191018/releaseRelationship.html',{userId: this.userId,role:a,realRelease:b}).then((res) => {
// mui.toast("已发送解除消息,对方接受后会通知你哦",2000);
if(res.releaseStatus == '0'){ //不能解约
mui.toast(res.remark,2000)
}else if(res.releaseStatus == 1){ //可解约
this.popuShow = true;
this.actionPopShow = false;
this.protocolPopShow = false;
this.removePopshow = true;
}else if(res.releaseStatus == 2){
mui.toast("已发送解除消息,对方接受后会通知你哦",2000);
}
}).catch(() => {})
},
//确认解除
confirmRemoveClick(){
this.closeLayer();
console.log(this.personValue);
this.releaseRelationship (this.personValue,1)
}, //关闭操作协议弹窗
closeActionClick() {
this.popuShow = false;
this.actionPopShow = false;
clearTimeout(t);//清除倒计时
},
//点击合作协议
protocolClick(){
this.protocolPopShow = true;
this.popuShow = true;
}, //关闭弹窗
closeLayer(){
this.popuShow = false;
this.actionPopShow = false;
this.protocolPopShow = false;
this.removePopshow = false;
clearTimeout(t);//清除倒计时
},
//关闭解除操作确认
closeNoClick () {
this.popuShow = false;
this.protocolPopShow = false;
},
//关闭分成比例弹窗
closeScale(){
this.isScale = false;
},
//分转为元
regFenToYuan (fen) {
var num = fen;
num=fen*0.01;
num+='';
var reg = num.indexOf('.') >-1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
num=num.replace(reg,'$1');
num = this.toDecimal2(num)
return num
},
toDecimal2 (x) {
var f = parseFloat(x);
if (isNaN(f)) {
return false;
}
var f = Math.round(x * 100) / 100;
var s = f.toString();
var rs = s.indexOf('.');
if (rs < 0) {
rs = s.length;
s += '.';
}
while (s.length <= rs + 2) {
s += '0';
}
return s;
},
//协议请求
protocolAjax() {
this.$request.post(_basePath + '/activity/page20191018/queryProtocol.html',{type:0}).then((res) => {
this.protocolTitle = res.title;
this.protocolCon = res.content;
}).catch(() => {})
}
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll)
}
};
</script> <style lang="scss" scoped>
@import "index";
.artistCon{padding-bottom:1.8rem;}
.loadTxt{
margin-top:.2rem;
height:.4rem;
line-height:.4rem;
text-align:center;
color:#B6B3C5;
font-size:.24rem;
} .allContent{
overflow:auto;
-webkit-overflow-scrolling: touch; }
#pageTop{
.isFixed{
position:fixed;
top:0;
z-index:100;
height:.9rem;
background: #121223;
width:100%;
}
}
</style>
注意事项
1、监听滚动处理scroll
mounted: function () {
this.protocolAjax();
this.broker();
this.featchData(); window.addEventListener('scroll', this.handleScroll);
},
2、跳到另外一个页面再此返回手机上会出现一个黑屏,触摸才会把黑屏去掉,解决办法就是在返回页面的时候,再滚动到顶部
watch:{
$route(to,from){
window.scrollTo(0,20);
if(to.name == 'index'){
window.addEventListener('scroll', this.handleScroll);
} else {
window.removeEventListener('scroll', this.handleScroll)
}
}
},
3、scroll完以后要destroy
destroyed() {
window.removeEventListener('scroll', this.handleScroll)
}
4、分页滚动处理
//获取数据函数
featchData:function (){
//如果已经在加载数据,不可以重复加载
if (this.lock) return;
this.lock = true;
this.loadTxt='正在加载中...';
this.$request.post(_basePath + '/activity/page20191018/queryArtistList.html',{pageNo:this.pageNo,pageSize:pageSize}).then((res) => {
this.artistTotal = res.total; this.totalPage = res.total % pageSize > 0 ? Math.floor(res.total / pageSize + 1) : res.total / pageSize;
let result = [];
res.artistInfoList.forEach((item) =>{
result.push(item.userInfo.hwUserId)
})
this.$request.post(_basePath + '/activity/page20191018/batchQueryUserAccount.html',{userIdList:result}).then((res2) => {
res2.userAccountDetailList.forEach((item,i) =>{
res.artistInfoList[i].status = item.status;
})
this.artistInfoList = res.artistInfoList;
}).catch(() => {}); this.artistInfoList = [...this.artistInfoList, ...res.artistInfoList];
++this.pageNo;
this.lock = false;
this.loading = false;
this.loadTxt='';
}).catch(() => {
this.lock = false;
this.loading = false;
})
},
handleScroll () {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;//滚动条滚动的长度
let _offsetHeight = document.querySelector('#pageTop').offsetHeight; //是指元素内容的高度
let brokeHeight = document.querySelector('.brokerBlock').offsetHeight; //经纪人内容高度
let clientHeightValue = document.documentElement.clientHeight || document.body.clientHeight; console.log("scrollTop",scrollTop,"_offsetHeight",_offsetHeight,"brokeHeight",brokeHeight,"clientHeightValue",clientHeightValue)
if(scrollTop > brokeHeight){ //滚动条滚动的距离超过经纪人的内容高度
this.isBroker = false;
}else{
this.isBroker = true;
}
if(this.pageNo > 1){
//距离底部距离50就加载数据
if(_offsetHeight - clientHeightValue - scrollTop <= 50 ){
if (this.totalPage <= this.pageNo) {
setTimeout(() => {
//mui.toast("已经没有更多了~");
this.loadTxt='当当当~已经到底啦~';
}, 300)
return;
}else{
this.featchData();
}
}
}
},
vue滚动分页加载以及监听事件处理的更多相关文章
- vue滚动分页加载
做了一个项目,要求将后台数据滚动加载. 滚动加载必须要求后台传的接口中由pageSize和pageIndex两个参数,来判断每次传数据的条数和数据的页码. 首先要判断滑轮是向上滚动还是向下滚动,可以在 ...
- oracle_协议适配器错误_协议适配器不可加载_TNS监听程序在connect-data中未获得service-name
最近在使用powerdesigner连接远程oracle进行反向工程操作时,出现了一些问题,这些问题很普遍,大多是由于配置引起的 说明:(1)远程数据库版本问 oracle11g 64bit (2)本 ...
- 微信小程序实现滚动分页加载更多
参考网址:https://www.cnblogs.com/Smiled/p/8203306.html 1.wxml: <view class='myScroll' style='float:le ...
- vue.js 分页加载,向上滑动,依次加载数据。
export default { layout: 'default', data(){ return{ page:1, pageSize:10, orderListArr:[], prodListLo ...
- Android基本控件之listView(三)<用ListView实现分页加载>
我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...
- 【Android进阶】Listview分页加载数据的实现
Listview分页加载数据的实现 public class MainActivity extends Activity { protected static final int SUCCESS_GE ...
- Vue图片懒加载插件
图片懒加载是一个很常用的功能,特别是一些电商平台,这对性能优化至关重要.今天就用vue来实现一个图片懒加载的插件. 这篇博客采用"三步走"战略--Vue.use().Vue.dir ...
- ListView实现分页加载(三)实现分页加载
在上一篇中,我们实现了底部布局(即带上了进度条).没有读过的朋友可以点击下面的链接: http://www.cnblogs.com/fuly550871915/p/4866966.html 但是进度条 ...
- Android中Listview实现分页加载效果OnScrollListener
activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...
随机推荐
- ionic4.x网络请求
创建common服务: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/ ...
- 【Java】Spring快速入门(一)
Spring介绍 Spring可以轻松创建Java企业应用程序.它提供了在企业环境中使用Java语言所需的一切,支持Groovy和Kotlin作为JVM上的替代语言,并可根据应用程序的需要灵活地创建多 ...
- python设计模式第2版
python设计模式第2版 目录 第1章 设计模式简介 1 1.1 理解面向对象编程 1 1.1.1 对象 2 1.1.2 类 2 1.1.3 方法 2 1.2 面向对象编程的主要概念 3 1.2.1 ...
- doris: shell invoke .sql script for doris and passing values for parameters in sql script.
1. background in most cases, we want to execute sql script in doris routinely. using azkaban, to l ...
- 分类:logistic回归
import numpy as np import matplotlib.pyplot as plt x=np.linspace(-1,1,200) y=1/(1+np.exp(10*x-1)) pl ...
- @media 适配兼容
/* 兼容iphone4/4s */ @media (device-height:480px) and (-webkit-min-device-pixel-ratio:2){ } /* 兼容iphon ...
- robot:循环遍历数据库查询结果是否满足要求
使用list类型变量@{}接收查询结果,再for循环遍历每行数据,取出需要比较的数值
- Brave浏览器
Brave是基于Chromium的开源Web浏览器,具有更快的页面加载速度,并且默认情况下会阻止广告和跟踪器.整合了一些其它浏览器所没有的功能,其中包括被称为 Basic Attention Toke ...
- 【Chrome插件】Session Buddy--搁置标签页
写在前面:看文章前请先看文章写作时间,避免浪费时间.2019-09-10 使用场景 Chrome打开许多网页,临时有事需要把当前的一些标签页一键保存,等待事后继续处理. 操作演示 原片地址:https ...
- OneNote中更改英文输入默认不是微软雅黑的问题
win10下的终极版解决方案: 1.进入C:\Windows\Fonts找到Calibri字体,点进去后先右键Calibri常规-属性-安全-高级,将所有者从“TrustedInstaller”更改为 ...