suggestion.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // pages/index/suggestion/suggestion.js
  2. const app = getApp();
  3. import HTTP from "../../../../requestFn/Api"
  4. Page({
  5. data: {
  6. suggestion_list: [],
  7. status: {
  8. 1: "待受理",
  9. 2: "受理中",
  10. 3: "已完成"
  11. },
  12. page: 1,
  13. garden_id: null,
  14. page_size: 10,
  15. hasMore: true,
  16. },
  17. onLoad() {
  18. const {
  19. garden_id
  20. } = app.globalData;
  21. if (garden_id) {
  22. this.setData({
  23. garden_id
  24. })
  25. }
  26. },
  27. onShow(options) {
  28. this.init();
  29. },
  30. init() {
  31. this.setData({
  32. page: 1,
  33. hasMore: true
  34. })
  35. this.getSuggestion(true)
  36. },
  37. onReachBottom() {
  38. if (!this.data.hasMore) {
  39. wx.showToast({
  40. title: '没有更多数据了',
  41. icon: 'none'
  42. })
  43. return console.log('没有更多数据了');
  44. }
  45. this.getSuggestion();
  46. },
  47. async getSuggestion(flag = false) {
  48. let {
  49. page,
  50. suggestion_list,
  51. garden_id,
  52. page_size
  53. } = this.data;
  54. let res = await HTTP.Suggestion({
  55. garden_id,
  56. page,
  57. page_size
  58. })
  59. this.setData({
  60. suggestion_list: flag ? res.list : [...suggestion_list, ...res.list],
  61. page: ++page,
  62. hasMore: res.list.length === page_size
  63. })
  64. console.log(res);
  65. },
  66. goAddSuggestion() {
  67. wx.navigateTo({
  68. url: './addsuggestion/addsuggestion',
  69. })
  70. },
  71. goDetail(e) {
  72. const {
  73. id
  74. } = e.currentTarget
  75. wx.navigateTo({
  76. url: `./detail/detail?id=${id}`,
  77. })
  78. },
  79. onPullDownRefresh: function () {
  80. app.onRefresh();
  81. this.init();
  82. },
  83. })