<template>
	<view>
		<div class="jhyyes">
			<img src="/static/sm.png" alt="" class="img">
		</div>
		<view class="naver" @click="smit">
			扫码粗查
		</view>
	</view>
</template>

<script>
	import url from "@/util/url";
	export default {
		data() {
			return {
				//潜山
				qians:'',
				uehg:1,
				phonhe:'',
				url:url
			};
		},
		onLoad() {
			// this.uehg = 1
			// this.params.parentPhone = uni.getStorageSync('phone')
			console.log(url.host,345)
			let token = uni.getStorageSync('phone')
			this.phonhe = token
			// if(!token){
			// 	uni.redirectTo({
			// 		url: '/pages/login/login'
			// 	})
			// 	return  false
			// }
			this.scanAction()
		},
		onShow() {
			
			// this.uehg = 1
			// this.scanAction()
			console.log(34)
			
		},
		onHide() {
			
			// this.uehg = 2
			console.log(344)
			
		},
		methods:{
			
			smit(){
				this.scanAction()
			},
			
			   //扫码功能
			scanAction() {
				// if(this.uehg == 1){
					const app = getApp();
					wx.scanCode({
					  onlyFromCamera: true,
					  scanType: ['qrCode', 'barCode'],
					     //结果处理
					  success: res => this.dealScanCode(res.result),
					  fail: (e) => {
					      if (e && e.errMsg && e.errMsg.indexOf('scanCode:fail cancel') != -1) {
					          return;
					      }
					      wx.showToast({ title: '扫码失败', icon: 'none', })
					  }
					});
				// }else{
				// 	return
				// }
				
			},
			 // 判断连接
			 dealScanCode(result) {
				 
				 // console.log(result)
				 const app = getApp();
				 console.log(result,123)
			   let str = result
			   
			   // 潜山
			   // this.qians = str.includes('https://qsxyakm.qs163.cn/prod-api/applet/scanQr')
			   // /、岳西 https://yxxy.qs163.cn
			   
			   this.qians = str
			   
			   // console.log(str.includes('https://yuexi.0da.com/applet/scanQr'))
			   // url.host
			   if(this.qians){
				   console.log(123098)
				   uni.request({
				   url: url.host + '/gateway/query/queryReportNum',
				   method: 'POST',
				   header: {
				   		'Content-Type': 'application/x-www-form-urlencoded',
				   		'X-Requested-With': 'xmlhttprequest'
				   	},
				   data:{
					   queryPhone:this.phonhe,
					   reportNumber:result
				   		// pid:this.companyId
				   	},
				    success: function(res) {
				    	console.log(res.data)
				   					if(res.data.code==200){
										let hjees = JSON.stringify(res.data.data)
				   						wx.redirectTo({
				   						  url: '/pages/home/recordtwo?code=' + hjees
				   						})
										console.log(3456)
				   					}else {
										wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000})
				   						setTimeout(function () {
				   						    wx.navigateBack({
				   						      delta: 1 //想要返回的层级
				   						    })
				   						}, 1000);
										
				   						 
				   					}
				    },
				   });
			   }else{
				  uni.showToast({ title: '请扫描正确的二维码', icon: 'none', duration: 3000}) 
				  wx.navigateBack({
				    delta: 1 //想要返回的层级
				  })

			   }
			   
			   // let index = str.indexOf("/");
			   // console.log(index)
			   // let id = str.substring('/');
			   // console.log(id)
			   // this.bindAccount(result)
			   // app.log("scan:" + result)
			   // if (!result || !result.lastIndexOf) {
			   //     wx.showToast({ title: '二维码错误', icon: 'none', duration: 2000 })
			   //    return;
			   //  }
			
			    // 具体的连接处理
			      // if (result.lastIndexOf('synthetical=') != -1) {
			      //  bindAccount(result);
			      //  return;
			      // }
			  
			 //无效的二维码
			  // wx.showToast({ title: '二维码错误', icon: 'none', duration: 2000 })
			 },
			  //处理连接
			     bindAccount(param){
			     // 截取字符串
			     let groupNum = getUrlParam(param, 'chatID')
			    let groupType = getUrlParam(param, 'type');
			    },
			 
			    // 提供外部的接口
			     // module.exports = {
			     //  scanAction,
			     //  dealScanCode,
			     //  getUrlParam
			     // }
				  // 正则表达式截取字符串的方法
				    getUrlParam(url, name) {
				        // 正则筛选地址栏
				        let reg = new RegExp("(^|&|/?|//)" + name + "=([^&]*)(&|$)");
				       // 匹配目标参数
				      let result = url.substr(1).match(reg);
					  console.log(result)
				      //返回参数值
				       // return result ? decodeURIComponent(result[2]) : null;
				   }

		}
	}
</script>

<style lang="scss">
	.jhyyes{
		display: flex;
		justify-content: center;
		margin-top: 200upx;
	}
	.img{
		width: 258upx;
		height: 251upx;
		// margin:  auto;
		// margin-left: 50%;
		// transform: translateX(-50%);
	}
	
	
	.naver{
		width: 85%;
		height: 90upx;
		font-size: 31upx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 90upx;	
		background-color: #1678FF;
		margin-left: 50%;
		transform: translateX(-50%);
		border-radius: 14upx;
		text-align: center;
		margin-top: 150upx;
		}

</style>
