<template>
	<view style="background-color: #F1F2F8;letter-spacing: 1rpx;min-height: 100vh;">
		<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="true" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view style="padding-left: 15rpx;" @click="goBack()">
					<text class="tn-icon-left" style="font-size: 40rpx;"></text>
				</view>
				<view style="width: 83%;font-weight: bold;">
					<text>活动列表</text>
				</view>
			</view>
		</tn-nav-bar>
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}"
			style="background-color: #FFF;padding-bottom: 30rpx;">
			<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin">
				<view class="justify-content-item align-content-item" style="width: 100%;position: relative;">
					<view class="tn-flex tn-flex-col-center"
						style="border-radius: 100rpx;padding: 20rpx;width: 100%;background-color:#F1F2F8;">
						<text style="color: #BABDC7;"
							class="tn-icon-search justify-content-item tn-padding-right-xs tn-text-lg"></text>
						<input v-model="content" class="justify-content-item" placeholder="请输入活动名称搜索" name="input"
							placeholder-style="color:#BABDC7" style="width: 100%;padding-right: 200rpx;"></input>
					</view>
					<view style="position: absolute;right: 10rpx;top: 10rpx">
						<tn-button backgroundColor="rgba(48,86,211,0.1)" shape="round" padding="20rpx 20rpx"
							width="150rpx" @click="onsubmit()">
							<text style="color:#3056D3;font-weight: bold;">搜 索</text>
						</tn-button>
					</view>
				</view>
			</view>
			<tn-tabs :showBar="false" :list="tabList" :activeItemStyle="{fontSize:'30rpx',fontWeight:'600'}"
				:isScroll="false" :current="current" name="name" @change="tabChange" activeColor="#3056D3"></tn-tabs>
		</view>

		<view style="padding-bottom: 30rpx;">
			<view style="padding: 20rpx">
				<view v-for="(item,index) in actList">
					<view @click="openUrl('/pages/packageB/event/event_info?id='+item.id)"
						style="margin-bottom: 30rpx;background-color: #FFF;border-radius: 20rpx;">
						<view class="tn-flex tn-flex-row-between"
							style="padding:20rpx 20rpx 10rpx 10rpx;position: relative;">
							<view style="margin-left: 10rpx;" v-if="item.activity_image">
								<image :src="apiImgUrl+item.activity_image" mode="aspectFill"
									style="width: 280rpx;height: 180rpx;border-radius: 20rpx;"></image>
							</view>
							<view style="margin-left: 20rpx;width: 54%;">
								<view class="tn-text-ellipsis-2" style="font-size: 32rpx;font-weight: bold;">
									{{ item.activity_name }}
								</view>
								<view style="font-size: 24rpx;margin: 20rpx 0rpx;color: #888888;">
									<text class="tn-icon-time"></text>
									<text>{{formatTime(item.activity_end_time)}}-{{formatTime(item.activity_start_time)}}</text>
								</view>
								<view class="tn-text-ellipsis" style="font-size:26rpx;color: #888888;">
									<text class="tn-icon-location" style="vertical-align: middle;"></text>
									<text style="vertical-align: middle;">{{item.activity_name}}</text>
								</view>
							</view>
							<view style="position: absolute;top: 0rpx;left: 0rpx;">
								<view v-if="item.type=='进行中'" class="my_tag" style="background-color: #13C296">
									进行中
								</view>
								<view v-if="item.type=='未开始'" class="my_tag" style="background: #BABDC7;">
									未开始
								</view>
								<view v-if="item.type=='已结束'" class="my_tag" style="background-color: #FF5159">
									已结束
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="padding-bottom: 120rpx;">
			<tn-load-more class="tn-margin-top" :status="load_status"></tn-load-more>
		</view>
		<!-- <tn-tabbar :outHeight="140" :height="120" v-model="currentIndex" :list="tabbarList" activeColor="#3377FF"
			inactiveColor="#AAAAAA" activeIconColor="#3377FF" inactiveIconColor="#8A8E99" :animation="true"
			:safeAreaInsetBottom="true" @change="switchTabbar"></tn-tabbar> -->
	</view>
</template>

<script>
	import {
		activityIndex,
	} from '@/util/api.js';
	import store from '@/store/index.js'

	export default {
		data() {
			//1.线下活动2.调查问卷3.公益捐赠4.学习培训
			return {
				currentIndex: -1,
				// 底部tabbar菜单数据
				tabbarList: [{
						title: '首页',
						activeIcon: '/static/01_1.png',
						inactiveIcon: '/static/01.png'
					},
					{
						title: '通讯录',
						activeIcon: '/static/02_2.png',
						inactiveIcon: '/static/02.png'
					},
					{
						title: '青企圈',
						activeIcon: '/static/03_3.png',
						inactiveIcon: '/static/03.png'
					},
					{
						title: '个人中心',
						activeIcon: '/static/04_4.png',
						inactiveIcon: '/static/04.png'
					}
				],
				current: 0,
				load_status: 'loading ',
				tabList: [{
					name: '全部',
					id: 0
				}, {
					name: '协会活动',
					id: 1
				}, {
					name: '调查问卷',
					id: 2
				}, {
					name: '公益捐赠',
					id: 3
				}, {
					name: '学习培训',
					id: 4
				}],
				apiImgUrl: this.$store.state.imgUrl,
				content: '',
				topCurrent: 0,
				actList: [],
				page: 1,
			}
		},
		onLoad(d) {
			console.log(d);
			if (typeof(d.type) != 'undefined') {
				this.current = d.type;
			}
			this.getActivityIndex();
		},
		methods: {
			formatTime(time) {
				return time.split(" ")[0];
			},
			switchTabbar(d) {
				console.log(d);
				uni.$emit('depId', {
					index: d
				})
				uni.navigateBack()
			},
			onsubmit() {
				this.page = 1;
				this.actList = [];
				this.getActivityIndex();
			},
			tabChange(d) {
				console.log(d);
				this.current = d;
				this.page = 1;
				this.actList = [];
				this.getActivityIndex();
			},
			ReachBottom() {
				console.log('service');
				this.page = this.page + 1;
				this.getActivityIndex();
				//this.getIndex();
			},
			getNewInfo() {
				this.current = 0;
				this.page = 1;
				this.actList = [];
				this.getActivityIndex();
			},
			getActivityIndex() {
				var type = this.tabList[this.current].id;
				activityIndex({
						association_id: store.state.Gid,
						page: this.page,
						size: 10,
						activity_name: this.content,
						activity_type: type
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							this.actList.push(...res.data.ret);
						} else {
							this.load_status = 'nomore';
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							duration: 2000
						});
					})
			},
			goBack() {
				if (getCurrentPages().length > 1) {
					uni.navigateBack()
				} else {
					uni.redirectTo({
						url: '/pages/index/index'
					})

				}
			},
			openUrl(e) {
				uni.navigateTo({
					url: e
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.curve {
		width: 200px;
		height: 200px;
		background-color: red;
		clip-path: path("M0 0 Q100 200, 200 0");
	}

	.my_tag {
		padding: 8rpx 15rpx;
		font-size: 20rpx;
		color: rgba(255, 255, 255, 1);
		border-radius: 20rpx 0rpx 20rpx 0rpx;
	}
</style>