<template>
	<view class="uni-main">
		<view class="sticky-nav">
			<view class="nav-box">
				<u-icon name="arrow-left" color="#000" size="48" @click="navBack()"></u-icon>
				<text class="title">寺院活动</text>
				<u-icon class="right-icon" name="zhuanfa" color="#000" size="48" @click="showMenu()"></u-icon>
			</view>
		</view>  
		<view class="uni-main_box" v-if="info.id">
			<view class="uni-header_title">
				<text v-text="info.title"></text>
			</view>
			<view class="uni-banner">
				<image class="uin-banner_thumb" :src="info.thumb" width="100" height="120"></image>
			</view>
			<view class="uni-info">
				<view class="uni-text uni-info_time">
					时间： <text class="time" v-text="info.publish_at"></text>
				</view>
				<view class="uni-text uni-info_price">
					<view>费用：<text class="price" v-text="info.price>0?'¥'+info.price: '免费'"></text></view>
				</view>
			</view>
			<view class="uni-content">
				<view class="header">
					<text class="info_text">活动详情</text>
				</view>
				<view class="content" v-html="info.content">
				</view>
			</view>
			<view class="uni-buy">
				<view class="uni-buy_btn" @click="showPopup=true">
						<text  v-text="info.type==1? '我要代订': (info.type==2?'我要助印': '我要供奉')"></text>
				</view>
			</view>
		</view>
		<view class="specs-box">
			<view v-show="showPopup" @touchmove.stop.prevent="stopSlide">
				<!-- 遮罩层 -->
				<view class="mask" @click="modalCancel"></view>
				<!-- 内容区 -->
				<view class="tip">
					<view class="main"> 
						<view class="count">
							随喜：<text class="input-box"><input class="tip-input" type="text" placeholder="8-3000" disabled="true"/>券</text>
						</view>
						<view class="options">
							<text :class="'option'+(v.value==selectOptionData.value? ' active' : '')" v-for="(v,k) in quanArr" :key="k" v-text="v.name" @click="selectOption(v)"></text>
						</view>
					</view>
					<view class="bottom">
						<view class="btn cancel" @click="modalCancel()">取消</view>
						<view class="btn confirm" @click="modalConfirm()">确定</view>
					</view>
				</view>
			</view>
				
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPopup: false,
				phone: '12345678',
				autoplay: true,
				adAutoplay: true,
				interval: 2000,
				adInterval: 4000,
				duration: 1000,
				adDuration: 500,
				info: {
					id: 0,
				},
				selectOptionData: {name: '',value: ''},
				quanArr: [
					{name: '8券', value: '8'},
					{name: '28券', value: '28'},
					{name: '58券', value: '58'},
					{name: '68券', value: '68'},
					{name: '168券', value: '168'},
					{name: '268券', value: '268'},
				],
				
			}
		},
		onLoad(option){
			let _uni = this
			let id = option.id
			id = typeof(id) != 'undefined'? id : 0;
			if(id<=0){
				uni.showToast({
					title: '活动参数错误',
					icon: 'none'
				})
				setTimeout(function(){
					uni.navigateBack({
						data: id,
					})
				}, 1200)
				
				return false;
			}
			
			this.getInfo(id)
		},
		methods: {
			navBack(){
				location.href = '/pages/temple/index';
			},
			showMenu(){
				
			},
			modalCancel(){
				this.showPopup = false;
			},
			modalConfirm(){
				if(this.selectOptionData.value <= 0){
					uni.showToast({
						title: '请先选择随喜券数',
						icon: 'none'
					})
					return false;
				}
				
				
				uni.navigateTo({
					url: '/pages/temple/books?id='+this.info.id+'&num='+this.selectOptionData.value,
				})
				
			},
			selectOption(data){
				this.selectOptionData = data
			},
			stopSlide() {
				return;
			},
			getInfo(id) {
				let _uni = this
				uni.showLoading()
				this.$request.api('/api/activity/info', {id: id}).then(res => {
					uni.hideLoading()
					if(res.success == true){
						_uni.info = res.data
					}
				}).catch(err => {
					uni.showToast({
						title: typeof(err.msg) != 'undefined'? err.msg : '服务器错误',
						icon: 'none'
					})
				})
			},
			
		},
	}
