<template>
	<view class="content">
		<statusBar :item="navBarData"></statusBar>

		<!-- <view class="" style="width: 750rpx;height: 60px;">
			<view class="activeTitle">
				<view class="left" @click="phoneLogin" :class="current==0?active:test">
					<text>教研室活动</text>
					<view :class="current==0?yun:test"></view>
				</view>
				<view class="right" @click="accountLogin" :class="current==1?active:test">
					<text class="zw-font">特色活动</text>
					<view :class="current==1?yun:test"></view>
				</view>
			</view>
		</view> -->


		<view class="activeClass">
			<view class="classBox" @click="gotoDetail" :data-all="item" v-for="(item,index) in classList" :key="index">

				<view class="classLeft">
					<!-- <view class="class_Img"> -->
					<image :src="item.pic" mode="aspectFill"></image>
					<!-- </view> -->

					<view class="class_Text">
						<view class="text_Title">
							<text class="manage">类型</text>
							<text class="wenzi">{{ item.acName }}</text>
						</view>
						<view class="text_Intro">
							<text>{{ item.brief }}</text>
						</view>
						
						<view class="classright">
							<image src="https://teacherapi.cocorobo.cn/teaching-file/static/dingyue_blue.png" mode="aspectFill" @click.stop="sub" :data-e="item"></image>
						</view>
					</view>

				</view>

			</view>
		</view>


		<!-- <swiper class="scroll-view-height" @change="swipeIndex" :current="current" :duration="300">
			<swiper-item>
				<scroll-view scroll-y="true" style="height: 80vh;">
					<view class="activeClass">
						<view class="classBox" @click="" v-for="(item,index) in classList" :key="index">

							<view class="classLeft">
								<view class="class_Img">
									<image :src="item.pic" mode="aspectFill"></image>
								</view>
								<view class="class_Text">
									<view class="text_Title">
										<text class="manage">类型</text>
										<text>{{ item.acName }}</text>

									</view>
									<view class="text_Intro">
										<text>{{ item.brief }}</text>
									</view>
								</view>
							</view>
							<view class="classright">
								<image src="https://teacherapi.cocorobo.cn/teaching-file/static/dingyue_blue.png"
									mode="aspectFill" @click="sub" :data-e="item"></image>

							</view>
						</view>
					</view>
				</scroll-view>


			</swiper-item>
			<swiper-item>
				<scroll-view scroll-y="true" style="height: 80vh;">
					<view class="activeClass">
						<view class="classBox" @click="gotoWeb_2(index)" v-for="(item,index) in activeList"
							:key="index">
							<view class="classLeft">
								<view class="class_Img">
									<image :src="activeList[index].img" mode="aspectFill"></image>
								</view>
								<view class="class_Text">
									<view class="text_Title">
										<text class="manage">类型</text>
										<text>{{ item.className }}</text>
									</view>
									<view class="text_Intro">
										<text>{{ item.intro }}</text>
									</view>
								</view>
							</view>
							<view class="classright">
								<image src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/Union.png"
									mode=""></image>
							</view>
						</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navBarData: {
					title: '我的订阅',
					btn: 1
				},
				current: 0, //切换

				aaa: `calc(100vh-60vh)`,

				navheight: this.navheight, //导航栏高度

				active: 'active', //类名
				test: 'test',
				yun: 'yun',
				subArr: [],
				// 渲染列表
				classList: [],
				activeList: [],
			};
		},
		computed: {
			dynamicStyle() {
				return {
					height: `calc(100vh - 10px)`
				};
			}
		},
		methods: {
			getData() {
				console.log(111);
				let data = {
					oid: this.$store.state.user.openid, //用户id
					type: 1
				}
				this.$request('/selectOperator', 'POST', data).then(res => {
					console.log('获取订阅', res);
					this.classList = res[0]
				})
				// let data = {
				// 	oid: this.$store.state.user.openid, //用户id
				// }
				// this.$request('/selectSub', 'POST', data).then(res => {
				// 	this.subArr = JSON.parse(res[0][0].sub)
				// 	// console.log(this.collArr);
				// 	// let a=this.collArr.join(', ');
				// 	// return console.log({a});
				// 	let data = {
				// 		oid: this.$store.state.user.openid, //用户id
				// 		list: this.subArr
				// 	}
				// 	// return console.log(data);
				// 	this.$request('/selectSubList', 'POST', data).then(res => {
				// 		// console.log("要渲染的数据", res);
				// 		// this.collArr=res[0]
				// 		this.classList = res[0]
				// 		// console.log(this.classList);
				// 	})
				// })
			},
			// 这里获取的活动肯定是已订阅的，就不用判断直接删除就可以了
			sub(event) {
				let aId = event.currentTarget.dataset.e.acId
				
				let data = {
					acid: aId,
					oid: this.$store.state.user.openid, //用户id
					ty: 1
				}
				
				this.$request('/deleteOperator', 'POST', data).then(res => {
					console.log(res);
					this.getData()
				})
				// let aId = event.currentTarget.dataset.e.acId
				// // 先获取用户订阅信息
				// let data = {
				// 	oid: this.$store.state.user.openid, //用户id
				// }

				// this.$request('/selectSub', 'POST', data).then(res => {

				// 	let subs = JSON.parse(res[0][0].sub)

				// 	// 把未取消订阅的数据提取出来
				// 	const newArray = subs.filter(item => item !== aId);
				// 	let arr3 = {
				// 		oid: this.$store.state.user.openid, //用户id
				// 		acid: JSON.stringify(newArray)
				// 	}
				// 	this.$request('/updateSub', 'POST', arr3).then(res => {
				// 		// 删除后重新获取数据进行渲染
				// 		this.getData()
				// 		uni.showToast({
				// 			title: '已取消订阅',
				// 			icon: 'error',
				// 			duration: 1000
				// 		})
				// 	})
				// })
			},
			swipeIndex(index) {
				this.current = index.detail.current;
			},
			phoneLogin() {
				this.current = 0
			},
			accountLogin() {
				this.current = 1
			},
			gotoWeb(index) {
				const urls = [
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1181",
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1183",
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1210",
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1234",
				];
				if (index >= 0 && index < urls.length) {
					const url = urls[index];
					uni.navigateTo({
						url: "/pages/skipone/skipone?url=" + encodeURIComponent(url),
					});
				}
			},
			// 跳转详情页
			gotoDetail(e){
				let data=e.currentTarget.dataset.all
				if(data.type<=1){
					uni.navigateTo({
						url: `/pages/activityDetail/activityDetail?acId=${data.acId}`,
					});
				}else{
					uni.navigateTo({
						url: `/pages/teachingDetail/teachingDetail?acId=${data.acId}`
					});
				}
			},
			gotoWeb_2(index) {
				const urls = [
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1183",
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1211",
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1210",
					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1209",
				];
				if (index >= 0 && index < urls.length) {
					const url = urls[index];
					uni.navigateTo({
						url: "/pages/skipone/skipone?url=" + encodeURIComponent(url),
					});
				}
			}
		},
		onShow() {
			this.getData()
		}
	}
