<template>
	<view class="signUp">
		<template v-if="info.activityType != 1">
			<image class="good-img" :src="info.activityMain" mode="aspectFit"></image>
			<view class="goods-info">
				<view class="goods-name">
					{{info.activityName}}
				</view>
				<view class="price-box" v-if="info.activityEnable == 1">
					<view class="left">
						<view class="unit">
							￥
						</view>
						<view class="price">
							{{info.price}}
						</view>
					</view>
					
				</view>
			</view>
			
			<view class="list">
				<view class="item">
					<view class="label">
						活动时间
					</view>
					<view class="value">
						{{info.activityStartTime}} 至 {{info.activityEndTime}}
					</view>
				</view>
				<view class="item" v-if="info.activityEnable == 1">
					<view class="label">
						报名时间
					</view>
					<view class="value">
						{{info.signupStartTime}} 至 {{info.signupEndTime}}
					</view>
				</view>
				<view class="item" v-if="info.address">
					<view class="label">
						活动地址
					</view>
					<view class="value">
						{{info.address}}
					</view>
				</view>
			</view>
			
			<view class="sub-title">
				活动详情
			</view>
		</template>
		
		<view class="desc-box">
			<rich-text class="goods-desc" :nodes="info.activityDetail"></rich-text>
		</view>
		
		
		<view class="buy-box"  v-if="info.activityEnable == 1&&!isEnd">
			<button class="buy-btn" type="default" @click="handleSignUp">报名</button>
		</view>
		
	</view>
</template>

<script>
	import {getActivityDetail} from '@/api/activity.js'
	import {
		getShareInfo
	} from '@/api/common.js'
	export default {
		data() {
			return {
				shareInfo:{
					shareDescribe:'慧研学惠生活',
					shareImg:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/XHBjBiMRhVYG8f1a30bbbd80c2346197b81470444c9a.png/1.png',
					shareTitle:'慧研学惠生活',
				},
				id:0,
				info: {},
				isEnd:false
			}
		},
		methods: {
			handleSignUp(){
				let that = this
				let {activityStartTime,activityEndTime,limited,activityName,id,price,shopId} = this.info
				let obj = {
					activityStartTime,
					activityEndTime,
					limited,
					activityName,
					id,
					price,
					shopId
				}
				
				if (uni.getStorageSync('token')) {
					if(JSON.parse(uni.getStorageSync('userInfo')).setMealCode != 0&&JSON.parse(uni.getStorageSync('userInfo')).setMealCode){
						uni.setStorageSync('activity',JSON.stringify(obj) )
						uni.navigateTo({
							url:'/signUp/makeOut?id='+this.info.dataCollectId
						})
					}else{
						uni.showModal({
							title:'此商品需要开通会员才能购买',
							cancelText:'下次再说',
							confirmText:'立即开通',
							success(res) {
								if(res.confirm){
									uni.navigateTo({
										url:'/my/memberCenter/index'
									})
								}
							}
						})
					}
					
				} else {
					uni.showModal({
						title:'请登录',
						confirmText:'去登录',
						success(res){
							console.log(res);
							if(res.confirm){
								uni.navigateTo({
									url:`/login/login/login?redirect=/signUp/index&scene=${that.id}`
								})
							}
						}
					})
				}
			},
			getActivityDetail(id){
				getActivityDetail({id}).then(res=>{
					if (res.state == 'Success') {
						this.info = res.content
						this.info.activityDetail = res.content.activityDetail.replace(/<img/gi, '<img class="img_class" ')
						uni.setNavigationBarTitle({
							title:this.info.activityName
						})
						if(new Date(this.info.activityEndTime).getTime()< new Date().getTime() ){//活动结束
							this.isEnd = true
						}
					}
				})
			},
			getShareInfo(){
				getShareInfo({id:1}).then(res=>{
					if(res.state == 'Success'){
						this.shareInfo = {
							shareDescribe:res.content.shareDescribe,
							shareImg:res.content.shareImg,
							shareTitle:res.content.shareTitle,
						}
					}
				})
			}
		},
		onLoad(options) {
			this.getShareInfo()
			this.id = decodeURIComponent(options.scene)
			this.getActivityDetail(this.id)
		},
		onShareTimeline() {
		  // return {
		  //   title: "慧研学惠生活-"+this.info.activityName,
		  //   query: "scene="+this.id,
		  // };
		  return {
		    title: this.shareInfo.shareDescribe,
		    query: "id=1",
		    imageUrl: this.shareInfo.shareImg,
		  };
		},
		onShareAppMessage() {
		  // return {
		  //   title: "慧研学惠生活-"+this.info.activityName,
		  //   path: "/signUp/index?scene="+this.id,
		  // };
		  return {
		    title: this.shareInfo.shareDescribe,
		    path: "/signUp/index?scene="+this.id,
		  	imageUrl: this.shareInfo.shareImg,
		  };
		},
		
	}
</script>

<style lang="scss" >
.signUp{
	background: #F9F9F9;
	padding-bottom: 200rpx;
	min-height: 100vh;
	.good-img{
		width: 100%;
		height: 750rpx;
		vertical-align: bottom;
	}
	.goods-info{
		padding: 24rpx;
		margin-bottom: 20rpx;
		background: #fff;
		.price-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 20rpx;
			.left{
				display: flex;
				align-items: flex-end;
				.unit{
					font-size: 20rpx;
					color: $uni-color-primary;
					font-weight: bold;
				}
				.price{
					font-size: 36rpx;
					color: $uni-color-primary;
					font-weight: bold;
				}
				
			}
			
		}
		.goods-name{
			font-size: 32rpx;
			color: #222222;
			font-weight: bold;
		}
		
	}
	
	.sub-title{
		font-weight: 600;
		font-size: 28rpx;
		color: #222222;
		padding: 24rpx;
		border-radius: 16rpx 16rpx 0 0;
		background: #fff;
	}
	.desc-box{
		.goods-desc{
			color: #222222;
			font-size: 24rpx;
			.img_class{
				max-width: 100%!important;
				vertical-align: bottom;
			}
		}
	}
	
	.list{
		background: #fff;
		margin-bottom: 20rpx;
		.item{
			padding: 24rpx;
			border-top:1rpx solid #F0F0F0;
			.label{
				font-weight: 600;
				font-size: 28rpx;
				color: #222222;
			}
			.value{
				font-weight: 300;
				font-size: 24rpx;
				color: #AAAAAA;
				margin-top: 16rpx;
				line-height: 40rpx;
			}
		}
	}
	
	.buy-box{
		position: fixed;
		bottom: 0%;
		left: 0%;
		width: 100%;
		background: #fff;
		padding: 10rpx 24rpx env(safe-area-inset-bottom);
		border-top: 1rpx solid #EEEEEE;
		box-sizing: border-box;
		.buy-btn{
			width: 702rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: $uni-color-primary;
			border-radius: 40rpx;
			font-weight: 600;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	
		
	}
	
}
</style>