clubList.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { mapGetters } from 'vuex'
  2. import { geolocation } from '@/utils/map-utils'
  3. import { drawLogo, debounce } from '@/utils'
  4. export default {
  5. data() {
  6. return {
  7. active: false,
  8. isRequest: false, // 是否发起请求
  9. finished: true, // 列表加载是否完毕(加载完了所有数据)
  10. loadingMore: false, // 是否正在加载
  11. listQuery: {
  12. authUserId: '',
  13. lngAndLat: '',
  14. authParty: '',
  15. provinceId: '',
  16. cityId: '',
  17. townId: '',
  18. pageNum: 1,
  19. pageSize: 12,
  20. },
  21. list: [], // 机构列表
  22. starList: [], // 明星机构列表
  23. total: 0, // 机构数量
  24. }
  25. },
  26. computed: {
  27. ...mapGetters(['authUserId', 'routePrefix']),
  28. },
  29. created() {
  30. const cacheData = this.$getStorage(this.routePrefix, 'club_list_data')
  31. if (cacheData) {
  32. this.initFromCache(cacheData)
  33. this.$removeStorage(this.routePrefix, 'club_list_data')
  34. } else {
  35. this.init()
  36. }
  37. this.fetchStarClubList()
  38. },
  39. beforeDestroy() {
  40. this.$toast.clear()
  41. },
  42. methods: {
  43. // 绘制logo的方法
  44. drawLogo,
  45. // 页面初始化
  46. async init() {
  47. this.listQuery.authUserId = this.authUserId
  48. this.$toast.loading({
  49. message: '正在获取您附近的机构...',
  50. duration: 0,
  51. })
  52. try {
  53. if (process.env.HTTPS === 'true' || true) {
  54. const resLocation = await geolocation()
  55. this.listQuery.lngAndLat = `${resLocation.position.lng},${resLocation.position.lat}`
  56. }
  57. } catch (error) {
  58. // this.$toast('获取定位信息失败')
  59. console.log(error)
  60. } finally {
  61. this.filterClubList()
  62. }
  63. },
  64. // 搜索机构列表
  65. filterClubList() {
  66. this.listQuery.pageNum = 1
  67. this.list = []
  68. this.loadingMore = true
  69. this.isRequest = true
  70. this.fetchClubList()
  71. },
  72. // 获取机构列表
  73. fetchClubList: debounce(async function () {
  74. try {
  75. const res = await this.$http.api.getAuthClubList(this.listQuery)
  76. this.list = [...this.list, ...res.data.list]
  77. this.finished = !res.data.hasNextPage
  78. this.listQuery.pageNum++
  79. this.total = res.data.total
  80. } catch (error) {
  81. console.log('机构获取失败')
  82. } finally {
  83. this.$toast.clear()
  84. this.loadingMore = false
  85. this.isRequest = false
  86. }
  87. }, 500),
  88. // 获取明星机构列表
  89. async fetchStarClubList() {
  90. try {
  91. const res = await this.$http.api.getAuthClubStarList({
  92. authUserId: this.authUserId,
  93. })
  94. this.starList = res.data.slice(0, 2)
  95. } catch (error) {
  96. console.log(error)
  97. }
  98. },
  99. // 查看机构详情
  100. toDetail(item) {
  101. // 缓存数据
  102. this.$setStorage(this.routePrefix, 'club_list_data', this.$data, {
  103. expiredTime: 5 * 60 * 1000,
  104. })
  105. this.$setStorage(this.routePrefix, 'clubInfo', item)
  106. const url = `${this.routePrefix}/approve/club/detail?id=${item.authId}`
  107. this.$router.push(url)
  108. },
  109. // 格式化地址
  110. formatAddress(a1, a2) {
  111. let resutl = ''
  112. if (a1) resutl += a1
  113. if (a2) resutl += a2
  114. return resutl || '暂无'
  115. },
  116. // 格式化距离
  117. formatDistance(value) {
  118. return value > 1 ? value + 'km' : value * 1000 + 'm'
  119. },
  120. },
  121. }