<template name="buy">
	<view>
		<view class="buy-layer" :class="show ?'slidein':''">
		  <form bindsubmit="doBuy">
			<view class="tit ">《{{fetch.info.name}}》{{fetch.info.ticket_name}}</view>
			<view class="msg"><text @click="showTip">查看{{fetch.info.ticket_name}}说明</text> <text class="spliter"></text> <text @click="showInfo">查看介绍</text></view>
			<view class="share_msg" @click="showShare" v-if="fetch.ticket && fetch.ticket.total">共有<text style="color:#007AFF;font-size: 30rpx;padding-left:5rpx;padding-right: 5rpx;">{{fetch.ticket.total}}</text>{{fetch.info.unit}}，当前剩余<text style="color:#CC1619;font-size: 30rpx;padding-left:5rpx;padding-right: 5rpx;">{{fetch.ticket.num}}</text>{{fetch.info.unit}}<text v-if="fetch.ticket.num > 0">，点此分享给好友</text></view>
			<scroll-view scroll-y class="list">
			  <view v-for="(v, k) in fetch.buy" :key="k" class="item" :class="index === k?'active':''" @click="buy(k)">
				<text class="name">{{v.name}}</text>
				<text>￥{{v.price}}</text>
			  </view>
			</scroll-view>
			<view class="btn-wrapper ">
			  <view class="button cancel" @click="hideBuy">取消</view>
			  <view class="button primary" :style="bgcolor" @click="buyAct">确认
				<button formType="submit"></button>
			  </view>
			</view>
		  </form>
		</view>
		<view class="mask" v-if="tip">
		  <view class="buytip-layer layer " catchtap="handleStop">
			<view class="buy-tit">购买说明</view>
			<rich-text class="p" :nodes="fetch.info.buy_content"></rich-text>
			<view class="btn-wrapper">
			  <view class="button" @click="hideTip" :style="bgcolor">我知道了</view>
			</view>
		  </view>
		</view>
		<view class="mask" v-if="info">
		  <view class="buytip-layer layer " catchtap="handleStop">
			<view class="buy-tit">介绍说明</view>
			<rich-text class="p" :nodes="fetch.info.desc"></rich-text>
			<view class="btn-wrapper">
			  <view class="button" @click="hideInfo" :style="bgcolor">我知道了</view>
			</view>
		  </view>
		</view>
		<view class="mask" v-if="share">
		  <view class="buytip-layer layer " catchtap="handleStop">
			<view class="buy-tit">分享给你的好友</view>
			<view class="grace-news-list">
				<view class="grace-news-item" style="padding: 12rpx 8rpx;border: 1px dashed cornflowerblue;">
					<view class="grace-news-body">
						<text class="grace-news-title">{{fetch.share.title}}</text>
						<text class="grace-news-desc">{{fetch.share.content}}</text>
					</view>
					<image :src="fetch.share.pic" class="image grace-news-img grace-news-img-r"></image>
				</view>
				<view class="grace-news-info">
					<view style="width:500rpx;margin-top:20rpx;justify-content: center;" class="grace-nowrap">
						<text class="grace-icons grace-news-info-text">查看 {{fetch.ticket.num}}</text>
						<text class="grace-icons grace-news-info-text" style="margin-left:30rpx;">使用 {{fetch.ticket.num}}</text>
						<text class="grace-icons grace-news-info-text" style="margin-left:30rpx;">剩余 {{fetch.ticket.num}}</text>
					</view>
				</view>
			</view>
			<!--
			<view class="share_left">
				<text class="p">{{fetch.share.title}}</text>
				<text class="p">{{fetch.share.content}}</text>
			</view>
			<view class="share_right">
				<image :src="fetch.share.pic" class="image"></image>
			</view>
			-->
			<view class="grace-form-item grace-border-b">
				<view class="grace-form-body" style="margin-left:0rpx">
					<input type="text" class="grace-form-input" style="text-align:left" name="desc" @blur="saveTicket" @confirm="saveTicket" v-model="fetch.ticket.desc" placeholder="在这里输入一句话,你的好友能够看到哦~" />
				</view>
			</view>
			<view class="btn-wrapper">
				<view class="button cancel" @click="hideShare">取消</view>
				<view class="button primary" :style="bgcolor" @click="onShare">分享
					<button formType="submit"></button>
				</view>
			</view>
		  </view>
		</view>
		<view class="mask success-tip" v-if="pay">
		  <view class="layer">
			<view class="tit">支付成功</view>
			<view class="msg">您已成功购买{{paycount}}张{{fetch.info.ticket_name}}</view>
			<view class="btn-wrapper">
			  <view class="button" @click="gotoCodeDetail">赠送{{fetch.info.ticket_name}}</view>
			  <view class="button" @click="gotoRead">立即进入</view>
			</view>
		  </view>
		</view>
	</view>
