<template>
	<!-- 教研室详情 -->
	<view class="activeDetail">
		<statusBar :item="navbar"></statusBar>

		<!-- 顶部 -->
		<view class="backPic">
			<image src="https://teacherapi.cocorobo.cn/teaching-file/static//yym/Rectangle 40.png" mode="aspectFill">
			</image>
			<view class="card">
				<view class="cardTop">
					<view class="title three-font">{{ actItemList.acName }}</view>
					<view class="icons">
						<view class="icon" @click="coll">
							<image :src="collArr.includes(actItemList.acId) ? pic_coll2 : pic_coll "
								style="width: 42rpx;height: 42rpx;" mode="aspectFill"></image>
						</view>
						<view class="icon" @click="sub">
							<image
								:src="subArr.includes(actItemList.acId) ? pic_sub2 : pic_sub "
								style="width: 38rpx;height: 42rpx;" mode="aspectFill"></image>
						</view>
					</view>
				</view>
				<view class="col fz-font">
					活动日期：<text class="col2"> {{ actItemList.begin_at}}</text> 
				</view>
				<view class="col fz-font">
					招募人数：<text class="col2"> {{actItemList.bnum}}/{{ actItemList.pers}}</text> 
				</view>
				<view class="col fz-font tag">
					<view class=" tag">活动地址：</view>
					<text class="col2">{{actItemList.address}}</text>
				</view>
			</view>
		</view>


		<!-- 创建者用户名 -->
		<view style="padding:30rpx;padding-top: 30rpx;">
			<view class="creator">
				<image
					:src="actItemList.avatar"
					mode="aspectFill"></image>
				<view class="creName btn-font">
					{{ actItemList.username }}
				</view>
			</view>
		</view>



		<!-- 教研室详情 -->
		<view class="" style="padding: 0 30rpx;">
			<!-- <detailBlock :actItemList='actItemList' :item="judge"></detailBlock> -->
			<view class="detailBlock">
				<view class="tit fwb-font">活动详情</view>
				<view class="cont sZw-font">
					活动时间：<text>{{ actItemList.begin_at }}</text>
				</view>
				<view class="cont sZw-font">
					活动形式：<text style="color: #0056a8;">{{ actItemList.acshape }}</text>
				</view>
				<view class="cont sZw-font">
					<!-- <view id="myElement" class="activeTit">
						教研室概况：查看更多查看更多查看更多看更多查看更多查看更多查看更多查看更多查看更多查看更多查看更多看更多查看更多查看更多查看更多查看更多
				   </view>
					<text class="zdwz" style="color: #0056a8;float: right;" @click="zdwz">收起</text> -->
					<view class="content">
						<view ref="p" :class="getClassNames">
							<text style="color: #999999;">教研室概况：</text>
							{{actItemList.brief}}
						</view>
			
						<view ref="btnnn" :class="getClassNames1" @click="qqq">
							<!-- {{isAll ? '收起' : '展开'}} -->
						</view>
					</view>
				</view>
			</view>
		</view>


		<!-- 当前成员 -->
		<!-- {{!applyUserlist.length}} -->
		<view style="padding: 0 30rpx;" v-if="applyUserlist.length">
			<view class="member">
				<view class="memberTop">
					<view class="btn-font">当前成员</view>
					<view class="fz-font" style="color: rgba(0, 0, 0, 0.4);display: flex;align-items: center;"
						@click="gotoMorePer">
						<text>查看更多</text>
						<image src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"
							style="width: 32rpx;height: 32rpx;" mode="aspectFill"></image>
					</view>
				</view>

				<view class="pers" >
					<view class="per"  v-for="(i,index) in applyUserlist" :key="index">
						<image :src="i.avatar" mode=""></image>
						<view class="perName fz-font">
							{{i.username}}
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 申请加入 -->
		<view class="btnBlock">
				<button class="btn btn1 zw-font" v-if="actItemList.openid==oid">本人创建，暂不支持加入</button>
				<button class="btn zw-font" v-if="!isSign && actItemList.openid!=oid" @click="applyAdd">申请加入</button>
				<button class="btn btn1 zw-font" v-if="isSign && actItemList.openid!=oid">已加入</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navbar: {
					title: '活动详情',
					btn: 1
				},
				// 是否已加入
				isSign:0,
				// 用户openid
				oid:'',
				// 活动id
				acId:'',
				// 页面数据
				actItemList: {},
				// 用户收藏列表
				collArr:[],
				// 用户订阅列表
				subArr:[],
				
				// 报名列表
				applyUserlist:[],
			
				
				
				pic_coll: 'https://teacherapi.cocorobo.cn/teaching-file/static/yym/Star 1 (Stroke).png',
				pic_coll2: 'https://teacherapi.cocorobo.cn/teaching-file/static//mine/Collect_yellow.png',
				pic_sub: 'https://teacherapi.cocorobo.cn/teaching-file/static/yym/Vector (Stroke).png',
				pic_sub2: '../../static/mine/dingyue_blue.png'
				
				
				// pic_coll:'https://teacherapi.cocorobo.cn/teaching-file/static//yym/Star 1 (Stroke) (2).png',
				// pic_coll2:'https://teacherapi.cocorobo.cn/teaching-file/static//mine/Collect_yellow.png',
				// pic_sub:'https://teacherapi.cocorobo.cn/teaching-file/static/yym/Vector (Stroke) (1).png',
				// pic_sub2:'https://teacherapi.cocorobo.cn/teaching-file/static/dingyue_blue.png',
			};
		},
		methods: {
			// 获取页面数据
			getdata(){
				let data = {
					oid:this.$store.state.user.openid,
					acId: this.acId,
				}
				this.$request('/selectActivityID', "POST", data).then(res => {
					console.log('获取页面数据',res[0][0]);
					this.actItemList = res[0][0]
				})
				
			},
			addview(){
				let data={
					oid:this.$store.state.user.openid,
					acId: this.acId,
				}
				this.$request('/updateView', "POST", data).then(res => {
					console.log(res[0][0]);
					this.actItemList = res[0][0]
				})
			},
			// 收藏事件
			coll(){
				//判断是否收藏
				let iscoll = null
				
				// 查询是否收藏过
				let data = {
					acid: this.acId,
					oid: this.$store.state.user.openid, //用户id
					ty: 0
				}
				this.$request('/selectOneOperator', 'POST', data).then(res => {
					// console.log('查询是否收藏过',res);
					res[0].length ? iscoll = true : iscoll = false;
				
					// iscoll为true表示已经收藏过，执行删除  为true则收藏
					if (iscoll) {
						console.log('执行删除');
						this.$request('/deleteOperator', 'POST', data).then(res => {
							// console.log(res);
							this.getColl()
						})
					} else {
						console.log('执行添加');
						this.$request('/insertOperator', 'POST', data).then(res => {
							// console.log(res);
							this.getColl()
						})
					}
				})
			},
			// 订阅事件
			sub(){
				//判断是否订阅
				let iscoll = null
				
				// 查询是否订阅过
				let data = {
					acid: this.acId,
					oid: this.$store.state.user.openid, //用户id
					ty: 1
				}
				this.$request('/selectOneOperator', 'POST', data).then(res => {
					// console.log('查询是否订阅过',res);
					res[0].length ? iscoll = true : iscoll = false;
					
					// iscoll为true表示已经订阅过，执行删除  为true则订阅
					if (iscoll) {
						console.log('执行删除');
						this.$request('/deleteOperator', 'POST', data).then(res => {
							console.log(res);
							this.getSub()
						})
					} else {
						console.log('执行添加');
						this.$request('/insertOperator', 'POST', data).then(res => {
							console.log(res);
							this.getSub()
							// 添加消息页面订阅通知提示订阅成功
							this.addMessage()
						})
					}
				})
			},
			// 添加消息页面订阅通知提示订阅成功
			addMessage() {
				let data = {
					oid: this.$store.state.user.openid,
					acid: this.acId,
					type: 2,
					con: ``
				}
				this.$request('/insertMessage', "POST", data).then(res => {
					console.log(res);
				})
			},
			// 申请加入
			applyAdd() {
				
				uni.navigateTo({
					url: `/pages/jys/jys?acId=${this.acId}&tit=${'活动报名'}`
				})
			},
			// 查看更多报名同学
			gotoMorePer() {
				uni.navigateTo({
					url: `/pages/dy/dy?acId=${this.acId}`
				})
			},
			// 获取是否订阅
			getSub(){
				let data = {
					oid: this.$store.state.user.openid, //用户id
					type: 1
				}
				this.$request('/selectOperator', 'POST', data).then(res => {
					// console.log('获取', res);
					// 每次调用前清零，防止push叠加错误
					this.subArr = []
					// 将acid遍历到subArrsubArr中
					res[0].forEach(i => {
						this.subArr.push(i.acId)
					})
				
				})
				
			},
			//获取是否收藏
			getColl() {
				let data = {
					oid: this.$store.state.user.openid, //用户id
					type: 0
				}
				this.$request('/selectOperator', 'POST', data).then(res => {
					// console.log('获取收藏', res);
					// 每次调用前清零，防止push叠加错误
					this.collArr = []
					// 将acid遍历到collArr中
					res[0].forEach(i => {
						this.collArr.push(i.acId)
					})
				})
			},
			//判断是否报名
			btnEnroll() {
				let data = {
					oid: this.$store.state.user.openid, //用户id
					aid:this.acId,
					type: 2
				}
				this.$request('/selectSignup', 'POST', data).then(res => {
					// console.log('获取报名', res[0][0]);
					this.isSign=res[0][0].num
				})
			},
			// 获取报名用户
			getUsers(){
				let data = {
					oid: this.$store.state.user.openid, //用户id
					aid:this.acId,
					type: 2,
					page: 1, //下拉获取更多的备用字段
					lim: 6 //一次获取多少数据
				}
				this.$request('/selectApplyUser', 'POST', data).then(res => {
					console.log('获取报名用户列表', res[0]);
					this.applyUserlist=res[0]
				})
			}

		},
		onLoad(e) {
			console.log('接收参数',e);
			this.acId=e.acId
			this.oid=this.$store.state.user.openid
			// this.getActivity()
			// 获取是否已经报名
			this.btnEnroll()
			// 获取页面数据
			this.getdata()
			// 是否收藏
			this.getColl()
			// 是否订阅
			this.getSub()
			// 获取报名人名单
			this.getUsers()
		}
	}
