index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // pages/device-inner/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. import api from '../../utils/api'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: [],
  11. page: 1,
  12. touchBottom: false,
  13. project_ids: [''],
  14. work_point_ids: [''],
  15. device: '',
  16. device_name_id: '',
  17. spec_id: '',
  18. list: [],
  19. number: '',
  20. stat: null,
  21. device_status: ""
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. },
  28. getList: function () {
  29. var data = this.data
  30. var that = this
  31. http({
  32. url: 'inner-devices/search',
  33. data: {
  34. number: data.number,
  35. project_ids: data.project_ids,
  36. work_point_ids: data.work_point_ids,
  37. device_id: data.device_id,
  38. device_name_id: data.device_name_id,
  39. spec_id: data.spec_id,
  40. page: data.page,
  41. stat: true,
  42. status: this.data.device_status
  43. },
  44. success: function (res) {
  45. if (res.code == 0) {
  46. var list = that.data.list
  47. var touchBottom = that.data.touchBottom
  48. list = list.concat(res.data);
  49. if (res.data.length <= 0) {
  50. touchBottom = true;
  51. }
  52. that.setData({
  53. touchBottom,
  54. list,
  55. isSearch: false,
  56. stat: res.stat
  57. })
  58. }
  59. }
  60. })
  61. },
  62. onChange: function (e) {
  63. var name = e.currentTarget.dataset.name
  64. this.setData({
  65. [name]: e.detail
  66. })
  67. },
  68. filterSelect: function (e) {
  69. let name = e.currentTarget.dataset.status
  70. this.setData({
  71. device_status: name,
  72. touchBottom: false,
  73. list: [],
  74. page: 1
  75. })
  76. this.getList()
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. navigate: function (e) {
  84. // this.saveFilter()
  85. wx.navigateTo({
  86. url: e.currentTarget.dataset.url,
  87. })
  88. },
  89. saveFilter() {
  90. var data = {
  91. project_ids: this.data.project_ids,
  92. work_point_ids: this.data.work_point_ids,
  93. type: this.data.type,
  94. name: this.data.name,
  95. spec: this.data.spec
  96. }
  97. wx.setStorageSync('sg-device-filters', data)
  98. },
  99. /**
  100. * 生命周期函数--监听页面显示
  101. */
  102. onShow: function () {
  103. var data = wx.getStorageSync('sg-device-filters')
  104. this.setData(data)
  105. this.search()
  106. },
  107. search: function () {
  108. this.setData({
  109. touchBottom: false,
  110. list: [],
  111. page: 1
  112. })
  113. this.getList()
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. // this.saveSearchOption()
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload: function () {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh: function () {
  130. },
  131. /**
  132. * 页面上拉触底事件的处理函数
  133. */
  134. onReachBottom: function () {
  135. if (!this.data.touchBottom) {
  136. this.setData({
  137. page: this.data.page + 1
  138. })
  139. this.getList()
  140. } else {
  141. util.error('没有更多数据了')
  142. }
  143. },
  144. /**
  145. * 用户点击右上角分享
  146. */
  147. onShareAppMessage: function () {
  148. }
  149. })