classification.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="class-main">
  3. <network-error />
  4. <u-sticky
  5. :enable="enable"
  6. offset-top="0"
  7. h5-nav-height="0"
  8. @fixed="stickyFixed"
  9. @unfixed="unStickyFixed"
  10. >
  11. <view class="class-tabs">
  12. <u-tabs
  13. is-scroll
  14. :list="list"
  15. name="category_name"
  16. :current="currentTab"
  17. height="72"
  18. font-size="28"
  19. active-color="#111111"
  20. inactive-color="#111111"
  21. :gutter="32"
  22. :bar-style="{
  23. bottom: '16rpx',
  24. marginLeft: '-8rpx',
  25. width: '56rpx',
  26. height: '10rpx',
  27. borderRadius: 0,
  28. backgroundColor: '#FD5B36',
  29. boxShadow: '0px 1px 1px 0px rgba(255, 102, 50, 0.3)'
  30. }"
  31. @change="changeTab"
  32. >
  33. </u-tabs>
  34. </view>
  35. </u-sticky>
  36. <block v-if="isLocation">
  37. <view class="activity-list" :style="{marginTop: `${activityListMT}rpx`}">
  38. <block v-if="activityList.length !== 0">
  39. <view class="activity-card u-border-bottom" v-for="(item, index) in activityList" :key="index">
  40. <activity-card
  41. :value="item"
  42. @sign-up="toActivityDetail"
  43. @click-ybm="toActivityDetail"
  44. @click-yqg="toActivityDetail"
  45. >
  46. </activity-card>
  47. </view>
  48. <view class="touch-bottom u-font-22 line-32 u-text-center">{{isLoadMore ? '加载中...' : '到底了~'}}</view>
  49. </block>
  50. <block v-else>
  51. <view class="no-location def-content">
  52. <def-content type="1"></def-content>
  53. </view>
  54. </block>
  55. </view>
  56. </block>
  57. <block v-else>
  58. <view class="def-content">
  59. <def-content type="2"></def-content>
  60. </view>
  61. </block>
  62. </view>
  63. </template>
  64. <script>
  65. import defContent from '@/components/defContent'
  66. import activityCard from '@/components/activityCard'
  67. import { getActivityCategoryList, getActivityList } from '@/api/activityApi.js'
  68. export default {
  69. components: { defContent, activityCard },
  70. data () {
  71. return {
  72. isLocation: false,
  73. enable: true,
  74. currentTab: 0,
  75. activityListMT: 16,
  76. list: [],
  77. isLoadMore: false,
  78. searchForm: {
  79. page_no: 1,
  80. page_size: 10,
  81. category_id: 0
  82. },
  83. activityList: [],
  84. total: -1
  85. }
  86. },
  87. computed: {
  88. cateId () {
  89. return this.$store.state.cateId
  90. }
  91. },
  92. async onShow () {
  93. await this.getCategoryData()
  94. if (this.cateId) {
  95. this.currentTab = this.list.findIndex(item => {
  96. return item.id === this.cateId * 1
  97. })
  98. } else {
  99. this.currentTab = 0
  100. }
  101. this.searchForm.page_no = 1
  102. this.total = -1
  103. this.activityList = []
  104. this.getActivityData()
  105. this.enable = true
  106. this.$store.commit('changeCateId', '')
  107. },
  108. onHide () {
  109. this.enable = true
  110. },
  111. onPullDownRefresh () {
  112. this.searchForm.page_no = 1
  113. this.total = -1
  114. this.activityList = []
  115. this.getActivityData()
  116. },
  117. onReachBottom () {
  118. if (this.isLoadMore) {
  119. this.searchForm.page_no += 1
  120. this.getActivityData()
  121. }
  122. },
  123. methods: {
  124. // 获取用户经纬度
  125. getLocation () {
  126. return new Promise((resolve, reject) => {
  127. uni.getLocation({
  128. type: 'gcj02',
  129. success: (res) => {
  130. this.isLocation = true
  131. resolve(res)
  132. },
  133. fail: () => {
  134. this.isLocation = false
  135. resolve(false)
  136. }
  137. })
  138. })
  139. },
  140. // 获取分类标签
  141. async getCategoryData () {
  142. const { code, data } = await getActivityCategoryList()
  143. if (code === 200) {
  144. this.list = data
  145. }
  146. },
  147. // 获取活动列表
  148. async getActivityData () {
  149. const location = await this.getLocation()
  150. if (!location) { return }
  151. const params = {
  152. lng: location.longitude,
  153. lat: location.latitude,
  154. page_no: this.searchForm.page_no,
  155. page_size: this.searchForm.page_size,
  156. category_id: this.searchForm.category_id
  157. }
  158. const { code, data } = await getActivityList(params)
  159. if (code === 200) {
  160. this.total = data.total_count
  161. this.activityList = this.activityList.concat(data.rows)
  162. this.isLoadMore = this.total !== this.activityList.length
  163. }
  164. },
  165. changeTab (index) {
  166. this.currentTab = index
  167. this.searchForm.category_id = this.list[index].id
  168. this.searchForm.page_no = 1
  169. this.total = -1
  170. this.activityList = []
  171. this.getActivityData()
  172. },
  173. toActivityDetail (e) {
  174. uni.navigateTo({
  175. url: `/pagesSub/activity/activityDetail?id=${e.id}`
  176. })
  177. },
  178. stickyFixed () {
  179. this.activityListMT = 64
  180. },
  181. unStickyFixed () {
  182. this.activityListMT = 16
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .class-main {
  189. .class-tabs {
  190. width: 100%;
  191. padding: 0;
  192. background-color: #fff;
  193. }
  194. .no-location, .activity-list {
  195. padding: 0 28px;
  196. min-height: 100vh;
  197. background-color: #fff;
  198. .activity-card {
  199. padding: 32px 0;
  200. }
  201. .touch-bottom {
  202. padding: 30px 0;
  203. color: #BABBBC;
  204. }
  205. }
  206. .back-color {
  207. height: 16px;
  208. background-color: #fff;
  209. }
  210. .def-content {
  211. padding-top: 252px;
  212. }
  213. }
  214. </style>
  215. <style >
  216. .class-tabs >>> .u-tab-item {
  217. z-index: 10;
  218. }
  219. </style>