<template>
	<view></view>
</template>

<script>

	import wx from 'weixin-js-sdk'
	import * as API_WeiXin from '@/apis/weixin'

	export default {
		name: 'Share',
		props: {
			 
		},
		data() {
			return {
				id:'',
				title:'',
				url:'',
				isLoading: false,
				nowItem: {
					shareTitle: '',
					shareImg: '',
					shareDescription: ''
				}
			}
		},
		created() {},
		methods: {
			 addPoint(){
				 if(this.id){
					 API_WeiXin.addPoint({
					 					 id:this.id,
					 					 pointCode:"70007"
					 }).then(response => {
					 		//("积分添加成功")
							uni.showToast({
								title: "分享成功",
								icon: "none"
							})
									 
					 })
				 }
				 
			 },
			
			//获取微信jssdk配置信息
			get_wx_config() {
				
				
				API_WeiXin.getConfig(window.location.href.split("#")[0]).then(response => {
					
					
					var wxconfig = response.data.wxConfig;
					
					//(wxconfig.nonceStr)
					//this.wxConfig = wxconfig;
				
					wx.config({
						debug: false, // 开启调试模式,
						appId: wxconfig.appId, // 必填，企业号的唯一标识，此处填写企业号corpid
						timestamp: wxconfig.timestamp, // 必填，生成签名的时间戳
						nonceStr: wxconfig.nonceStr, // 必填，生成签名的随机串
						signature: wxconfig.signature, // 必填，签名，见附录1
						jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 
						'onMenuShareQQ', 'onMenuShareQZone'] ,// 必填，需要使用的JS接口列表，所有JS接口列表见附录2
						//'checkJsApi',,'updateAppMessageShareData','updateTimelineShareData'
					});
					
						//("aaa")
					//this.wxShare()
				}).catch(error => {
					//(error)
						//("errorerror")
				})
			},
			setUrl(url){
				this.url=url;
			},
			setTitle(text,id){
				this.title=text;
				this.id=id;
				this.wxShare() 
				
			},
			//微信分享自定义
			wxShare() {
				var userInfo=this.carhelp.getPersonInfo()
				var img=require("@/assets/img/logo.png")
				
				var title=this.title
			//	var desc=
				let joinUrl = this.url;
				//(img);
				//(title);
				//(joinUrl);
				var _this = this;
				
				wx.ready(function() {
					
					
					// wx.updateTimelineShareData({
					// 	title: title,
					// //	desc:desc ,
					// 	link: joinUrl,
					// 	 imgUrl: img,
					// 	success: function() {
					// 		if(userInfo){
					// 			//_this.addPoint()
					// 		}
					// 		// 设置成功
					// 		_this.$emit("wxShare",null);
					// 	}
					// })
					// wx.updateAppMessageShareData({
					// 	title: title,
					// //	desc:desc ,
					// 	link: joinUrl,
					// 	 imgUrl: img,
					// 	success: function() {
					// 		if(userInfo){
					// 			//_this.addPoint()
					// 		}
					// 		// 设置成功
					// 		_this.$emit("wxShare",null);
					// 	}
					// })
					wx.onMenuShareAppMessage({
						title: title,
					 	desc:"[电管家]" ,
						link: joinUrl,
						 imgUrl: img,
						success: function() {
							//('111')
							if(userInfo){
								_this.addPoint()
							}
							// 设置成功
							_this.$emit("wxShare",null);
						}
					})
					wx.onMenuShareTimeline({
						title: title,
						desc:"[电管家]" ,
						link: joinUrl,
						 imgUrl: img,
						success: function() {
								//('222')
							if(userInfo){
								_this.addPoint()
							}
							// 设置成功
							_this.$emit("wxShare",null);
						}
					})
				});
			}
		},
		mounted() {
			this.url=window.location.href;
			this.get_wx_config();
		},
	}
</script>

<style>
</style>