</script>

<style lang="scss">
	.content {
		height: 100vh;
		width: 750rpx;
		background-color: #ffffff;

		.activeTitle {
			position: fixed;
			z-index: 9;
			width: 100%;
			height: 60px;
			background-color: white;
			border-top: 1px solid lightgray;
			display: flex;
			justify-content: center;
			padding: 0 30px;
			font-size: 34rpx;

			.test {
				// height: ;
			}

			.active {
				position: relative;
				font-weight: bold;

				.yun {
					width: 80rpx;
					height: 0rpx;
					position: absolute;
					left: 50%;
					top: 65%;
					transform: translate(-50%, -50%);
					box-shadow: 0px 0px 10px 2px #4a97f2;
				}
			}

			.left {
				width: 50%;
				height: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.right {
				width: 50%;
				height: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		.scroll-view-height {
			// height: 200vmin;
			height: 80vh;

			// height: auto;
			.activeClass {
				width: 100%;

				// height: auto;
				.classBox {
					display: flex;
					justify-content: space-between;
					padding: 0 47rpx;
					background-color: #fff;
					height: 144rpx;

					.classLeft {
						display: flex;
						height: 100%;

						.class_Img {
							display: flex;
							align-items: center;
							flex-grow: 1;

							image {
								width: 80rpx;
								height: 80rpx;
								border-radius: 10rpx;
							}
						}

						.class_Text {
							display: flex;
							justify-content: center;
							flex-grow: 2;
							flex-direction: column;
							margin-left: 20rpx;

							.text_Title {
								display: flex;
								margin-bottom: 6px;
								align-items: center;

								text {
									&:last-child {
										width: 220px;
										color: #000;
										font-size: 28rpx;
										font-weight: 600;
										display: -webkit-box;
										word-break: break-all;
										text-overflow: ellipsis;
										overflow: hidden;
										-webkit-box-orient: vertical;
										-webkit-line-clamp: 1;
										/*设置 需要显示的行数*/
									}

									&.manage {
										
										border: 1px #00b2b6 solid;
										font-size: 20rpx;
										width: 64rpx;
										display: flex;
										height: 32rpx;
										white-space: nowrap;
										justify-content: center;
										align-items: center;
										// padding: 4px 12px 4px 12px;
										border-radius: 5rpx;
										margin-right: 10rpx;
										color: #00b2b6;
									}
								}
							}

							.text_Intro {
								display: flex;

								text {
									font-size: 24rpx;
									font-weight: 400;
									color: rgb(191, 191, 191);
									width: 90%;
									letter-spacing: 2rpx;
									display: -webkit-box;
									word-break: break-all;
									text-overflow: ellipsis;
									overflow: hidden;
									-webkit-box-orient: vertical;
									-webkit-line-clamp: 1;
									/*设置 需要显示的行数*/

									// margin-left: 6px;
								}
							}
						}
					}

					.classright {
						display: flex;
						height: 100%;
						align-items: center;

						image {
							width: 38rpx;
							height: 42rpx;
						}
					}
				}
			}
		}
	}

	.activeClass {
		width: 100%;

		.classBox {
			width: 100%;
			display: flex;
			justify-content: space-between;
			background-color: #fff;
			position: relative;
			padding: 40rpx;

			.classLeft {
				display: flex;
				justify-content: space-between;
				height: 100%;
				width: 100%;
				image {
					width: 120rpx;
					height: 120rpx;
					border-radius: 10rpx;
				}

				// }

				.class_Text {
					display: flex;
					justify-content: space-between;
					flex: 1;
					flex-direction: column;
					margin-left: 20rpx;
					position: relative;
					.text_Title {
						display: flex;
						// justify-content: center;
						align-items: center;
						// justify-content: space-between;
						// width: 500rpx;
						.manage {
							border: 1px #00b2b6 solid;
							font-size: 20rpx;
							width: 64rpx;
							display: flex;
							height: 32rpx;
							white-space: nowrap;
							justify-content: center;
							align-items: center;
							border-radius: 5rpx;
							margin-right: 10rpx;
							color: #00b2b6;
						}
						.wenzi {
							// width: 100%;
							line-height: 32rpx;
							flex: 1;
							padding-right: 50rpx;
							color: #000;
							font-size: 28rpx;
							font-weight: 600;
							display: -webkit-box;
							word-break: break-all;
							text-overflow: ellipsis;
							overflow: hidden;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 1;
						}

						

					}
					.text_Intro {
						display: flex;
						width: 100%;
						text {
							font-size: 24rpx;
							font-weight: 400;
							color: rgb(191, 191, 191);
							width: 90%;
							letter-spacing: 2rpx;
							display: -webkit-box;
							word-break: break-all;
							text-overflow: ellipsis;
							overflow: hidden;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 1;
							/*设置 需要显示的行数*/

							// margin-left: 6px;
						}
					}
				}
			}

			.classright {
				height: 100%;
				position: absolute;
				top: 0;
				right: 0;

				image {
					width: 38rpx;
					height: 42rpx;
				}
			}
		}
	}
</style>