<template>
	<view class="">

		<view class="listBlock1" v-for="(i,index) in classList" :key="index" @click="gotoDetail"  :data-aid="i.acId">
			<view class="img cell-img">
				<image :src="i.pic" mode="aspectFill"></image>

				<view class="starView" @click.stop="coll" :data-e="i">
					<image class="star" :src="collArr.includes(i.acId) ? pic_coll2 : pic_coll " mode="aspectFill">
					</image>

				</view>


			</view>

			<view class="right">
				<view class="title">
					<view class="bqZ-font" style="font-size: 20rpx;" :class="i.acshape=='线下活动'?'tag':'tag1'">
						{{i.acshape}}
					</view>

					<view class="titTxt btn-font" style="font-size:34rpx ;">
						{{i.acName}}
					</view>
				</view>

				<view class="introduce">
					<view class="bri">
						<!-- {{ i.brief }} -->
						<!-- {{ i.address }} -->
						深圳职业技术大学
					</view>
					<view class="tim">
						{{ i.create_at }}
					</view>
				</view>


				<view class="operate">
					<view class="left">
						<view class="add fz-font">已报名{{i.bnum}}人</view>
					</view>
					<!-- <view class="Oright" v-if="!indexId" @click.stop="gotoDetail" :data-aid="i.acId"> -->
					<view class="Oright" v-if="!indexId">
						<view class="text">{{ i.signNum?'已报名':'报名' }}</view>
						<view class="arrow">
							<image src="https://teacherapi.cocorobo.cn/teaching-file/static/mine/arrow-right-blue.png"
								mode="aspectFill"></image>
						</view>
					</view>
					<view class="Oright" v-if="indexId">
						<view class="mon">￥<text style="font-size: 40rpx;">{{i.cost}}</text> </view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		name: "listBlock1",
		// computed: {
		//     ...mapState(['msgpop']) // 将 Vuex 中的 items 映射为组件的计算属性
		// },
		props: {
			classList: {
				type: Array,
				default () {
					return [];
				},
			},
			indexId: {
				type: Number,
				default () {
					return 0;
				},
			},
		},
		// props:['classList'],
		data() {
			return {
				// 收藏list
				collArr: [],
				// 节流阀
				stopTimer: 0,

				timer: null,
				// animationDataArr: [],

				// 收藏悬浮窗
				collpopulShow: false,

				// 决定悬浮窗显示哪些内容0 取消 1收藏
				collAoff: 0,
				// subArr: [],
				pic_coll: 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/Vstar21707269669382.png',
				pic_coll2: 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/VStar1707269577778.png',
				// pic_sub: 'https://teacherapi.cocorobo.cn/teaching-file/static/yym/Vector (Stroke).png',
				// pic_sub2: '../../static/mine/dingyue_blue.png'
			};
		},
		onShow() {},


		methods: {
			// 收藏事件
			coll(event) {
				const value = this.$store.state.user.openid;
				if (!value) {
					uni.showToast({
						title: '未登录，请登录',
						icon: 'none'
					})
					setTimeout(this.goLog, 1000)
					return
				}

				if (this.stopTimer) return uni.showToast({
					icon: 'none',
					title: '点击过快'
				})
				this.stopTimer = 1

				setTimeout(() => {
					this.stopTimer = 0
				}, 500)

				let aId = event.currentTarget.dataset.e.acId
				
				// let type= event.currentTarget.dataset.e.type

				//判断是否收藏
				let iscoll = null

				// 查询是否收藏过
				let data = {
					acid: aId,
					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) {
						// this.animationDataArr.push({
						// 	collAoff: 0
						// })
						this.$store.dispatch('asyncUpdatemsg', {
							collAoff: 0
						})
						// this.praiseMe()
						// console.log('执行删除');
						this.$request('/deleteOperator', 'POST', data).then(res => {
							this.getdata()
							setTimeout(() => {
								this.$store.dispatch('asyncDelMsg')
							}, 1500)
						})
					} else {

						// this.animationDataArr.push({
						// 	collAoff: 1
						// })
						// console.log('msgpop',this.$store.state.msgpop);
						this.$store.dispatch('asyncUpdatemsg', {
							collAoff: 1
						})
						// let aaa={collAoff: 1}
						// console.log('执行添加');
						this.$request('/insertOperator', 'POST', data).then(res => {
							this.getdata()
							// console.log(this.h);
							setTimeout(() => {
								this.$store.dispatch('asyncDelMsg')
							}, 1500)
						})
					}
				})
			},

			// 跳转到详情页
			gotoDetail(e) {
				const value = this.$store.state.user.openid;
				if (!value) {
					uni.showToast({
						title: '未登录，请登录',
						icon: 'none'
					})
					setTimeout(this.goLog, 1000)
					return
				}

				let aid = e.currentTarget.dataset.aid;
				uni.navigateTo({
					url: `/pages/activityDetailNew/activityDetailNew?acId=${aid}`
				});
			},

			//跳转到第三方链接
			gotoLink(e) {
				const value = this.$store.state.user.openid;
				if (!value) {
					uni.showToast({
						title: '未登录，请登录',
						icon: 'none'
					})
					setTimeout(this.goLog, 1000)
					return
				}

				let link = e.currentTarget.dataset.link;
				uni.navigateTo({
					url: "/pages/skipone/skipone?url=" + encodeURIComponent(link),
				});
			},

			// 获取收藏事件
			getdata() {
				// console.log(111);
				// this.timer=setInterval(() => {
				// 	if(this.animationDataArr.length>0){
				// 		console.log(this.animationDataArr.length);
				// 		this.animationDataArr.unshift()
				// 	}
				// }, 1500)

				const value = this.$store.state.user.openid;
				if (!value) return this.collArr = []

				// 触发收藏事件
				// console.log('触发收藏事件');
				// this.collArr: [],
				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)
					})
					// console.log('this.collArr',this.collArr);
				})
			},
			goLog() {
				uni.navigateTo({
					url: "/pages/login_Wechat/login_Wechat",
				});
			},
		},

	}
