<template>
	<NavBar />
	<HomeSwiper position="1" />
	<view class="container">
		<view class="title">
			<PageTitle :title="$t('menu.activity')" />
		</view>
		<view class="content">
			<Spin v-show="loading" />
			<view v-if="shop" class="top-shop" >
				<image class="img" mode="aspectFill" :src="shop.img_url" @click="goShop"></image>
				<view class="footer" v-if="shop.doc">
					<uni-link :showUnderLine="false" color="#29BBE4" :fontSize="fs" :href="shop.doc" :text="$t('activity.doc')"></uni-link>
				</view>
			</view>
			<view class="activity-list">
				<template v-for="(item, index) in activityList" >
					<view class="activity-item" >
						<image class="img" mode="aspectFill" :src="item.img_url" ></image>
						<view class="info" >
							<view class="activity-title uni-ellipsis-2">
								<view v-if="item.activity_if_over == 1" class="act-tag-1">{{ $t('activity.activityIfOver1') }}</view>
								<view v-else class="act-tag-0">{{ $t('activity.activityIfOver0') }}</view>
							{{item.title ? item.title : item.activity_name}}
							</view>
							<view class="activity-footer" v-if="item.contentId"  >
								<view @click="goDetail(item)" >									
									<text>{{$t('activity.more')}}</text>
									<image class="icon" src="/static/more.svg"></image>
								</view>
							</view>
						</view>
					</view>
				</template>
			</view>
		</view>
	</view>
</template>

<script>
import { getShopBrief, queryActivityList, queryNewActivityList } from '@/services/activity';
import { UserLanguage } from '@/utils/const.ts';
export default {
	data() {
		return {
			loading: false,
			shop: undefined,
			list1: [],
			list2: [],
			fs: uni.upx2px(24)
		};
	},
	methods: {
		async getListData() {
			this.loading = true
			let res = await getShopBrief()
			this.shop = res.data
			res = await queryActivityList({qcc_language: UserLanguage})
			if (res && res.code === 0) {
				this.list1 = res.data
			}
			res = await queryNewActivityList({qcc_language: UserLanguage})
			if (res && res.code === 0) {
				this.list2 = res.data
			}
			this.loading = false
		},
		goDetail(item) {
			uni.navigateTo({
				url: "/pages/activity/detail?contentId=" + item.contentId + "&contentType=" + item.contentType
			})
		},
		goShop() {
			uni.navigateTo({
				url: "/pages/activity/shop/index"
			})
		}
	},
	created() {
		this.getListData();
	},
	computed: {
		activityList() {
			if(!this.list1 && !this.list2) {
				return []
			}
			if (!this.list1) {
				return this.list2
			}
			if (!this.list2) {
				return this.list1
			}
			return [...this.list1, ...this.list2]
		}
	}
};
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
