index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // pages/repairs/index.js
  2. const util = require('../../utils/util.js');
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. searchParams:{
  10. pageNo:1,
  11. pageSize:10,
  12. },
  13. repairList:[],
  14. loadding: false,
  15. pullUpOn: true,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.bindRepairList()
  22. },
  23. onUnload: function () {
  24. wx.reLaunch({
  25. url: '../operation/index',
  26. })
  27. },
  28. /**
  29. * 页面相关事件处理函数--监听用户下拉动作
  30. */
  31. onPullDownRefresh: function () {
  32. this.setData({
  33. ["searchParams.pageNo"]: 1,
  34. pullUpOn: true,
  35. loadding: false,
  36. repairList: []
  37. })
  38. this.bindRepairList()
  39. setTimeout(() => {
  40. wx.stopPullDownRefresh()
  41. }, 300);
  42. },
  43. /**
  44. * 页面上拉触底事件的处理函数
  45. */
  46. onReachBottom: function () {
  47. var that = this
  48. //只是测试效果,逻辑以实际数据为准
  49. this.setData({
  50. loadding: true,
  51. pullUpOn: true
  52. })
  53. this.setData({
  54. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  55. })
  56. this.bindRepairList()
  57. },
  58. toDetailRepairs(e){
  59. wx.navigateTo({
  60. url: '/pages/repairs/detail?repairsId='+e.currentTarget.dataset.id,
  61. })
  62. },
  63. toAddRepairs(){
  64. wx.navigateTo({
  65. url: 'add',
  66. })
  67. },
  68. bindRepairList(){
  69. var that = this
  70. util.request(util.api.repairsListPage, that.data.searchParams, "GET", false, true,app.globalData.token).then((res)=>{
  71. if (res.code == 200) {
  72. if (res.result.records.length > 0) {
  73. if (that.data.repairList.length > 0) {
  74. let list = that.data.repairList
  75. var records = res.result.records
  76. records.forEach(record => {
  77. list.push(record)
  78. });
  79. that.setData({
  80. repairList: list
  81. })
  82. } else {
  83. that.setData({
  84. repairList: res.result.records
  85. })
  86. }
  87. } else {
  88. that.setData({
  89. loadding: false,
  90. pullUpOn: false,
  91. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  92. })
  93. }
  94. }
  95. }).catch((res) => {})
  96. },
  97. })