fault-list.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/fault-list/fault-list.js
  2. const util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. current: 1,
  9. size: 10,
  10. total: 0,
  11. list: [],
  12. type: ''
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad(options) {
  18. let that = this;
  19. util.get({
  20. url: '/api/fault/handling/record/list',
  21. data: {
  22. current: that.data.current,
  23. size: that.data.size
  24. },
  25. success: function (res) {
  26. wx.hideLoading();
  27. if (res.data.code != 200) {
  28. util.toast(res.data.msg);
  29. } else {
  30. that.setData({
  31. total: res.data.data.total,
  32. list: res.data.data.records
  33. });
  34. }
  35. }
  36. });
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady() {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow() {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide() {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload() {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh() {
  62. let that = this;
  63. that.setData({
  64. current: 1,
  65. list: []
  66. });
  67. util.get({
  68. url: '/api/fault/handling/record/list',
  69. data: {
  70. current: that.data.current,
  71. size: that.data.size
  72. },
  73. success: (res) => {
  74. wx.hideLoading();
  75. wx.stopPullDownRefresh();
  76. if (res.data.code != 200) {
  77. util.toast(res.data.msg);
  78. } else {
  79. that.setData({
  80. total: res.data.data.total,
  81. list: res.data.data.records
  82. });
  83. }
  84. }
  85. });
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom() {
  91. let that = this;
  92. let arr = that.data.list;
  93. let page = that.data.current;
  94. if (arr.length >= that.data.total) {
  95. util.toast('没有更多数据了');
  96. return;
  97. }
  98. that.setData({
  99. current: ++page
  100. });
  101. util.get({
  102. url: '/api/fault/handling/record/list',
  103. data: {
  104. current: that.data.current,
  105. size: that.data.size
  106. },
  107. success: (res) => {
  108. wx.hideLoading();
  109. wx.stopPullDownRefresh();
  110. console.info(res);
  111. if (res.data.code != 200) {
  112. util.toast(res.data.msg);
  113. } else {
  114. let list = res.data.data.records;
  115. that.setData({
  116. list: arr.concat(list)
  117. });
  118. }
  119. }
  120. });
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage() {
  126. }
  127. })