index.js 2.9 KB

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