</template>

<script>
export default {
	name: "buy",
	props: {
		id : 0,
		bgcolor : '',
		color : '',
		code : '',
		name : '',
	},
	data() {
		return {
			fetch : {
				buy : [],
				info : {},
			},
			index : 0,
			pay : false,
			info : false,
			tip : false,
			show : false,
			share : false,
		}
	},
	mounted() {
		this.getData();
	},
	methods:{
		getData : function() {
			var self = this;
			var url = this.Dever.host + '/pages/dream/index';
			this.Dever.get(this, 'app/collection/?l=api.getBuy', {id:this.id, code:this.code, url:url}, function(t) {
				self.show = true;
			});
		},
		//购买
		buy : function(index) {
			this.index = index;
		},
		//拉起支付
		buyAct : function() {
			var self = this;
			var data = {};
			data.buy_id = this.fetch.buy[this.index].id;
			var location = 'dream/view?code='+this.code + '&name=' + this.name;
			data.refer = this.Dever.host + '/' + location;

			this.Dever.post('app/user/?l=pay.ticket', data, function(t) {
				//console.info(t);
				self.Dever.pay(t, location, '支付失败');
			});
			/*
			this.Dever.alert('拉起支付', 'none', function() {
				self.$emit('view');
			});
			*/
		},
		showTip : function() {
			this.tip = true;
		},
		hideTip : function() {
			this.tip = false;
		},
		showInfo : function() {
			this.info = true;
		},
		hideInfo : function() {
			this.info = false;
		},
		showShare : function() {
			this.share = true;
		},
		hideShare : function() {
			this.share = false;
		},
		onShare : function() {
			this.$emit('share');
		},
		hideBuy : function() {
			this.show = false;
			this.$emit('hideBuy');
		},
		saveTicket : function() {
			var data = {};
			data.ticket_id = this.fetch.ticket.id;
			data.desc = this.fetch.ticket.desc;
			data.noloading = 1;
			this.Dever.post('app/user/?l=api.ticketSave', data);
		}
	},
	components:{
		
	}
}
</script>

<style>
.spliter{
  flex-shrink: 0;
  width: 1rpx;
  background: #fff;
  height: 40rpx;
  color: #333;
  margin-left: 20rpx;
}
.share_left {
	position: relative;
}
.share_right {
	position: relative;
}
.image {
	width:150rpx;
	height:150rpx;
}
.buy-layer{
  padding: 50rpx 55rpx 62rpx;
  background-color: #fff;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  transform: translateY(100%);
  transition-property: transform;
  transition-duration: 0.3s;
  transition-timing-function: ease-in;
  overflow: auto;
}
.buy-layer.slidein{
  transform: translateY(0);
}
.buy-layer .tit{
  font-weight: bolder;
  font-size: 36rpx;
  margin: 0 0 40rpx;
  text-align: center;
}
.buy-layer .msg{
  font-size: 22rpx;
  line-height: 36rpx;
  width: 640rpx;
  margin: 0 auto 47rpx;
  text-align: center;
  text-decoration: underline;
  color: #666;
}
.buy-layer .share_msg{
  font-size: 22rpx;
  line-height: 36rpx;
  width: 640rpx;
  margin: 0 auto 47rpx;
  color: #666;
  text-align: center;
  border: 1px dashed cornflowerblue;
}
.btn-wrapper {
  justify-content: space-around;
  width: 100%;
}

