<template>
	<view class="content">
		 
	</view>
</template>

<script>
	import { getConfigSignature } from '@/api/qw.js'
	export default {
		data() {
			return {
				loading: null,
				outUserId: null,
				qwUserId: null,
				currentPath: null,
				baseUrl:uni.getStorageSync('requestPath')
				
			};
		},
		onShow() {
			// this.getUserId();
			this.navigatHandler();
		},
		methods: {
			navigatHandler() {
				if (!this.utils.isLogin()) {
					uni.reLaunch({
						url: '../auth/login',
					})
				} else {
					uni.reLaunch({
						url: '../user/index',
					})
				}
			},
			getUserId() {
				const urlParams = new URLSearchParams(window.location.search);
				const currentUrl = window.location.href.split('#')[0];
				const companyId = urlParams.get('companyId');
				const code = urlParams.get('code');
				var data={
					companyId: companyId,
					url: currentUrl,
					code: code
				}
				getConfigSignature(data).then(
					res => {
						uni.hideLoading()
						if(res.code==200){
							const agentConfigSignature = res.config.agentConfigSignature;
							const configSignature = res.config.configSignature;
							const corpId = res.config.corpId;
							const nonceStr = res.config.nonceStr;
							const timestamp = res.config.timestamp;
							const agentId = res.config.agentId;
							this.qwUserId = res.config.userid;
							wx.config({
								beta: true,
								debug: false,
								appId: corpId,
								timestamp: timestamp,
								nonceStr: nonceStr,
								signature: configSignature,
								jsApiList: ['getCurExternalContact']
							});
							wx.ready(() => {
								wx.agentConfig({
									corpid: corpId,
									agentid: agentId,
									timestamp: timestamp,
									nonceStr: nonceStr,
									signature: agentConfigSignature,
									jsApiList: ['getCurExternalContact'],
									success: (res) => {
										wx.invoke('getCurExternalContact', {}, async (res) => {
											if (res.err_msg === "getCurExternalContact:ok") {
												this.outUserId = res.userId;
												uni.showToast({
													title: res.userId,
													icon: 'none'
												})
											} else {
												// 错误处理
											}
										});
									},
									fail: (res) => {
										console.error('agentConfig fail:', res);
									}
								});
							});
							wx.error((res) => {
								console.error('wx.error:', res);
							});
						}
						else{
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
						
					},
					rej => {}
				);
				 
			}
		}
 
	};
 
</script>
<style>
	page{
		background-color: #fff;
	}
	.content {
		background-color: #fff;
		height: 100%;
		width: 100%;
		position: relative;
	}
</style>
