<template>
	<view class="content">
	<!-- 	<view>11{{code}}</view> -->
  <!-- <view>agentId:{{agentId}}</view>
	<view>code:{{code}}</view> -->
	</view>
</template>

<script>

	export default {
		components: {
		
		},
		
		data() {
			return {
			 code:'',
			 corpID:'',
			 agentId:'',
			}
		},
		onLoad(opt) {
		  console.log(opt)
		  this.agentId=opt.agentid
		  this.corpID=opt.appid
		  if(this.agentId){
			  uni.setStorage({
			  	key: 'corpID',
			  	data: opt.appid,
			  	 success: function () {	
			  					
			  	 }
			  });
			  uni.setStorage({
			  	key: 'agentId',
			  	data: opt.agentid,
			  	 success: function () {	
			  				
			  	 }
			  });
		  }
		  
		  uni.showLoading({
		   	title: '加载中'
		  }); 
            //const token = uni.getStorageSync('token');
		  // this.init()
		// this.code= this.$common.getHashQuery('code')
		  // this.code=uni.getStorageSync('code')
		  if(opt.code){
			   uni.hideLoading();
			  this.code=opt.code
			  uni.setStorage({
			  	key: 'code',
			  	data: opt.code,
			  	 success: function () {	
					 uni.navigateTo({
					 	url:'index'
					 }) 
			  	 }
			  });
			 
		  }else{
			  this.$http('enterpriseWechat/auth/oAuth2', {
			       corpID:opt.appid,
			  	   redirectUri:this.$configUrl+'pages/index/auto',
			  	   agentId:opt.agentid
			  }, 'GET').then(res => {
			  	//console.log(res.data)
			  	location.href=  res.data
			  	
			  }).catch(err=>{
			  		
			  })
		  }
		   
		},
		methods: {
		   init(){
			    this.code=uni.getStorageSync('code')
				
			    uni.showLoading({
			     	title: '加载中'
			    }); 
			  
			   this.$http('enterpriseWechat/auth/getAgentConfig', {
			     corpID:'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g',
				 url:'http://qw.66km.com.cn/'
			   }, 'GET').then(res => {
			   	   uni.hideLoading();
				   //console.log(this.$wx.agentConfig)
				   this.$wx.agentConfig({
				       corpid: 'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g', // 必填，企业微信的corpid，必须与当前登录的企业一致
				       agentid: '1000051', // 必填，企业微信的应用id （e.g. 1000247）
				       timestamp: res.data.timestamp, // 必填，生成签名的时间戳
				       nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
				       signature: res.data.signature,// 必填，签名，见附录-JS-SDK使用权限签名算法
				       jsApiList: ['getCurExternalContact'], //必填，传入需要使用的接口名称
				       success: function(res) {
						   console.log(res)
						   uni.showToast({
						   	title: 'agentConfig成功',
						   	icon: 'none',
						   	duration: 3000
						   });
				           // 回调
				       },
				       fail: function(res) {
						   console.log(res)
						   uni.showToast({
						   	title: 'agentConfig失败',
						   	icon: 'none',
						   	duration: 3000
						   });
				           if(res.errMsg.indexOf('function not exist') > -1){
				               alert('版本过低请升级')
				           }
				       }
				   });
			   	
			   }).catch(err=>{
				    uni.hideLoading();
			   })
		   },
           tabFn(num){
			   this.tabIndex=num
		   }
		}
	}
</script>

<style scoped>
	.top{
		background: #fff;
	}
	.top{
		display: flex;
		padding: 30rpx 24rpx;
	}
	.logo{
		width: 98rpx;height: 98rpx;
	}
	.topRight{
		padding-left: 20rpx;
	}
	.wxName{
		font-weight: 500;
		font-size: 32rpx;
		color: #333333;
		line-height: 45rpx;
	}
	.titleBox{
		display: flex;
		padding-top: 10rpx;
	}
	.title{
		height: 36rpx;
		border-radius: 4rpx;
		border: 1px solid #FF8113;
		line-height: 34rpx;
		font-size: 24rpx;
		color: #FF8113;
		padding: 0 8rpx;
		margin-right: 10rpx;
		
	}
	.tabBox{
		display: flex;justify-content: space-between;
		background: #fff;
		margin-top: 16rpx;
		padding: 30rpx 24rpx;
		font-size: 30rpx;
		color: #333333;
		line-height: 42rpx;
	}
	.tabActive{
		color: #FF8113;font-weight: 500;
		border-bottom: 2px solid #FF8113;
	}
	.tabline{
		padding-bottom: 8rpx;
	}
</style>
