<template></template>
<script>
	import req from '../../utils/request.js';
	export default {
		// props: ['title', 'desc', 'url', 'image', 'hideItem'],

		data() {
			return {
				shareContent: ''
			};
		},

		methods: {
			getData() {
				var configRes = JSON.parse(req.getStorage('configRes'));
				return {
					title: this.shareContent && this.shareContent.title ? this.shareContent.title : '绿萝云', // 分享标题
					desc: this.shareContent && this.shareContent.desc ? this.shareContent.desc : '绿萝云', // 分享描述
					link: this.shareContent && this.shareContent.path ? this.shareContent.path : window.location
						.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
					imgUrl: this.shareContent && this.shareContent.imageUrl ? this.shareContent.imageUrl : configRes.CONFIG_PROJECT_LOGO, // 分享图标
					success: () => {

					}
				};
			},
			wxShareTimeline() {
				let data = this.getData();
				console.log('wxShareTimeline>>>>>>>', data);
				jWeixin.updateAppMessageShareData(data);
				jWeixin.onMenuShareTimeline(data);
				jWeixin.onMenuShareAppMessage(data);
				jWeixin.onMenuShareQQ(data);
				jWeixin.onMenuShareQZone(data);
			},
			wxShareAppMessage() {
				let data = this.getData();
				console.log('wxShareAppMessage>>>>>>>', data);
				jWeixin.updateTimelineShareData(data);
			},

			hideShareItem() {
				var url = window.location.href;
				req.getRequestKDX(
					'/api/getWeiXinJsApiInfo', {
						url: url
					},
					data => {
						jWeixin.config({
							debug: false, // 开启调试模式
							appId: data.appId, // 必填，公众号的唯一标识
							timestamp: data.timestamp, // 必填，生成签名的时间戳
							nonceStr: data.nonceStr, // 必填，生成签名的随机串
							signature: data.signature, // 必填，签名
							jsApiList: [
								'hideMenuItems' //自定义“分享给朋友”及“分享到QQ”按钮的分享内容
							]
						});
						jWeixin.ready(function() {
							jWeixin.hideMenuItems({
								menuList: [
									'menuItem:share:appMessage',
									'menuItem:share:timeline',
									'menuItem:share:qq',
									'menuItem:share:facebook',
									'menuItem:share:QZone',
									'menuItem:copyUrl'
								]
							});
						});
					},
					err => {}
				);
			},
			initShare() {
				let that = this;
				var url = window.location.href;
				req.getRequestKDX(
					'/api/getWeiXinJsApiInfo', {
						url: url
					},
					res => {
						jWeixin.config({
							debug: false, // 开启调试模式
							appId: res.appId, // 必填，公众号的唯一标识
							timestamp: res.timestamp, // 必填，生成签名的时间戳
							nonceStr: res.nonceStr, // 必填，生成签名的随机串
							signature: res.signature, // 必填，签名
							jsApiList: [
								'updateAppMessageShareData',
								'updateTimelineShareData',
								'onMenuShareTimeline',
								'onMenuShareAppMessage',
								'onMenuShareQQ',
								'onMenuShareQZone',
								'chooseWXPay', //
								'scanQRCode', //扫码
								'getLocation', //定位
							]
						});
						jWeixin.ready(function(res) {
							that.wxShareAppMessage();
							that.wxShareTimeline();
						});
						jWeixin.error(function(res) {
							console.log(res);
						});
					},
					err => {}
				);
			},

			init(shareContent) {
				this.shareContent = shareContent;
				var ua = navigator.userAgent.toLowerCase();
				if (ua.indexOf('micromessenger') != -1) {
					console.log(this.hideItem);
					if (this.hideItem) {
						this.hideShareItem();
					} else {
						this.initShare();
					}
				}
			},
		},
		created() {

		}
	};
</script>