<template>
	<view class="content">
		<view class="box">
			<web-view :src="url" @message="message"></web-view> 
		</view>
		<!-- <view>12zf</view> -->
		 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: '',
				shopId:'',
				wxOpendata:'',
				logindata:'',
				id:'',
			}
		},
		onLoad(opt) {
			var that=this;
			this.wxOpendata=uni.getStorageSync("wxOpendata");
			this.logindata=uni.getStorageSync("logindata");
			//this.wxOpendata.code='39C455DB5CAF4FD4AE5F3F52EBA8ABD6'
			//opt.scene='E37BB2965A084534859DB351BA611AF9' //连锁二号
			//opt.scene='1B43BADDB6704B27B6C1604523287EAF' //连锁一号
			if(opt.scene){
				this.shopId=opt.scene;
				that.shopId=that.insertStr(that.shopId,8,"-");
				that.shopId=that.insertStr(that.shopId,13,"-");
				that.shopId=that.insertStr(that.shopId,18,"-");
				that.shopId=that.insertStr(that.shopId,23,"-");
				uni.setStorage({
					key: 'shopId',
					data: that.shopId,
					success: function () {
					}
				});
				if(this.shopId!=this.wxOpendata.shopID){
					uni.removeStorageSync('wxOpendata');
					this.wxOpendata=''
				}
			}
			if (opt.path) {
			      //this.url = `${this.url}${options.path}`
				   //this.url = opt.path
				    console.log('options', opt)
					//console.log(opt)
					var url=opt.path.replace('$', '?')
					this.shopId=opt.shopId;
					if(this.shopId!=this.wxOpendata.shopID){
						if(opt.shareID){
							 var webviewurl=url+'&shareID='+opt.shareID+'&type='+opt.type
						}else{
							 var webviewurl=url+'&type='+opt.type
						}
						var testshopid='1B43BADD-B670-4B27-B6C1-604523287EAF'
						uni.setStorage({
							key: 'webviewurl',
							data: webviewurl,
							success: function () {
								uni.navigateTo({
									url:'../login/empower?shopId='+that.shopId
								})
								uni.removeStorageSync('wxOpendata');
							}
						});
						return false;
					}
					if(that.wxOpendata.code){
						if(opt.shareID){
							 var webviewurl=url+"&codeapp="+that.wxOpendata.code+'&shareID='+opt.shareID+'&type='+opt.type+'&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
						}else{
							 var webviewurl=url+"&codeapp="+that.wxOpendata.code+'&type='+opt.type+'&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
						}
						this.url = webviewurl;
						/* uni.setStorage({
							key: 'webviewurl',
							data: webviewurl,
							success: function () {
								uni.navigateTo({
									url:'../login/empower'
								})
							}
						}); */
					}else{
						if(opt.shareID){
							 var webviewurl=url+'&shareID='+opt.shareID+'&type='+opt.type
						}else{
							 var webviewurl=url+'&type='+opt.type
						}
						uni.setStorage({
							key: 'webviewurl',
							data: webviewurl,
							success: function () {
								uni.navigateTo({
									url:'../login/empower'
								})
							}
						});
					}
				   
			        console.log(url)
			}else{
				var newwebviewurl = uni.getStorageSync('webviewurl');
				
				if(newwebviewurl){
					newwebviewurl=newwebviewurl+"&codeapp="+that.wxOpendata.code+'&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
					this.url=newwebviewurl;
					uni.removeStorageSync('webviewurl');
				}else{
					
				
				uni.getLocation({
				    type: 'gcj02',
				    success: function (res) {
				        console.log('当前位置的经度是：' + res.longitude);
				        console.log('当前位置的纬度：' + res.latitude);
						if(opt.id){
							if(opt.type==6){
								that.url=that.$webURL+'paySuccessPinTuan?id='+opt.id+'&hideHeader=true&codeapp='+that.wxOpendata.code+'&lat='+res.latitude+'&lng='+res.longitude+'&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
							}else{
								that.url=that.$webURL+'paySuccess?orderId='+opt.id+'&hideHeader=true&codeapp='+that.wxOpendata.code+'&lat='+res.latitude+'&lng='+res.longitude+'&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
							}
							
						}else{
							/* if(!that.wxOpendata.shopID||!that.logindata){
								uni.navigateTo({
									url:'../login/empower'
								})
							} */
							
							if(that.wxOpendata.code){
								//this.url='http://dms.32che.cn/#/carOwner/index?codeapp='+this.wxOpendata.code+ '&shopId='+this.wxOpendata.shopID
								that.url=that.$webURL+'carOwner/index?codeapp='+that.wxOpendata.code+ '&shopId='+that.wxOpendata.shopID+'&lat='+res.latitude+'&lng='+res.longitude+'&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
							}else{
								that.url=that.$webURL+'carOwner/index?codeapp=&shopId=&lat='+res.latitude+'&lng='+res.longitude
							}
						}
				    },
					fail(err) {
						console.log(err)
					    if(opt.id){
					    	if(opt.type==6){
					    		that.url=that.$webURL+'paySuccessPinTuan?id='+opt.id+'&hideHeader=true&codeapp='+that.wxOpendata.code+'&lat=&lng=&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
					    	}else{
					    		that.url=that.$webURL+'paySuccess?orderId='+opt.id+'&hideHeader=true&codeapp='+that.wxOpendata.code+'&lat=&lng=&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
					    	}
					    }else{
					    	if(!that.wxOpendata.shopID){
					    		uni.navigateTo({
					    			url:'../login/empower'
					    		})
					    	}
					    	if(that.wxOpendata.code){
					    		//this.url='http://dms.32che.cn/#/carOwner/index?codeapp='+this.wxOpendata.code+ '&shopId='+this.wxOpendata.shopID
					    		that.url=that.$webURL+'carOwner/index?codeapp='+that.wxOpendata.code+ '&shopId='+that.wxOpendata.shopID+'&lat=""&lng=""'+'&isDmsOpen='+that.wxOpendata.isDmsOpen+'&isMarketingOpen='+that.wxOpendata.isMarketingOpen
					    	}
					    }
					}
				});
				}
			}
			
			
			console.log(opt)
			//opt.id='3A9DBC40-D5D4-43A6-8ACA-5CF909771512'
			
			
			/* if(opt.shopId){
				this.url2='http://wx.32che.cn/weixin/authorize?path=/carOwner/index&isCarOwner=true&shopId='+opt.shopId
			} */
           //http://192.168.0.215:9588/#/carOwner/index?codeapp=D8E849B9EE0D4A07812BB0186E77B993&lat=36.68013&lng=117.06533
		   
		
		   
		},
		
		
		    
		
		methods: {
			goUrl(){
				
			},
			insertStr(soure, start, newStr){
			   return soure.slice(0, start) + newStr + soure.slice(start);
			},
           message(event){
               console.log(event);
           	let { data } = event.mp.detail
           	console.log('message', data)
           	this.shareData = JSON.parse(data.pop())
           	console.log(this.shareData)
           	//this.shareData= event.mp.detail
           },
		},
		onShareAppMessage(){
			console.log(this.shareData)
			/* var share={
				url:this.shareData.path
			}
			var obj=JSON.stringify(share) */
			var newUrl=this.shareData.path.replace('?', '$')
			newUrl=newUrl+'&shopId='+this.wxOpendata.shopID
			console.log(newUrl)
			/*   
			    if (this.shareData) {
			       path = shareData.path
			    } */
		 return {
		       title:this.shareData.title,
		       path: 'pages/index/index?path='+ encodeURI(newUrl),
			   //path: 'pages/index/home?path='+ obj+'&id='+this.shareData.id+'&shareID='+this.shareData.shareID,
		       imageUrl:this.shareData.img,
			   desc:this.shareData.desc,
		       success: function (res) {
		           // 转发成功
		         wx.showToast({
		           title: "转发成功",
		           icon: 'success',
		           duration: 2000
		         })
		       },
		       fail: function (res) {
		           // 转发失败
		       },
			   }
		
		}
	}
</script>

<style>
	.content {
		/* display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center; */
		
	}
	.box{
		padding-bottom: env(safe-area-inset-bottom);
		
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
