<template>
	<view class="im">
		<commons-header></commons-header>
		<view style="margin-top:128rpx" @click="bindConfirmInvite">
			<view class="company-list">
				<view class="company-title"><span>新美特</span></view>
				<view class="list-box">
					<view class="user-img">
						张
					</view>
					<view class="user-text">
						<p>张三</p>
						<span>总经理</span>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import commonsHeader from '../../components/commons-header/index.vue'
	import { setTokenStorage } from '../../utils/token';
	import logger from '../../utils/logger';
	import { genTestUserSig } from '../../debug/GenerateTestUserSig.js';
	const { getTokenStorage } = require('../../utils/token.js');
	const app = getApp();
	export default {
		components:{
			commonsHeader
		},
		data() {
			return {
				userID: '',
				hidden: false,
				btnValue: '获取验证码',
				btnDisabled: false,
				privateAgree: false,
				phone: '',
				code: '',
				sessionID: '',
				second: 60,
				path: '',
				lastTime: 0,
				countryIndicatorStatus: false,
				country: '86',
				indicatorValue: 46,
				headerHeight: app.globalData.headerHeight,
				statusBarHeight: app.globalData.statusBarHeight,
				showlogin: false
			}
		},
		onLoad(option) {
			const v = this
			this.setData({
				path: option.path
			});
			uni.getStorage({
				// 获取本地缓存
				key: 'sessionID',
				success(res) {
					that.setData({
						sessionID: res.data
					});
				}
			});
			uni.setStorage({
				key: 'path',
				data: option.path
			});
			setTimeout(()=>{
				v.imInit()
			},5000)
		},
		methods: {
			
			bindConfirmInvite() {
				uni.$TUIKit
					.getUserProfile({
						userIDList: ['111']
					})
					.then(imRes => {
						if (imRes.data.length > 0) {
							console.log(imRes.data[0].userID)
							uni.navigateTo({
								url: `../TUI-Chat/chat?conversationID=C2C${imRes.data[0].userID}`
							});
						} else {
							uni.showToast({
								title: '用户不存在',
								icon: 'error'
							});
							this.setData({
								userID: ''
							});
						}
					});
			},
			imInit(){
				const userID = '111';
				const userSig = genTestUserSig(userID).userSig;
				const SDKAppID = app.globalData.SDKAppID;
				
				
				
				app.globalData.userInfo = {
					userSig,
					userID
				};
				setTokenStorage({
					userInfo: app.globalData.userInfo
				});
				wx.setStorageSync(`TIM_${getApp().SDKAppID}_isTUIKit`, true);
				uni.$TUIKit.login({
					userID: userID,
					userSig: userSig
				}).then(() => {
					
				}).catch((error) => {
					
				})
				console.log(SDKAppID,userID,userSig)
				uni.$TUICalling.login(
					{
						sdkAppID: SDKAppID,
						userID: userID,
						userSig: userSig
					},
					res => {
						console.log(JSON.stringify(res.msg));
						// uni.showToast({
						// 	title: 'login',
						// 	icon: 'none'
						// });
						// uni.navigateTo({
						// 	url: '../TUI-Index/index'
						// });
					}
				);
				// 登录原生插件
				// #ifdef APP-PLUS
				// if(typeof(uni.$TUICalling) == 'undefined') {
				// 	uni.showToast({
				// 		title: '如果需要音视频功能，请集成插件使用真机运行并且自定义基座调试哦～',
				// 		icon: 'none',
				// 		duration: 3000
				// 	});
				// 	logger.error('请使用真机运行并且自定义基座调试，否则影响音视频功能～ 插件地址：https://ext.dcloud.net.cn/plugin?id=7097 , 调试地址：https://nativesupport.dcloud.net.cn/NativePlugin/use/use');
				// } else {
					
				// }
				
				// #endif
				if (this.path && this.path !== 'undefined') {
					uni.redirectTo({
						url: this.path
					});
				} else {
					
				}
			},
			
		},
	}
</script>

<style lang="less">
	.im{
		background-color: #f1f1f1;
		min-height: calc(100vh - 128rpx);
		.company-title{
			height: 100rpx;
			line-height: 100rpx;
			color: #333;
			font-size: 28rpx;
			position: relative;
			padding: 0 47rpx;
			background-color: #fff;
			border-bottom: 1rpx solid #ddd;
		}
		.company-title::before{
			content:' ';
			position: absolute;
			width: 8rpx;
			height: 32rpx;
			top: 35rpx;
			left: 24rpx;
			background-color: #3370FF;
			
		}
		.list-box{
			background-color: #fff;
			height: 160rpx;
			padding: 40rpx 24rpx;
			display: flex;
			box-sizing: border-box;
			.user-img{
				height: 80rpx;
				width: 80rpx;
				background-color: #3370FF;
				border-radius: 10rpx;
				color: #fff;
				text-align: center;
				line-height: 80rpx;
			}
			.user-text{
				margin-left: 24rpx;
				line-height: 40rpx;
				p{
					color: #333;
					font-size: 28rpx;
				}
				span{
					color: #999;
					font-size: 24rpx;
				}
			}
		}
	}
</style>