123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <template>
- <view class="news-index">
- <nav-bar title="新闻" @init="onInitNavbar"></nav-bar>
- <u-scroll-view :tabbar-conflict="false" @scroll-near-lower="onScrollToLower">
- <view class="main-container">
- <u-tabs :active.sync="tabActive" :tabs="tabs" tab-style="default" @change="tabChange"/>
- <van-empty v-if="newsList.length === 0" description="暂无数据" />
- <view v-else class="news-list">
- <template v-for="(item, index) in newsList">
- <news-item :item="item" :key="index" :type="tabActive" />
- </template>
- </view>
- <disclaimer-text></disclaimer-text>
- </view>
- </u-scroll-view>
- </view>
- </template>
- <script>
- import NavBar from '@/components/layout/nav-bar'
- import UTabs from '@/components/common/u-tabs'
- import UScrollView from '@/components/common/u-scroll-view'
- import NewsItem from '@/pages/news/components/news-item.vue'
- import { exhibitorsNewsList, newsList } from '@/api/exhibitor'
- import DisclaimerText from '@/components/disclaimer-text/index.vue'
- export default {
- options: {
- styleIsolation: 'shared'
- },
- components: {
- NavBar,
- UTabs,
- UScrollView,
- NewsItem,
- DisclaimerText
- },
- data() {
- return {
- tabActive: 'exhibition',
- tabs: [{
- label: '展会新闻',
- value: 'exhibition'
- }, {
- label: '展商新闻',
- value: 'exhibitor'
- }],
- newsList: [],
- newsParams: {
- page: 1,
- page_size: 10,
- keyword: '',
- },
- newsListLoading: false,
- newsListLastPage: 1,
- }
- },
- onLoad(options) {
- if (options.type) {
- this.tabActive = options.type
- }
- },
- mounted() {
- this.getNewsList()
- },
- methods: {
- getList() {
- if (this.tabActive === 'exhibitor') {
- this.getExhibitorsNewsList()
- }
- if (this.tabActive === 'exhibition') {
- this.getNewsList()
- }
- },
- getNewsList() {
- this.newsListLoading = true
- newsList(this.newsParams).then(res => {
- if (res.data.data) {
- if (this.newsParams.page > 1) {
- this.newsList = [...this.newsList, ...res.data.data]
- } else {
- this.newsList = res.data.data
- this.newsListLastPage = res.data.last_page
- }
- } else {
- this.showToast('系统繁忙,稍候再试')
- }
- this.newsListLoading = false
- })
- },
- getExhibitorsNewsList() {
- this.newsListLoading = true
- exhibitorsNewsList(this.newsParams).then(res => {
- if (res.data.data) {
- if (this.newsParams.page > 1) {
- this.newsList = [...this.newsList, ...res.data.data]
- } else {
- this.newsList = res.data.data
- this.newsListLastPage = res.data.last_page
- }
- } else {
- this.showToast('系统繁忙,稍候再试')
- }
- this.newsListLoading = false
- })
- },
- onScrollToLower(e) {
- if (this.newsListLastPage === this.newsParams.page) {
- return
- }
- if (this.newsListLoading === true) {
- return
- }
- this.newsListLoading = true
- this.newsParams.page = this.newsParams.page+1
- this.getList()
- },
- tabChange(e) {
- this.tabActive = e.detail.value
- this.newsParams.page = 1
- this.getList()
- }
- }
- }
- </script>
- <style lang="scss">
- .news-list{
- display: grid;
- grid-template-columns: 1fr;
- grid-row-gap: 18rpx;
- margin-top: 28rpx;
- }
- </style>
|