<template>
	<view>
		<!-- 标签栏 -->
		<view v-if=" id=='1'">
			<u-tabs :list="list" lineWidth="30" lineColor="#F1992D" :activeStyle="{
			            color: '#F1992D',
			            fontWeight: 'bold',
			            transform: 'scale(1.05)'
			        }" :inactiveStyle="{
			            color: '#606266',
			            transform: 'scale(1)'
			        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;" @click="tabChange" :current="current">
			</u-tabs>
		</view>
		
		<view v-if=" id!='1'">
			<u-tabs :list="list1" lineWidth="30" lineColor="#F1992D" :activeStyle="{
			            color: '#F1992D',
			            fontWeight: 'bold',
			            transform: 'scale(1.05)'
			        }" :inactiveStyle="{
			            color: '#606266',
			            transform: 'scale(1)'
			        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;" >
			</u-tabs>
		</view>
		<!-- 校内活动 -->
		<view v-if="current == 0">
			<view v-for="activity in activityList">
				<view class="one-school-activity" @click="goToDetail(activity.activityId)" >
					<text class="school-activity-title">{{activity.title}}</text>
					<image class="school-activity-icon" :src="activity.picture"></image>
				</view>
			</view>
		<view @click="goActivityAdd(teacherId)" class="add-activity" v-if="showButton">
			<u-icon name="edit-pen" color="#F1992D" size="40"></u-icon>
		</view>
		</view>
		<!-- 我的活动 -->
		<view  v-if="current == 1 &&id=='1'"  >
			<view v-for="activity in activityList1">
				<view class="one-school-activity" @click="goToDetail(activity.activityId,1)">
					<text class="school-activity-title">{{activity.title}}</text>
					<image class="school-activity-icon" :src="activity.picture"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				showButton: false, // 初始值为隐藏
				id: '1' ,// 根据id控制显示和隐藏 后期改为判断用户身份
				teacherId: '',
				list: [{
					name: '发现'
				},{
					name: '我的活动',

				}, ],
				list1: [{
					name: '发现'
				}],
				activityList:[],
				activityList1:[],
				title:'趣味篮球赛'
			}
		},
		onPullDownRefresh(){
					//刷新后的效果
					this.onLoad1();
					uni.stopPullDownRefresh();
		},		
		mounted() {
		      // 根据id值进行判断
		      if (this.id == 1) {
		        this.showButton = true;
		      }
		},
		methods: {
			goToDetail(activityId) {
				uni.navigateTo({
				url: '/pages/discover/discover-detail?activityId='+ activityId
			})
		},
		goToDetail(activityId,from) {
				uni.navigateTo({
				url: '/pages/discover/discover-detail?activityId='+ activityId +'&from=' + from
			})
		},
		goActivityAdd(teacherId) {
			uni.navigateTo({
			 	url: '/pages/discover/add-school-activity?teacherId=' + teacherId
			})
		},
		tabChange(index) {
			this.current = index.index;
		},
		getData() {
							uniCloud.callFunction({
					  		name: 'fe-find-activityList',
					  		data: {}
					  	})
					  	.then(res => {
							this.activityList=res.result.data.activityList,
							console.log(res);
					  	});
						
		},
		getData1() {
			uniCloud.callFunction({
				name: 'fe-find-teacher-ActivityList',
				data: {teacherId:this.teacherId}
			})
			.then(res => {
				 this.activityList1=res.result.data.activityList,
				console.log(this.activityList1);
			});
		},
		onLoad1() {
			let type =getApp().globalData.type;
			if(type=="644a64c228064a7587cd79bf") this.id=2;
			else this.id=1;
			if(this.id==1) this.teacherId=getApp().globalData.userId;
			this.getData();
			this.getData1();
		}
		
		
	},
		onLoad() {
			let type =getApp().globalData.type;
			if(type=="644a64c228064a7587cd79bf") this.id=2;
			else this.id=1;
			if(this.id==1) this.teacherId=getApp().globalData.userId;
			this.getData();
			this.getData1();
		},
		onShow() {
			this.onLoad1();
		}
	}
</script>

<style>
	.one-school-activity {
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  width: 90%;
	  background-color: rgb(245 154 35 / 30%);
	  margin: 20px auto;
	  border-radius: 15px;
	  overflow: auto;
	}
	.school-activity-icon {
	  width: 90%;
	  height: 200px;
	  margin-top: 2px;
	  margin-bottom: 10px;
	  border-radius: 15px;
	}

	.school-activity-title {
		display: block;
		text-align: center;
		font-size: 20px;
		font-weight: bold;
	}
	.add-activity {
	    	position: fixed;
	    	right: 20rpx;
	    	bottom: 100rpx;
	    	width: 100rpx;
	    	height: 100rpx;
	    	border-radius: 50%;
	    	background-color: white;
	    	box-shadow: 0 0 20rpx #999;
	    	display: flex;
	    	justify-content: center;
	    	align-items: center;
	}
</style>
