<template>
	<view class="activity-item" hover-class="active" @click="onClickActivity(item)">
		<view class="activity-title">
			<view>{{ item.title }}</view>
			<view v-if="!favoritesHidden" @click.stop="onCollect(item)" class="activity-favourites" :class="{ 'active': index === 1 }">
				<view v-if="item.is_collect" class="iconfont icon-favourites-filled-star-symbol active"></view>
				<view v-else class="iconfont icon-Favourites-Add-Large"></view>
				<view class="activity-favourites-text">收藏</view>
			</view>
		</view>
		<view class="activity-time">{{ formatDate(item.start_date || item.start_time || '') }} | {{ item.address }}</view>
		<view class="activity-views">浏览：{{ item.view || item.pv || 0 }}</view>
		<view class="activity-desc">
			<view>
				{{ item.description || item.content || '' }}
			</view>
			<view>
				<van-button class="activity-detail-link" type="primary">
					<template>
						<view>了解详情</view> <view class="arrow iconfont icon-right-s"></view>
					</template>
				</van-button>
			</view>
		</view>
	</view>
</template>

<script>
	import { meetingCollect, meetingCancelCollect, mettingView } from '@/api/exhibitor'


	export default {
		options: {
			styleIsolation: 'shared'
		},
		components: {
		},
		props: {
      type: String,
			// 数据
			item: Object,
			favoritesHidden: Boolean,
			platform: String
		},
		data() {
			return {
				websiteUrl: process.env.WEBSITE
			}
		},
		created() {
		},
		methods: {
			onCollect(item) { // 收藏
				if (!this.checkAuth('pages/activity/index')) {
					return
				}
				if (item.is_collect === 1) {
					meetingCancelCollect({ id: item.id }).then(res => {
						if (res.code === 0) {
							this.$emit('updateItemValue', {
								id: item.id,
								key: 'is_collect',
								value: 0
							})
						}
					})
				} else {
					meetingCollect({ id: item.id }).then(res => {
						if (res.code === 0) {
							this.$emit('updateItemValue', {
								id: item.id,
								key: 'is_collect',
								value: 1
							})
						}
					})
				}
			},
			formatDate(dateString) {
			  const date = new Date(dateString);
			  const year = date.getFullYear();
			  const month = date.getMonth() + 1; // 月份从 0 开始
			  const day = date.getDate();
			  return `${year}年${month}月${day}日`;
			},
      onClickActivity(item){
        this.saveMeetingView(item)
        if (this.type === 'exhibitor') {
          this.webviewTo(this.$store.getters.website_url + '/mini-pro-activity?v=' + this.$store.getters.version)
        } else {
          this.webviewTo(this.$store.getters.website_url + '/mini-pro-same-detail?v=' + this.$store.getters.version)
        }
        // this.navigateTo('/pages/activity/detail')
      },
			saveMeetingView(item) {
				if (this.platform !== 'metting') return
				mettingView({ id: item.id }).then(res => {

				})
			}
		}
	}
</script>
<style lang="scss">
</style>
