index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //index.js
  2. import { getGroupListNew } from '../../api/index'
  3. import { getStorageSync, navigateTo } from '../../utils/util'
  4. Page({
  5. data: {
  6. loading: true,
  7. mLoading: false,
  8. hideCityTip: false,
  9. showData: false,
  10. showNoDataTip: false,
  11. hasMoreData: false,
  12. cityName: '',
  13. listQuery: {
  14. page: 1,
  15. limit: 10,
  16. cityId: ''
  17. },
  18. groupList: []
  19. },
  20. onLoad: function () {
  21. const citySelectObj = getStorageSync('citySelectObj')
  22. const { cityId, cityName } = citySelectObj
  23. this.data.listQuery.cityId = cityId
  24. this.setData({ cityName })
  25. // 城市选择提示
  26. setTimeout(() => {
  27. this.setData({ hideCityTip: true })
  28. }, 4000)
  29. this.getGroups();
  30. },
  31. onShow: function () {
  32. },
  33. onPullDownRefresh: function () {
  34. this.data.listQuery.page = 1
  35. this.getGroups()
  36. },
  37. onReachBottom: function (e) {
  38. if (this.data.hasMoreData) {
  39. this.data.listQuery.page += 1
  40. this.getGroups()
  41. }
  42. },
  43. /**
  44. * 用户点击右上角分享
  45. */
  46. onShareAppMessage: function() {
  47. return {
  48. title: "组织已经准备好,还不快来~",
  49. path: "/pages/index/index"
  50. }
  51. },
  52. refresh: function () {
  53. this.data.listQuery.page = 1
  54. this.getGroups()
  55. },
  56. getGroups: function () {
  57. const listQuery = this.data.listQuery
  58. const groupList = this.data.groupList
  59. getGroupListNew(listQuery).then((result) => {
  60. const data = result.data || {}
  61. this.setData({
  62. loading: false,
  63. showData: true,
  64. mLoading: false,
  65. groupList: listQuery.page > 1 ? groupList.concat(data.list) : data.list || [],
  66. showNoDataTip: listQuery.page > 1,
  67. hasMoreData: data.pages.totalCount > listQuery.page * listQuery.limit
  68. })
  69. }).catch((err) => {
  70. this.setData({
  71. loading: false,
  72. showData: true,
  73. mLoading: false
  74. })
  75. })
  76. },
  77. onCityTap: function () {
  78. navigateTo('/pages/select/select')
  79. },
  80. onSearchTap: function () {
  81. navigateTo('/pages/search/search')
  82. },
  83. onJoin: function (e) {
  84. const { index } = e.detail
  85. const groupList = this.data.groupList
  86. navigateTo(`/pages/detail/detail?id=${groupList[index].id}`)
  87. }
  88. })