myWork.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. option1: [], //区域选择
  13. value1: 0, //第一个显示什么
  14. areaID: '',
  15. url: '',
  16. screenHeight: '', //屏幕可视高度
  17. },
  18. // 触摸开始事件
  19. touchStart: function (e) {
  20. touchDotX = e.touches[0].pageX; // 获取触摸时的原点
  21. touchDotY = e.touches[0].pageY;
  22. // 使用js计时器记录时间
  23. interval = setInterval(function () {
  24. time++;
  25. }, 100);
  26. },
  27. // 触摸结束事件
  28. touchEnd: function (e) {
  29. var that = this;
  30. let touchMoveX = e.changedTouches[0].pageX;
  31. let touchMoveY = e.changedTouches[0].pageY;
  32. let tmX = touchMoveX - touchDotX;
  33. let tmY = touchMoveY - touchDotY;
  34. if (time < 20) {
  35. let absX = Math.abs(tmX);
  36. let absY = Math.abs(tmY);
  37. // if (absX > 2 * absY) {
  38. if (absX > 40 && (2 * absY) < 20) {
  39. that.setData({
  40. workList: ''
  41. })
  42. if (tmX < 0) {
  43. if (that.data.active >= 3) return
  44. that.setData({
  45. active: that.data.active + 1
  46. })
  47. that.goTop();
  48. that.getWork();
  49. } else {
  50. if (that.data.active <= 0) return
  51. that.setData({
  52. active: that.data.active - 1
  53. })
  54. that.goTop();
  55. that.getWork();
  56. }
  57. }
  58. }
  59. clearInterval(interval); // 清除setInterval
  60. time = 0;
  61. },
  62. onLoad: function (options) {
  63. let that = this;
  64. that.setData({
  65. screenHeight: app.globalData.screenHeight,
  66. option1: wx.getStorageSync('allArea'),
  67. })
  68. let curVal = wx.getStorageSync('curVal')
  69. if (curVal) {
  70. that.setData({
  71. value1: curVal
  72. })
  73. }
  74. let areaID = wx.getStorageSync('curId')
  75. if (areaID) {
  76. that.setData({
  77. areaID
  78. })
  79. } else {
  80. let id = that.data.option1[0].areaID
  81. that.setData({
  82. areaID: id
  83. })
  84. }
  85. that.menu = that.selectComponent("#menu");
  86. that.menu.changeTitle(that.data.option1[that.data.value1].text);
  87. that.getWork();
  88. wx.hideHomeButton();
  89. },
  90. change(e) {
  91. var that = this;
  92. var options = this.data.option1;
  93. var areaId = options[e.detail].areaID;
  94. this.setData({
  95. areaID: areaId
  96. })
  97. that.getWork();
  98. that.goTop();
  99. wx.setStorageSync('curVal', options[e.detail].value)
  100. wx.setStorageSync('curId', options[e.detail].areaID)
  101. },
  102. scanCode() {
  103. wx.reLaunch({
  104. url: '/pages/logs/logs?scan=' + 1,
  105. })
  106. },
  107. getWork() {
  108. wx.showLoading({
  109. title: '加载中',
  110. })
  111. let that = this;
  112. let planned = '';
  113. let url = "";
  114. let data = '&&put_area_id=' + that.data.areaID
  115. if (this.data.active == 0) {
  116. planned = 1
  117. url = "work_order/list?planned=" + planned + data
  118. } else if (this.data.active == 1) {
  119. planned = 2
  120. url = "work_order/myWorkOrderList?planned=" + planned + data
  121. } else if (this.data.active == 2) {
  122. planned = 3
  123. url = "work_order/myWorkOrderList?planned=" + planned + data
  124. } else if (this.data.active == 3) {
  125. planned = 4
  126. url = "work_order/myWorkOrderList?planned=" + planned + data
  127. }
  128. app.request(url, '', 'GET').then(res => {
  129. console.log(res,'工单')
  130. wx.hideLoading();
  131. this.setData({
  132. workList: res.data.data
  133. })
  134. })
  135. },
  136. //回到顶部
  137. goTop: function (e) { // 一键回到顶部
  138. if (wx.pageScrollTo) {
  139. wx.pageScrollTo({
  140. scrollTop: 0
  141. })
  142. }
  143. },
  144. wordDetail: function (e) {
  145. //工单详情
  146. wx.navigateTo({
  147. url: '/pages/workDetail/workDetail?id=' + e.currentTarget.dataset.id,
  148. })
  149. },
  150. onChange(event) {
  151. let that = this;
  152. that.setData({
  153. workList: '',
  154. active: event.detail.name,
  155. page: 1
  156. })
  157. that.getWork();
  158. that.goTop();
  159. },
  160. onPullDownRefresh: function () {
  161. wx.showNavigationBarLoading();
  162. this.getWork(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
  163. },
  164. onReachBottom: function () {
  165. var that = this;
  166. wx.showLoading({
  167. title: '加载中',
  168. })
  169. let planned = '';
  170. var page = that.data.page + 1
  171. if (that.data.active == 0) {
  172. planned = 1
  173. } else if (that.data.active == 1) {
  174. planned = 2
  175. } else if (that.data.active == 2) {
  176. planned = 3
  177. } else if (that.data.active == 3) {
  178. planned = 4
  179. }
  180. let url = 'work_order/list?planned=' + planned + '&&put_area_id=' + that.data.areaID + '&&page=' + page
  181. app.request(url, '', 'GET').then(res => {
  182. console.log(res)
  183. wx.hideLoading()
  184. if (res.data.data.length > 0) {
  185. that.setData({
  186. workList: that.data.workList.concat(res.data.data),
  187. page
  188. })
  189. } else {
  190. wx.showToast({
  191. title: '没有更多了~',
  192. icon: 'none'
  193. })
  194. }
  195. })
  196. },
  197. onShareAppMessage: function () {
  198. return {
  199. title: '轻松出行,方便你我',
  200. path: '/pages/login/login',
  201. success: function (res) {}
  202. }
  203. }
  204. })