warning.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //获取应用实例
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: [],
  9. page: 1,
  10. pageSize: 10,
  11. isLastPage: false,
  12. tips: '上拉加载更多',
  13. windowHeight: app.globalData.windowHeight
  14. },
  15. //获取搜索ID的值
  16. searchID: function (e) {
  17. this.setData({
  18. searchID: e.detail.value
  19. })
  20. },
  21. //点击搜索
  22. searchBtn: function () {
  23. wx.showLoading({
  24. title: '加载中',
  25. })
  26. var that = this;
  27. var searchID = that.data.searchID //获取到用户搜索的ID值
  28. wx.request({
  29. url: 'https://wx.yfzhwlw.com/wechat_equip_search',
  30. header: {
  31. "Content-Type": "application/x-www-form-urlencoded"
  32. },
  33. method: "post",
  34. data: {
  35. equip_id: searchID,
  36. type: '3'
  37. },
  38. success: function (res) {
  39. //判断当前请求到的数据是否为空
  40. if (res.data.dat.length == '0') {
  41. wx.showToast({
  42. title: '暂无该设备,请确定您输入的ID是否有误',
  43. icon: 'none',
  44. duration: 2000
  45. })
  46. } else {
  47. var list = [];
  48. for (var i = 0; i < res.data.dat.length; i++) {
  49. list.push(res.data.dat[i]);
  50. }
  51. that.setData({
  52. list: list
  53. });
  54. if (res.statusCode != 200) {
  55. app.showError()
  56. } else {
  57. wx.hideLoading()
  58. var num = that.data.pageSize //限制数据条数
  59. var nums = res.data.nums
  60. var bb = nums / num
  61. var aa = Math.ceil(bb) //最后得到的页数
  62. if (aa == that.data.page) {
  63. //后端数据条数大于限制数据条数时显示提示
  64. if (res.data.nums >= num) {
  65. that.setData({
  66. newData: '0'
  67. })
  68. }
  69. }
  70. }
  71. }
  72. },
  73. fail: function (res) {
  74. app.showError()
  75. }
  76. });
  77. },
  78. //点击进入测报灯详情
  79. warning: function (e) {
  80. var id = e.currentTarget.dataset.id
  81. var name = e.currentTarget.dataset.name
  82. wx.navigateTo({
  83. url: '../warning_details/warning_details?id=' + id + '&name=' + name,
  84. })
  85. },
  86. /**
  87. * 生命周期函数--监听页面加载
  88. */
  89. onLoad: function (options) {
  90. this.requestVideos(1)
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. this.requestVideos(1)
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function () {
  122. // 最后一页了,取消下拉功能
  123. if (this.data.isLastPage) {
  124. return
  125. }
  126. this.setData({
  127. page: this.data.page + 1
  128. })
  129. this.requestVideos(this.data.activeIndex)
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. },
  136. //请求数据
  137. requestVideos: function () {
  138. wx.showLoading({
  139. title: '加载中',
  140. })
  141. var that = this;
  142. wx.getStorage({
  143. key: 'login',
  144. success(res) {
  145. wx.request({
  146. url: 'https://wx.yfzhwlw.com/wechat_equip_list',
  147. header: {
  148. "Content-Type": "application/x-www-form-urlencoded"
  149. },
  150. method: "post",
  151. data: {
  152. username: res.data,
  153. type: '3',
  154. page: that.data.page
  155. },
  156. success: function (res) {
  157. var list = that.data.list;
  158. for (var i = 0; i < res.data.dat.length; i++) {
  159. list.push(res.data.dat[i]);
  160. }
  161. that.setData({
  162. list: list
  163. });
  164. if (res.statusCode != 200) {
  165. app.showError()
  166. } else {
  167. wx.hideLoading()
  168. var num = that.data.pageSize //限制数据条数
  169. var nums = res.data.nums
  170. var bb = nums / num
  171. var aa = Math.ceil(bb) //最后得到的页数
  172. if (aa == that.data.page) {
  173. //后端数据条数大于限制数据条数时显示提示
  174. if (res.data.nums >= num) {
  175. that.setData({
  176. newData: '0'
  177. })
  178. }
  179. }
  180. }
  181. },
  182. fail: function (res) {
  183. app.showError()
  184. }
  185. });
  186. }
  187. })
  188. },
  189. // 选择menu
  190. selector: function (e) {
  191. var index = e.currentTarget.dataset.index
  192. // 改变当前类,并重置分页数据
  193. this.setData({
  194. activeIndex: index,
  195. page: 1,
  196. isLastPage: false,
  197. tips: '上拉加载更多',
  198. list: []
  199. })
  200. this.requestVideos(index)
  201. },
  202. // 获取滚动条当前位置
  203. onPageScroll: function (e) {
  204. if (e.scrollTop > 100) {
  205. this.setData({
  206. floorstatus: true
  207. });
  208. } else {
  209. this.setData({
  210. floorstatus: false
  211. });
  212. }
  213. },
  214. //回到顶部
  215. goTop: function (e) { // 一键回到顶部
  216. if (wx.pageScrollTo) {
  217. wx.pageScrollTo({
  218. scrollTop: 0
  219. })
  220. } else {
  221. wx.showModal({
  222. title: '提示',
  223. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  224. })
  225. }
  226. },
  227. })