</script>

<style lang="scss" scoped>
	.listBlock1 {
		display: flex;
		justify-content: space-between;
		background-color: #ffffff;
		padding: 20rpx 30rpx;
		width: 750rpx;

		.img {
			width: 160rpx;
			height: 160rpx;
			flex-shrink: 0;
			position: relative;

			.starView {
				width: 40rpx;
				height: 40rpx;

				box-sizing: content-box;
				padding-bottom: 10rpx;
				padding-left: 10rpx;
				position: absolute;
				right: 0rpx;
				top: 0rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.star {
				width: 30rpx;
				height: 30rpx;
			}

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

		.right {
			padding-left: 20rpx;
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				display: flex;
				width: 500rpx;
				justify-content: flex-start;
				align-items: center;

				.titTxt {
					color: rgba(0, 0, 0, 0.8);
					flex: 1;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

			}

			.introduce {
				font-size: 24rpx;
				display: flex;
				justify-content: space-between;

				.bri {
					width: 250rpx;
					color: #a7a7a7;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.tim {
					color: #a7a7a7;
				}
			}

			.operate {
				display: flex;
				justify-content: space-between;

				.left {
					display: flex;
					align-items: baseline;
					position: relative;
					width: 60%;

					.add {
						position: absolute;
						bottom: 0;
						left: 0;
						width: 100%;
						padding-left: 3rpx;
						color: rgba(0, 0, 0, 0.6) !important;
					}
				}

				.Oright {
					// width: 80px;
					display: flex;
					justify-content: flex-end;
					align-items: center;

					.mon {
						color: rgba(246, 135, 23, 1);
						font-weight: 700;
						font-size: 34rpx;
					}

					.text {
						font-size: 24rpx;
						color: #3081E8;
					}

					.arrow {
						display: flex;
						justify-content: center;
						margin-top: 5rpx;

						image {
							width: 32rpx;
							height: 32rpx;
						}
					}
				}


			}
		}

		.tag {
			border: 1px rgba(0, 178, 182, 1) solid;
			flex-shrink: 0;
			letter-spacing: 2rpx;
			// width: 104rpx;
			// height: 36rpx;
			padding: 2rpx 4rpx;
			display: flex;
			white-space: nowrap;
			justify-content: center;
			align-items: center;
			border-radius: 4rpx;
			margin-right: 10rpx;
			color: rgba(0, 178, 182, 1);
			line-height: 32rpx;
		}

		.tag1 {
			flex-shrink: 0;
			letter-spacing: 2rpx;
			// width: 104rpx;
			// height: 36rpx;
			padding: 2rpx 4rpx;
			display: flex;
			white-space: nowrap;
			justify-content: center;
			align-items: center;
			border-radius: 4rpx;
			margin-right: 10rpx;
			line-height: 32rpx;
			border: 1px rgba(0, 86, 168, 1) solid;
			color: rgba(0, 86, 168, 1);
		}
	}
</style>