// pages/found2/index2.js var startY, endY Page({ /** * 页面的初始数据 */ data: { page : 1, has_more: true, lists : [], share_id: '', currentIndex : 0, safeArea : getApp().globalData.safeArea, playing : false }, onLoad(e){ this.setData({ share_id : e.share_id || '' }) getApp().globalData.inviteText = e.invite || '' this.getList() this.videoContext = wx.createVideoContext('found-cont-video') }, onHide(){ if(this.data.share_id){ this.setData({ share_id:'' }) } }, getList(){ let params = { page:this.data.page, share_id:this.data.share_id } wx.$api.found.foundIndex(params).then(res => { let lists = this.data.lists if(this.data.page == 1){lists = []} lists = this.data.lists.concat(res.data.data) this.setData({ lists : lists, has_more: res.data.page.has_more, }) if(this.data.currentIndex == 0){ this.onVideoPlay() } }).catch(err=>{ wx.showToast({ title: err.message, icon :'none', mask :true, duration:2000 }) setTimeout(()=>{ this.setData({ loading:false }) },3000) }) }, onTouchStart(e) { let { clientY } = e.changedTouches[0] startY = clientY }, onTouchEnd(e) { let { clientY } = e.changedTouches[0] endY = clientY let clientXY = startY - clientY console.log(clientXY) if(clientXY>60){ this.onIsDirection('next') }else if(clientXY < -60){ this.onIsDirection('prev') } }, onIsDirection(type){ let {currentIndex,lists} = this.data if(type == 'next'){ console.log('获取下一个') if(currentIndex!=lists.length-1){ currentIndex ++ this.setData({ currentIndex:currentIndex }) this.onVideoPlay() }else{ if(this.data.has_more){ this.setData({ page:this.data.page+1 }) this.getList() }else{ wx.showToast({ title: '没有更多了~', icon:'none', mask:true }) } } return } if(type == 'prev'){ if(currentIndex>0){ currentIndex -- this.setData({ currentIndex:currentIndex }) this.onVideoPlay() }else{ wx.showToast({ title: '没有更多了~', icon:'none', mask:true }) } return } }, onVideoPlay(){ if(this.data.lists[this.data.currentIndex].type == 'video'){ setTimeout(() => { this.videoContext.seek(0) this.videoContext.play() this.setData({ playing:true }) }, 200); }else{ this.videoContext.pause() this.videoContext.seek(0) this.setData({ playing:false }) } }, onVideoPause(){ if(this.data.playing){ this.videoContext.pause() this.setData({ playing:false }) }else{ this.videoContext.play() this.setData({ playing:true }) } }, // 预览图片 preImg(e){ let current = e.currentTarget.dataset.idx console.log(current) let urls = e.currentTarget.dataset.urls wx.previewImage({ urls, current:urls[current] }) }, // 收藏 doSubscribeFavorite(e){ let index= e.currentTarget.dataset.index let type = e.currentTarget.dataset.type let item = this.data.lists[index] let lists = this.data.lists wx.$api.found.foundSubscribeFavorite(item.id,type).then(res => { lists[index].is[`${type}`] = res.data.res lists[index].count[`${type}`] = res.data.count this.setData({ lists:lists }) }).catch(err=>{ wx.showToast({ title: err.message, icon :'none', mask :true, duration:2000 }) }) }, onShareAppMessage(e){ let {describe,id,share_cover}= e.target.dataset.obj return { title : describe, imageUrl: share_cover, path : "/pages/found/index?share_id=" + id + '&invite=' + wx.getStorageSync("invite") } }, })