Browse Source

修改下拉刷新

master
lihua 5 years ago
parent
commit
68a6fa3130
  1. 51
      pages/device/device.vue

51
pages/device/device.vue

@ -2,7 +2,7 @@
<view @touchstart="refreshStart" @touchmove="refreshMove" @touchend="refreshEnd"> <view @touchstart="refreshStart" @touchmove="refreshMove" @touchend="refreshEnd">
<refresh ref="refresh" @isRefresh='isRefresh'></refresh> <refresh ref="refresh" @isRefresh='isRefresh'></refresh>
<mSearch :mode="2" button="inside" @search="setSearch($event)" ></mSearch> <mSearch :mode="2" button="inside" @search="setSearch($event)" ></mSearch>
<scroll-view scroll-y="true" style="height:1000upx" @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper" show-scrollbar="true"> <scroll-view scroll-y="true" style="height:1000upx" @scrolltolower="scrolltolower" show-scrollbar="true">
<view class="cu-list menu-avatar margin-top"> <view class="cu-list menu-avatar margin-top">
<view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''" v-for="(item,index) in deviceList" :key="index" <view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''" v-for="(item,index) in deviceList" :key="index"
@touchstart="ListTouchStart" @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index"> @touchstart="ListTouchStart" @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index">
@ -25,7 +25,7 @@
</view> </view>
</view> </view>
</view> </view>
<view style="text-align: center;">----------------底线----------------</view> <view v-if="offset > total" style="text-align: center;">----------------底线----------------</view>
</scroll-view> </scroll-view>
<uni-fab :pattern="pattern" :content="content" horizontal="right" vertical="bottom" direction="vertical" @trigger="trigger"></uni-fab> <uni-fab :pattern="pattern" :content="content" horizontal="right" vertical="bottom" direction="vertical" @trigger="trigger"></uni-fab>
</view> </view>
@ -73,7 +73,7 @@ export default {
}, },
onLoad(){ onLoad(){
this.getUserInfo(); this.getUserInfo();
this.search(); this.search(false);
}, },
filters:{ filters:{
dateFilter(msg,flag){ dateFilter(msg,flag){
@ -86,10 +86,16 @@ export default {
} }
}, },
methods: { methods: {
fetchDeviceList(content,limit,offset){ fetchDeviceList(content,limit,offset,isAppend){
getDevice(content,limit,offset).then(response => { getDevice(content,limit,offset).then(response => {
this.deviceList = response.data.data.result
this.total = response.data.data.total this.total = response.data.data.total
if(isAppend){
if(this.deviceList.length < this.total){
this.deviceList.push(...response.data.data.result)
}
}else{
this.deviceList = response.data.data.result
}
}) })
}, },
handleDeleteItem(id,index){ handleDeleteItem(id,index){
@ -110,7 +116,9 @@ export default {
}, },
isRefresh(){ isRefresh(){
setTimeout(() => { setTimeout(() => {
this.search() this.offset = 0
this.pageNum = 1
this.search(false)
uni.showToast({ uni.showToast({
icon: 'success', icon: 'success',
title: '刷新成功' title: '刷新成功'
@ -120,10 +128,14 @@ export default {
}, },
setSearch(val) { setSearch(val) {
this.query = val this.query = val
this.search() this.offset = 0
this.pageNum = 1
this.search(false)
}, },
search(){ search(isAppend){
this.fetchDeviceList(this.query,this.limit,this.offset) this.fetchDeviceList(this.query,this.limit,this.offset,isAppend)
this.pageNum ++
this.offset = (this.pageNum - 1) * this.limit
}, },
getUserInfo() { getUserInfo() {
uni.getUserInfo({ uni.getUserInfo({
@ -157,29 +169,14 @@ export default {
this.listTouchDirection = null this.listTouchDirection = null
}, },
scrolltolower(e){ scrolltolower(e){
console.log(e) if(this.offset >= this.total) {
this.offset = (this.pageNum - 1) * this.limit
if(this.offset > this.total) {
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '已经到底啦' title: '已经到底啦'
}) })
return; return;
} }
setTimeout(() => { this.search(true)
this.search()
this.$refs.refresh.endAfter()
}, 1000)
this.pageNum ++
},
scrolltoupper(e){
console.log(e)
this.offset = 0
this.pageNum = 1
setTimeout(() => {
this.search()
this.$refs.refresh.endAfter()
}, 1000)
}, },
trigger(e) { trigger(e) {
console.log(e); console.log(e);
@ -199,7 +196,7 @@ export default {
postDevice(dev).then(response => { postDevice(dev).then(response => {
if(response.data){ if(response.data){
if(response.data.code == 0){ if(response.data.code == 0){
that.search() that.search(false)
uni.showToast({ uni.showToast({
icon: 'success', icon: 'success',
title: '添加终端成功' title: '添加终端成功'

Loading…
Cancel
Save