myWork.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. var app = getApp();
  2. let touchDotX = 0; //X按下时坐标
  3. let touchDotY = 0; //y按下时坐标
  4. let interval; //计时器
  5. let time = 0;
  6. Page({
  7. data: {
  8. active: 0,
  9. workList: [], //工单列表
  10. page: 1,
  11. current: 4
  12. },
  13. // 触摸开始事件
  14. touchStart: function(e) {
  15. touchDotX = e.touches[0].pageX; // 获取触摸时的原点
  16. touchDotY = e.touches[0].pageY;
  17. // 使用js计时器记录时间
  18. interval = setInterval(function() {
  19. time++;
  20. }, 100);
  21. },
  22. // 触摸结束事件
  23. touchEnd: function(e) {
  24. var that = this;
  25. let touchMoveX = e.changedTouches[0].pageX;
  26. let touchMoveY = e.changedTouches[0].pageY;
  27. let tmX = touchMoveX - touchDotX;
  28. let tmY = touchMoveY - touchDotY;
  29. console.log(time)
  30. if (time < 20) {
  31. let absX = Math.abs(tmX);
  32. let absY = Math.abs(tmY);
  33. if (absX > 2 * absY) {
  34. that.setData({
  35. workList: ''
  36. })
  37. if (tmX < 0) {
  38. if (that.data.active >= 3) return
  39. that.setData({
  40. active: that.data.active + 1
  41. })
  42. that.goTop();
  43. that.getWork();
  44. } else {
  45. if (that.data.active <= 0) return
  46. that.setData({
  47. active: that.data.active - 1
  48. })
  49. that.goTop();
  50. that.getWork();
  51. }
  52. }
  53. }
  54. clearInterval(interval); // 清除setInterval
  55. time = 0;
  56. },
  57. onLoad: function(options) {
  58. this.getWork();
  59. wx.hideHomeButton();
  60. },
  61. scanCode() {
  62. wx.redirectTo({
  63. url: '/pages/logs/logs?scan=' + 1,
  64. })
  65. },
  66. getWork() {
  67. let planned = '';
  68. if (this.data.active == 0) {
  69. planned = 1
  70. } else if (this.data.active == 1) {
  71. planned = 2
  72. } else if (this.data.active == 2) {
  73. planned = 3
  74. } else if (this.data.active == 3) {
  75. planned = 4
  76. }
  77. let data = {
  78. planned: planned
  79. }
  80. app.request('work_order/list', data, 'GET').then(res => {
  81. this.setData({
  82. workList: res.data.data
  83. })
  84. })
  85. },
  86. //回到顶部
  87. goTop: function(e) { // 一键回到顶部
  88. if (wx.pageScrollTo) {
  89. wx.pageScrollTo({
  90. scrollTop: 0
  91. })
  92. }
  93. },
  94. wordDetail: function(e) {
  95. //工单详情
  96. wx.navigateTo({
  97. url: '/pages/workDetail/workDetail?id=' + e.currentTarget.dataset.id,
  98. })
  99. },
  100. onChange(event) {
  101. let that = this;
  102. that.setData({
  103. workList: '',
  104. active: event.detail.name,
  105. page: 1
  106. })
  107. that.getWork();
  108. that.goTop();
  109. },
  110. onReady: function() {
  111. },
  112. onShow: function() {
  113. },
  114. onHide: function() {
  115. },
  116. onUnload: function() {
  117. },
  118. onPullDownRefresh: function() {
  119. wx.showNavigationBarLoading();
  120. this.getWork(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
  121. },
  122. onReachBottom: function() {
  123. var that = this;
  124. wx.showLoading({
  125. title: '加载中',
  126. })
  127. let planned = '';
  128. var page = that.data.page + 1
  129. if (that.data.active == 0) {
  130. planned = 1
  131. } else if (that.data.active == 1) {
  132. planned = 2
  133. } else if (that.data.active == 2) {
  134. planned = 3
  135. } else if (that.data.active == 3) {
  136. planned = 4
  137. }
  138. let data = {
  139. planned: planned,
  140. page: page
  141. }
  142. app.request('work_order/list', data, 'GET').then(res => {
  143. console.log(res)
  144. wx.hideLoading()
  145. if (res.statusCode == 200) {
  146. if (res.data.data.length > 0) {
  147. that.setData({
  148. workList: that.data.workList.concat(res.data.data),
  149. page
  150. })
  151. } else {
  152. wx.showToast({
  153. title: '没有更多了~',
  154. icon: 'none'
  155. })
  156. }
  157. }
  158. })
  159. },
  160. onShareAppMessage: function() {
  161. }
  162. })