index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //获取应用实例
  2. const app = getApp();
  3. var page = 1;
  4. var flag = 0;
  5. var size = 10;
  6. var deviceId = 0;
  7. Page({
  8. data: {
  9. list: [],
  10. },
  11. onLoad: function (option) {
  12. deviceId = option.id;
  13. page = 1;
  14. flag = 0;
  15. this.showData();
  16. },
  17. onShow: function () {
  18. var that = this;
  19. app.ajaxReadyCallback = res => {
  20. var oldlist = that.data.list;
  21. var list = res.data.data;
  22. if (page == 1) {
  23. oldlist = [];
  24. }
  25. var newlist = oldlist.concat(list);
  26. that.setData({
  27. list: newlist
  28. });
  29. if (list.length < size) {
  30. flag = 1;
  31. } else {
  32. page++;
  33. }
  34. };
  35. },
  36. onPullDownRefresh() { //下拉刷新
  37. page = 1;
  38. flag = 0;
  39. this.showData();
  40. },
  41. onReachBottom() { //上拉加载
  42. this.showData();
  43. },
  44. showData: function () {
  45. if (flag == 1) {
  46. return false;
  47. }
  48. var userId = app.globalData.userinfo.userId;
  49. var org = app.globalData.userinfo.org;
  50. app.ajax({
  51. url: app.globalData.serverUrl + 'server/deviceRecord/queryRecordList',
  52. type: 'POST',
  53. data: {
  54. userId: userId,
  55. orgId: org.orgId,
  56. deviceId: deviceId,
  57. page: page,
  58. size: size
  59. }
  60. });
  61. },
  62. recordDetail: function(e){
  63. var id = e.currentTarget.dataset.id;
  64. var did = e.currentTarget.dataset.did;
  65. wx.navigateTo({
  66. url: '../recordDetail/detail?id=' + id + '&did=' + did
  67. })
  68. }
  69. })