</script>

<style lang="scss">
	.activeDetail {
		padding-bottom: 80px;

		.backPic {
			width: 750rpx;
			position: relative;
			margin-bottom: 30rpx;
			image {
				width: 100%;
				display: block;
			}

			.card {
				position: absolute;
				width: 690rpx;
				bottom: -30rpx;
				left: 50%;
				padding: 30rpx;
				// background-color: rgba(0, 0, 0, 0.26);
				background-color: #ffffff;
				border-radius: 10px;
				transform: translate(-50%, 0);
				// border: 1rpx #667870 solid;
				color: #ffffff;

				// display: flex;
				// flex-direction: column;
				// justify-content: space-between;
				.cardTop {
					display: flex;
					justify-content: space-between;

					.title {
						margin-bottom: 20rpx;
						width: 80%;
						// height: 48rpx;
						color:rgba(0, 0, 0, 0.8);
						font-family: PingFang SC;
						// overflow: hidden;
						// text-overflow: ellipsis;
						// white-space: nowrap;
						
						display: -webkit-box;
						word-break: break-all;
						text-overflow: ellipsis;
						overflow: hidden;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
					}

					.icons {
						flex: 1;
						display: flex;
						// align-items: center;
						justify-content: space-between;

						.icon {
							width: 48rpx;
							height: 48rpx;
							display: flex;
							align-items: center;
							justify-content: center;
						}
					}

				}

				.col {
					margin-bottom: 10rpx;
					// font-weight: 100;
					color:rgba(0, 0, 0, 0.4);
				}
				.col2 {
					color:rgba(0, 0, 0, 0.8);
					// font-weight: bold;
				}
				.tag {
					display: flex;
					align-items: center;
				}
			}

			// background-image: url(https://teacherapi.cocorobo.cn/teaching-file/static//resource/jqr.png);
		}


		.creator {
			display: flex;
			padding: 30rpx;
			background-color: #ffffff;
			align-items: center;
			// margin-top: 20rpx;
			border-radius: 10px;

			image {
				width: 96rpx;
				height: 96rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}

			.creName {
				font-weight: bold;
			}
		}

		.member {
			background-color: #ffffff;
			margin-top: 20rpx;
			padding: 30rpx;
			border-radius: 10px;
			margin-bottom: 30rpx;

			.memberTop {
				display: flex;
				justify-content: space-between;
				margin-bottom: 10px;
			}

			.pers {
				display: flex;
				width: 100%;
				// justify-content: space-between;

				.per {
					display: flex;
					flex-direction: column;
					align-items: center;
					width: 16%;
					image {
						width: 72rpx;
						height: 72rpx;
						border-radius: 50%;
					}

					.perName {
						text-align: center;
						display: -webkit-box;
						word-break: break-all;
						text-overflow: ellipsis;
						overflow: hidden;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
					}
				}

			}

		}

		.btnBlock {
			position: fixed;
			bottom: 0;
			width: 750rpx;
			background-color: #ffffff;
			// padding: 20px 0;
			padding: 2vh 0;

			.btn {
				width: 432rpx;
				height: 88rpx;
				font-weight: 500;
				display: flex;
				justify-content: center;
				align-items: center;
				margin: auto;
				background-color: #0056a8;
				color: #ffffff;
			}
			.btn1 {
				background-color: rgba(139, 190, 255, 1);
			}
		}
		.detailBlock {
			background-color: #ffffff;
			border-radius: 10rpx;
			padding: 30rpx;
		
			.tit {
				font-weight: 600;
				margin-bottom: 10px;
			}
		
			.cont {
				color: #999999;
				margin-bottom: 10px;
		
				text {
					color: #666666;
				}
		
				.content {
					white-space: normal;
					/*隐藏溢出*/
					/*当文本溢出包含元素时显示省略符号来代表被修剪的文本*/
					/*规定段落中的文本不进行换行*/
					letter-spacing: 2rpx;
					display: -webkit-box;
					word-break: break-all;
					text-overflow: ellipsis;
					overflow: hidden;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 4;
				}
		
				.content .p {
					width: 90%;
					color: #666666;
					// max-width: 100%;
					// display:inline-block;
					display: block;
					// float: left;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					// padding-right: 50rpx;
					/*设置文字溢出时显示省略号*/
		
				}
		
				.content .p.is-expanded {
					width: 100%;
					overflow: visible;
					white-space: normal;
					/*文字溢出时不再显示省略号*/
				}
		
				.btn-more {
					float: right;
					display: inline-block;
					// width: 60px;
					transform: translate(0, -100%);
					color: #0056a8;
				}
		
				.btn-more.is-zd {
					transform: none;
					// transform: translate(0,0);
				}
			}
		}
	}
</style>