.button {
  height: 80rpx;
  border: 1rpx solid #cc1619;
  color: #cc1619;
  font-size: 30rpx;
  min-width: 300rpx;
  border-radius: 40rpx;
  text-align: center;
  line-height: 80rpx;
  display: block;
  position: relative;
}
.button>button{
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  opacity: 0;
}

.button.big {
  width: 420rpx;
}

.button.primary {
  background-color: #000;
  color: #fff;
}

.button.blk {
  background-color: #000;
  color: #fff;
  border-color: #000;
}
.btn-wrapper{
  display: flex;
  justify-content: space-between;
  padding-top: 20rpx;
}
.btn-wrapper .button{
  border: 0;
  min-width: 0;
  box-sizing: border-box;
  color: #999999;
  width: 284rpx;
  border-radius: 5rpx;
}
.btn-wrapper .button.primary{
  border:0;
  color: #fff;
}
.btn-wrapper .button.cancel{
  border:0;
  background-color: #CCCCCC;
  color: #fff;
}
.list{
  max-height: 500rpx;
}
.list .item{
  height: 100rpx;
  border-radius: 10rpx;
  border: 1rpx solid #999;
  color: #999;
  margin-bottom: 30rpx;
  box-sizing: border-box;
  padding: 0 30rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 30rpx;
}
.list .item.active{
  border-color: #000;
  color: #000;
}
.list .item .name{
  display: flex;
  align-items: center;
}
.list .item .name:before{
  content: "";
  width: 40rpx;
  height: 40rpx;
  display: block;
  background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1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EVbgKpVuXLJml1XU70/bAdzAZsS3KYtQk2+yp2eoxxhjMXQYuqg416nIXMD0xWxP6m9NyqbDaDr7R5JRKu2zgp8RVN1xzE1w5IhNWF9mO3tr1CXxSe7erLti2l32duTQqtspvV/f34INXpv+GiNJ/AQYAgCbhym+3rl8AAAAASUVORK5CYII=) no-repeat;
  
  background-size: 40rpx 40rpx;
  flex-shrink: 0;
  padding-right: 30rpx;
}
.list .item.active .name:before{
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAABgmlDQ1BzUkdCIElFQzYxOTY2LTIuMQAAKJF1kb9LQlEUxz9qYVhhVFBDg0Q1aZiB1NKglAXVYAb9WvTlj0Dt8Z4R0hq0CgVRS7+G+gtqDZqDoCiCaGlpLmopeZ2XghJ5Lueez/3eew73ngvWSFrJ6HVeyGRzWjgUcM3NL7jsL9hpxYGNjqiiq1MzYxFq2uc9FjPeesxatc/9a43LcV0BS4PwiKJqOeFx4cn1nGryjnC7koouC58JuzW5oPCdqcdK/GpyssTfJmuRcBCsLcKuZBXHqlhJaRlheTk9mfSaUr6P+ZKmeHZ2RmK3eBc6YUIEcDHBKEH8DDAssx8PPvplRY1872/+NKuSq8iskkdjhSQpcrhFXZPqcYkJ0eMy0uTN/v/tq54Y9JWqNwWg/tkw3nvBvg3FgmF8HRlG8RhsT3CZreSvHsLQh+iFitZzAM5NOL+qaLFduNiCzkc1qkV/JZu4NZGAt1Nonoe2G3AslnpW3ufkASIb8lXXsLcPfXLeufQDE6lnwO9DRkoAAAAJcEhZcwAACxMAAAsTAQCanBgAAAKDSURBVFiF1dk/axRBGMfxT06CgaBJI4FgISGQMtEijSin2Ik2V1qFFHkF+grSWaayFS++gZDC2CQgqIWQUjSQwkYIIpGIYkCL3SW7k7nL3t4fLz9YOHaeeea7M7vP88zciGoaxU3cww3MYQrjafsRvuIjPuA13uBPxfFKaxZrOMDfDq+DtO9sP8Cm0cRxBbDwOk59TZcZeKSEzQqe4lKk7TfeYxf7+J7en8Q1zGMRFyN9f+AxnpUBjWkM6+KzsIFGalPGTyPtE/O1XtJPQRPYjjjbwkKnznJaSH2EfrfTMUtpLAJ3hKUuwEItpT5DyFIzGS7rF8m71GvNp77D5W6rlQjcTB/gMs04DbnSyngah4rL2o+ZCzWvuNyHWoSgpuKT9PKdO0tLwdjN0GBWMQhvDRAuU/7rPhZknDXFJ+gmlFTVQsCwljWMKubWjT6DjOI2rkTa8sH8ILVVVyRv9BFuAm/Tcb45/TE0ApY6rOZu/FIh7XQA9y4AeBjYjKUMWfsqbOZu7AwQ7hMuR2x3cjabNUmxmWm3T3CvJFVNpj3ckcS8UHmGuZqkEs60PyC4uiSDxJRnmKo5KdM5qediGsED3FeujqwCFzKMU3wvltt0fJKze4ELZ8CF79xnXG3TJ9Nyvl9NkgczTbbpeD33+xGet4CsOnMxhqOs86noHdEifirOSjOA7GbmMuWz2h6dhZm7bSB7AUcQZug8UMcgX/YILhqo64HjMqkuBtktHC1SXdVioRVkVThaFAtUL7dCyG7gWpZbdFew3pJs3je6gOOMgpUhL/k5B5smhnzbmWmoN+6cg6MPhvzwKNNQHL+d6wPMvP7bEXCnGvghepkljmlgf0P8A8uurmx6Sm7EAAAAAElFTkSuQmCC);
}

