<template name="dever-share">
	<view>
		<dever-popup ref="popup" type="bottom">
			<view class="sharebtn">
				<view class="uni-share">
					<view class="uni-share-content">
						<view v-for="(v, k) in button" :key="k" class="uni-share-content-box" :style="v.type == 'copy' ? 'margin-right:0rpx;' : mr" @click='share(v.type)'>
							<view class="uni-share-content-image">
								<image :src="v.icon" class="content-image" />
							</view>
							<text class="uni-share-content-text">{{ v.text }}</text>
						</view>
					</view>
				</view>
			</view>
		</dever-popup>
	</view>
</template>

<script>
	import deverPopup from "@/lib/dever/components/popup.vue"; 
	import copyText from "@/lib/clipboard.thorui.js";
	import wx from "@/lib/dever/components/jweixin.js"; 
	export default {
		data() {
			return {
				button: [{
						text: '微信',
						icon: '/static/dever/weixin.png',
						type: 'weixin'
					},
					{
						text: '朋友圈',
						icon: '/static/dever/pengyouquan.png',
						type: 'weixin_group'
					},
					{
						text: 'QQ',
						icon: '/static/dever/qq.png',
						type: 'qq'
					}
				],
			}
		},
		props: {
			id : 0,
			data : {},
			code : '',
		},
		created : function() {
			this.mr = 'margin-right:60rpx';
			if (this.data && this.data.poster) {
				this.mr = 'margin-right:40rpx';
				this.button.push({
					text: '海报',
					icon: '/static/dever/poster.png', 
					type: 'poster'
				});
			}
			
			this.button.push({
				text: '复制',
				icon: '/static/dever/copy.png',
				type: 'copy'
			});
			
			if (this.code) {
				this.data.link = this.data.link + '?code=' + this.code;
			}
			
			this.init();
		},
		methods: {
			open : function() {
				this.$refs.popup.open();
			},
			
			init : function() {
				if (this.Dever.source == 'h5') {
					this.Dever.shareInit(wx, 1, false, this.data);
				}
			},
			
			share : function(type) {
				eval("this."+type+"()");
			},
			
			copy : function() {
				var self = this;
				var value = this.data.title;
				if (this.data.content) {
					value += "\r\n" + this.data.content;
				}
				if (this.data.link) {
					value += "\r\n" + this.data.link;
				}
				copyText.getClipboardData(value, function(res) {
					if (res) {
						self.Dever.alert('复制成功');
					} else {
						self.Dever.alert('复制失败');
					}
				});
			},
			
			weixin : function() {
				this.Dever.share('weixin', 'WXSceneSession', 0, this.data);
			},
			
			weixin_group : function() {
				this.Dever.share('weixin', 'WXSenceTimeline', 0, this.data);
			},
			
			qq : function() {
				this.Dever.share('qq', '', 1, this.data);
			},
			
			poster : function() {
				if (this.data.poster) {
					// 弹出海报
				} else {
					this.Dever.alert('没有海报素材');
				}
			}
		},
		components:{
			deverPopup
		}
	}
</script>

<style lang="scss">
	/* 底部分享 */
	.sharebtn {
		.uni-share {
			width: 690rpx;
			margin: 30rpx;
			border-radius: 30rpx;
			/* #ifndef APP-NVUE */
			display: flex;
			flex-direction: column;
			/* #endif */
			background-color: #fff;
			.uni-share-content {
				/* #ifndef APP-NVUE */
				display: flex;
				/* #endif */
				flex-direction: row;
				flex-wrap: nowrap;
				justify-content: center;
				overflow-x: scroll;
				padding: 15px 50rpx;
				.uni-share-content-box {
					/* #ifndef APP-NVUE */
					display: flex;
					/* #endif */
					flex-direction: column;
					align-items: center;
					// width: 25%;
					// justify-content: space-between;
					&:nth-last-child(1) {
						margin-right: 0;
					}
					.uni-share-content-image {
						/* #ifndef APP-NVUE */
						display: flex;
						/* #endif */
						flex-direction: row;
						justify-content: center;
						align-items: center;
						width: 90rpx;
						height: 90rpx;
						overflow: hidden;
						border-radius: 10rpx;
						.content-image {
							width: 90rpx;
							height: 90rpx;
						}
					}
					&:nth-last-child(1){
						.uni-share-content-image .content-image {
							width: 50rpx!important;
							height: 50rpx!important;
						}
					}
					.uni-share-content-text {
						font-size: 26rpx;
						color: #333;
						padding-top: 5px;
						padding-bottom: 10px;
					}
				}
			}
		}
	}
</style>
