| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <template>
- <view class="class-main">
- <network-error />
- <u-sticky
- :enable="enable"
- offset-top="0"
- h5-nav-height="0"
- @fixed="stickyFixed"
- @unfixed="unStickyFixed"
- >
- <view class="class-tabs">
- <u-tabs
- is-scroll
- :list="list"
- name="category_name"
- :current="currentTab"
- height="72"
- font-size="28"
- active-color="#111111"
- inactive-color="#111111"
- :gutter="32"
- :bar-style="{
- bottom: '16rpx',
- marginLeft: '-8rpx',
- width: '56rpx',
- height: '10rpx',
- borderRadius: 0,
- backgroundColor: '#FD5B36',
- boxShadow: '0px 1px 1px 0px rgba(255, 102, 50, 0.3)'
- }"
- @change="changeTab"
- >
- </u-tabs>
- </view>
- </u-sticky>
- <block v-if="isLocation">
- <view class="activity-list" :style="{marginTop: `${activityListMT}rpx`}">
- <block v-if="activityList.length !== 0">
- <view class="activity-card u-border-bottom" v-for="(item, index) in activityList" :key="index">
- <activity-card
- :value="item"
- @sign-up="toActivityDetail"
- @click-ybm="toActivityDetail"
- @click-yqg="toActivityDetail"
- >
- </activity-card>
- </view>
- <view class="touch-bottom u-font-22 line-32 u-text-center">{{isLoadMore ? '加载中...' : '到底了~'}}</view>
- </block>
- <block v-else>
- <view class="no-location def-content">
- <def-content type="1"></def-content>
- </view>
- </block>
- </view>
- </block>
- <block v-else>
- <view class="def-content">
- <def-content type="2"></def-content>
- </view>
- </block>
- </view>
- </template>
- <script>
- import defContent from '@/components/defContent'
- import activityCard from '@/components/activityCard'
- import { getActivityCategoryList, getActivityList } from '@/api/activityApi.js'
- export default {
- components: { defContent, activityCard },
- data () {
- return {
- isLocation: false,
- enable: true,
- currentTab: 0,
- activityListMT: 16,
- list: [],
- isLoadMore: false,
- searchForm: {
- page_no: 1,
- page_size: 10,
- category_id: 0
- },
- activityList: [],
- total: -1
- }
- },
- computed: {
- cateId () {
- return this.$store.state.cateId
- }
- },
- async onShow () {
- await this.getCategoryData()
- if (this.cateId) {
- this.currentTab = this.list.findIndex(item => {
- return item.id === this.cateId * 1
- })
- } else {
- this.currentTab = 0
- }
- this.searchForm.page_no = 1
- this.total = -1
- this.activityList = []
- this.getActivityData()
- this.enable = true
- this.$store.commit('changeCateId', '')
- },
- onHide () {
- this.enable = true
- },
- onPullDownRefresh () {
- this.searchForm.page_no = 1
- this.total = -1
- this.activityList = []
- this.getActivityData()
- },
- onReachBottom () {
- if (this.isLoadMore) {
- this.searchForm.page_no += 1
- this.getActivityData()
- }
- },
- methods: {
- // 获取用户经纬度
- getLocation () {
- return new Promise((resolve, reject) => {
- uni.getLocation({
- type: 'gcj02',
- success: (res) => {
- this.isLocation = true
- resolve(res)
- },
- fail: () => {
- this.isLocation = false
- resolve(false)
- }
- })
- })
- },
- // 获取分类标签
- async getCategoryData () {
- const { code, data } = await getActivityCategoryList()
- if (code === 200) {
- this.list = data
- }
- },
- // 获取活动列表
- async getActivityData () {
- const location = await this.getLocation()
- if (!location) { return }
- const params = {
- lng: location.longitude,
- lat: location.latitude,
- page_no: this.searchForm.page_no,
- page_size: this.searchForm.page_size,
- category_id: this.searchForm.category_id
- }
- const { code, data } = await getActivityList(params)
- if (code === 200) {
- this.total = data.total_count
- this.activityList = this.activityList.concat(data.rows)
- this.isLoadMore = this.total !== this.activityList.length
- }
- },
- changeTab (index) {
- this.currentTab = index
- this.searchForm.category_id = this.list[index].id
- this.searchForm.page_no = 1
- this.total = -1
- this.activityList = []
- this.getActivityData()
- },
- toActivityDetail (e) {
- uni.navigateTo({
- url: `/pagesSub/activity/activityDetail?id=${e.id}`
- })
- },
- stickyFixed () {
- this.activityListMT = 64
- },
- unStickyFixed () {
- this.activityListMT = 16
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .class-main {
- .class-tabs {
- width: 100%;
- padding: 0;
- background-color: #fff;
- }
- .no-location, .activity-list {
- padding: 0 28px;
- min-height: 100vh;
- background-color: #fff;
- .activity-card {
- padding: 32px 0;
- }
- .touch-bottom {
- padding: 30px 0;
- color: #BABBBC;
- }
- }
- .back-color {
- height: 16px;
- background-color: #fff;
- }
- .def-content {
- padding-top: 252px;
- }
- }
- </style>
- <style >
- .class-tabs >>> .u-tab-item {
- z-index: 10;
- }
- </style>
|