.buytip{
  font-size: 24rpx;
  color: #999999;
  text-decoration: underline;
  padding-bottom: 40rpx;
}

.p{
  font-size: 28rpx;
  text-align: justify;
  line-height: 40rpx;
  margin-bottom: 12rpx;
  display: block;
  box-sizing: border-box;
}
.buy-tit{
  font-size: 40rpx;
  /* font-weight: bolder; */
  text-align: center;
  margin-bottom: 40rpx;
}
.mask .buytip-layer{
  padding: 60rpx; 
}
.buytip-layer .button{
  width: 300rpx;
  line-height: 80rpx;
  height: 80rpx;
  background-color: #000;
  color: #fff;
  border: 0;
  border-radius: 5rpx;
  margin: 0 auto;
}

.success-tip .layer{
  padding: 0;
  border-radius: 5rpx;
}
.success-tip .layer .msg{
  font-size: 32rpx;
  text-align: center;
}
.success-tip .layer .tit{
  font-size: 36rpx;
  text-align: center;
  margin: 62rpx 0 65rpx;
}
.success-tip .layer .btn-wrapper{
  display: flex;
  padding-top: 87rpx;
}
.success-tip .layer .btn-wrapper .button{
  border: 0;
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  font-size: 32rpx;
  color: #000;
}
.success-tip .layer .btn-wrapper .button:first-child{
  border-top: 1rpx solid #CCCCCC;
  border-radius: 0;
}
.success-tip .layer .btn-wrapper .button:last-child{
  background-color: #000;
  color: #fff;
  border-radius: 0 0 5rpx 0;
}
.mask {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.mask .layer {
  width: 620rpx;
  box-sizing: border-box;
  padding: 70rpx 60rpx;
  background: #fff;
  border-radius: 10rpx;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}

.mask .layer .tit {
  text-align: center;
  font-size: 40rpx;
  margin: 16rpx 0 60rpx;
}

.mask .layer input {
  border-radius: 10rpx;
  border: 1rpx solid #999;
  height: 88rpx;
  line-height: 88rpx;
  padding: 0 28rpx;
  box-sizing: border-box;
  font-size: 24rpx;
}

.mask .layer .errtip {
  color: #d1171a;
  text-align: center;
  font-size: 24rpx;
  margin: 21rpx 0;
  height: 34rpx;
}

.mask .layer .btn-wrapper {
  padding-top: 30rpx;
}

.mask .btn-wrapper{
  display: flex;
  justify-content: space-between;
  padding-top: 20rpx;
}
.mask .btn-wrapper .button{
  border: 0;
  min-width: 0;
  box-sizing: border-box;
  /*color: #999999;*/
  width: 200rpx;
  border-radius: 5rpx;
}
</style>
