<template>
	<view class="content">
		 <view class="loadding" v-if="loadding==true">
		 	<image :src="imgPath+'/app/image/logo.png'"></image>
		 	<text class="text">{{name}}</text>
		 </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: null,
				outUserId: null,
				qwUserId: null,
				currentPath: null,
				baseUrl:uni.getStorageSync('requestPath')
			};
		},
		computed: {
			imgPath() {
			  return this.$store.state.imgpath
			},
			name() {
			  return this.$store.state.logoname
			},
		  },
		onShow() {
			// this.getUserId();
			this.navigatHandler();
		},
		methods: {
			navigatHandler() {
				// // #ifdef MP-WEIXIN
				// uni.reLaunch({
				// 	url: '/pages/auth/wxlogin',
				// })
				// // #endif
				// #ifdef MP-WEIXIN
				console.log('现在')
				if(uni.getStorageSync('AppToken')){
					uni.reLaunch({
						url: '/pages/index/index',
					})
				}else{
					uni.reLaunch({
						url: '/pages/enterprise/enterprise',
					})
				}
				
				// #endif
				// #ifdef H5
				if (!this.utils.isLogin()) {
					// #ifdef H5
					uni.reLaunch({
						url: '/pages/auth/login',
					})
					// #endif
					
				} else {
					// #ifdef H5
					uni.reLaunch({
						url: '/pages/index/index',
					})
					// #endif
				}
				// #endif
			},
			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 lang="scss">
	page{
		background-color: #fff;
	}
	.content {
		background-color: #fff;
		height: 100%;
		width: 100%;
		position: relative;
	}
	.loadding{
		background-color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 9999;
		image{
			border-radius: 50%;
			animation: load linear 1s infinite;
			width: 120rpx;
			height:120rpx;
		}
		.text{
			font-size: 28rpx;
			margin-top: 20rpx;
		}
	}
</style>
