<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 => {
					 		console.log("积分添加成功")
							uni.showToast({
								title: "分享成功",
								icon: "none"
							})
									 
					 })
				 }
				 
			 },
			
			//获取微信jssdk配置信息
			get_wx_config() {
				
				
				API_WeiXin.getConfig(window.location.href.split("#")[0]).then(response => {
					
					
					var wxconfig = response.data.wxConfig;
					
					console.log(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'
					});
					
						console.log("aaa")
					//this.wxShare()
				}).catch(error => {
					console.log(error)
						console.log("errorerror")
				})
			},
			setUrl(url){
				this.url=process.car.IMG_URL+"railroad-phone/#"+url;
			},
			setTitle(text,id){
				this.title=text;
				this.id=id;
				this.wxShare() 
				
			},
			//微信分享自定义
			wxShare() {
				var userInfo=this.carhelp.getPersonInfo()
				var img=process.car.IMG_URL+"railroad-phone/"+require("@/assets/img/logo.png")
				
				var title=this.title
			//	var desc=
				let joinUrl = this.url;
				console.log(img);
				console.log(title);
				console.log(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() {
							console.log('111')
							if(userInfo){
								_this.addPoint()
							}
							// 设置成功
							_this.$emit("wxShare",null);
						}
					})
					wx.onMenuShareTimeline({
						title: title,
						desc:"[荆州市地方铁路有限公司微官网]" ,
						link: joinUrl,
						 imgUrl: img,
						success: function() {
								console.log('222')
							if(userInfo){
								_this.addPoint()
							}
							// 设置成功
							_this.$emit("wxShare",null);
						}
					})
				});
			}
		},
		mounted() {
			this.url=window.location.href;
			this.get_wx_config();
		},
	}
</script>

<style>
</style>