</script>

<style lang="less" scoped>
	.uni-main {
		width: 100%;
		height: 100%;
		background-color: #fff;
		font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
	}
	
	.sticky-nav {
		position: sticky;
		width: 100%;
		top: 0;
		z-index: 1;
		border-bottom: 1rpx solid rgb(229,229,229);
	}
	.nav-box {
		width: 100%;
		padding-top: 50rpx;
		display: flex;
		align-items: center;
		background: #fff;
		height: 100rpx;
		padding-bottom: 50rpx;
	    /deep/.u-icon{
			margin-left: 20rpx!important;
		}
		.title {
			font-size: 38rpx;
			color: #000;
			width: 100%;
			text-align: center;
		}
		
		.right-icon {
			float: right;
			margin-right: 20rpx;
		}
	}
	
	.uni-header_title {
		padding: 10rpx 0rpx;
		text-align: center;
		font-size: 36rpx;
	}
	
	.uni-banner .uin-banner_thumb {
		width: 80%;
		height: 300rpx;
		margin: 0 auto;
		display: block;
	}
	
	.uni-info .uni-text {
		font-size: 32rpx;
		margin-bottom: 10rpx;
		padding: 0rpx 10rpx;
	}
	.uni-info .uni-info_time {
		padding-top: 20rpx;
	}
	
	.uni-info .uni-info_price {
		padding-bottom: 20rpx;
		border-bottom: 8rpx solid #f1f1f1;
	}
	
	.uni-info .uni-info_price .price {
		color: #ff7a55;
	}
	
	.uni-info .uni-info_stock .kefu {
		float: right;
		margin-right: 10rpx;
	}
	
	.uni-content .header {
		padding: 20rpx 10px;
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
		color: #ff7a55;
	}
	
	
	.uni-content .content {
		border-top: 8rpx solid #f1f1f1;
	}

	.uni-content .content {
		padding: 10rpx;
	}
	.uni-buy {
		text-align: center;
		width: 100%;
		position: fixed;
		bottom: 0;
		background-color: #ccad51;
	}
	.uni-buy .uni-buy_btn {
		font-size: 40rpx;
		padding: 20rpx 0rpx;
		color: #fff;
	}
	
	/* 弹窗 */
	.mask {
		z-index: 99;
		background: rgba(0, 0, 0, 0.6);
		position: fixed;
		bottom: 0;
		right: 0;
		left: 0;
		top: 0;
	}
	
	.tip {
		z-index: 999;
		min-width: 600rpx;
		display: flex;
		font-size: 36rpx;
		text-align: center;
		background: #FFFFFF;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		border-radius: 8rpx;
		position: fixed;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}
	.tip .main {
		padding: 50rpx 35rpx 20rpx;
	}
	.tip .count {
		width: 100%;
		text-align: left;
	}
	.tip .count .input-box {
		color: #666;
		background-color: #ccc;
		padding: 6rpx 10rpx;
		font-weight: bold;
		border-radius: 4rpx;
	}
	.tip .count .tip-input {
		display: inline-block;
		width: 120rpx;
		vertical-align: middle;
	}
	.tip .options {
		margin-top: 30rpx;
		text-align: center;
	}
	.tip .options .option {
		border-radius: 4rpx;
		background-color: #ccc;
		padding: 6rpx 10rpx;
		width: 26%;
		margin: 10rpx 3%;
		text-align: center;
		font-weight: bold;
		color: #666;
		display: inline-block;
	}
	
	.tip .options .option.active {
		background-color: #ccad51;
	}
		
	
	.tip .bottom {
		width: 100%;
		position: relative;
		bottom: 0;
	}
	.tip .bottom .btn {
		width: 50%;
		display: inline-block;
		border: 1px solid #ccc;
		padding: 10rpx 0rpx;
		font-weight: bold;
	}
	.tip .bottom .btn.cancel {
		border-bottom-left-radius: 8rpx;
	}
	
	.tip .bottom .btn.confirm {
		color: red;
		border-bottom-right-radius: 8rpx;
	}
</style>
