<template>
	<view>
		<!-- <view class="naver" @click="smit">
			扫码登录
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//潜山
				qians:'',
				uehg:1
			};
		},
		onLoad() {
			// this.uehg = 1
			this.scanAction()
		},
		onShow() {
			// this.uehg = 1
			// this.scanAction()
		},
		onHide() {
			// this.uehg = 2
		},
		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) {
				 const app = getApp();
				 console.log(result,123)
			   let str = result
			   // https://qsfy.qs163.cn/
			   this.qians = str.includes('https://qsdp.qs163.cn/prod-api/auth/scanCode')
			   console.log(str.includes('https://qsdp.qs163.cn/prod-api/auth/scanCode'))
			   // 潜山
			   // this.qians = str.includes('https://qsxyakm.qs163.cn/prod-api/applet/scanQr')
			   // /、岳西 https://yxxy.qs163.cn   https://qsfy.qs163.cn
			   
			   if(this.qians){
				   console.log(123098)
				   // wx.navigateTo({
				   //   url: '/add/pages/addvacfrom/wufa?code=' + this.qians
				   // })
				   uni.request({
				   	url:  result,
				   	data:{
				   		// pid:this.companyId
				   	},
				    success: function(res) {
				    	console.log(res.data)
				   					if(res.data.code==200){
				   						wx.navigateTo({
				   						  url: '/add/pages/addvacfrom/wufa?code=' + res.data.data
				   						})
										console.log(3456)
				   					}else {
				   						wx.navigateBack({
				   						  delta: 1 //想要返回的层级
				   						})
				   						 wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000})
				   					}
				    	
				    },
				   });
			   }else{ 
				  wx.navigateBack({
				    delta: 1 //想要返回的层级
				  })
				   uni.showToast({ title: '请扫描正确的二维码', icon: 'none', duration: 3000}) 
				   
			   }
			   
			   // 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">
	.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: 250upx;
		}

</style>
