var app = getApp(); let touchDotX = 0; //X按下时坐标 let touchDotY = 0; //y按下时坐标 let interval; //计时器 let time = 0; Page({ data: { active: 0, workList: [], //工单列表 page: 1, current: 4 }, // 触摸开始事件 touchStart: function(e) { touchDotX = e.touches[0].pageX; // 获取触摸时的原点 touchDotY = e.touches[0].pageY; // 使用js计时器记录时间 interval = setInterval(function() { time++; }, 100); }, // 触摸结束事件 touchEnd: function(e) { var that = this; let touchMoveX = e.changedTouches[0].pageX; let touchMoveY = e.changedTouches[0].pageY; let tmX = touchMoveX - touchDotX; let tmY = touchMoveY - touchDotY; console.log(time) if (time < 20) { let absX = Math.abs(tmX); let absY = Math.abs(tmY); if (absX > 2 * absY) { that.setData({ workList: '' }) if (tmX < 0) { if (that.data.active >= 3) return that.setData({ active: that.data.active + 1 }) that.goTop(); that.getWork(); } else { if (that.data.active <= 0) return that.setData({ active: that.data.active - 1 }) that.goTop(); that.getWork(); } } } clearInterval(interval); // 清除setInterval time = 0; }, onLoad: function(options) { this.getWork(); wx.hideHomeButton(); }, scanCode() { wx.redirectTo({ url: '/pages/logs/logs?scan=' + 1, }) }, getWork() { let planned = ''; if (this.data.active == 0) { planned = 1 } else if (this.data.active == 1) { planned = 2 } else if (this.data.active == 2) { planned = 3 } else if (this.data.active == 3) { planned = 4 } let data = { planned: planned } app.request('work_order/list', data, 'GET').then(res => { this.setData({ workList: res.data.data }) }) }, //回到顶部 goTop: function(e) { // 一键回到顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } }, wordDetail: function(e) { //工单详情 wx.navigateTo({ url: '/pages/workDetail/workDetail?id=' + e.currentTarget.dataset.id, }) }, onChange(event) { let that = this; that.setData({ workList: '', active: event.detail.name, page: 1 }) that.getWork(); that.goTop(); }, onReady: function() { }, onShow: function() { }, onHide: function() { }, onUnload: function() { }, onPullDownRefresh: function() { wx.showNavigationBarLoading(); this.getWork(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(); }, onReachBottom: function() { var that = this; wx.showLoading({ title: '加载中', }) let planned = ''; var page = that.data.page + 1 if (that.data.active == 0) { planned = 1 } else if (that.data.active == 1) { planned = 2 } else if (that.data.active == 2) { planned = 3 } else if (that.data.active == 3) { planned = 4 } let data = { planned: planned, page: page } app.request('work_order/list', data, 'GET').then(res => { console.log(res) wx.hideLoading() if (res.statusCode == 200) { if (res.data.data.length > 0) { that.setData({ workList: that.data.workList.concat(res.data.data), page }) } else { wx.showToast({ title: '没有更多了~', icon: 'none' }) } } }) }, onShareAppMessage: function() { } })