classification.vue 5.6 KB

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