<template>
	<view class="popupBox ">
		<view class="es-bc-white popupBox-content" v-if="userList.length>0">
			<view class="u-f es-mt-20 popupBox-content-list" v-for="(item,index) in userList" :key="index"
				@tap="loginByUserIdFun(item)">
				<view class="es-mr-20">
					<image class="es-icon-90 es-br-ban" :src="item.avatar" mode=""></image>
				</view>
				<view class="es-fs-40 es-fw x-c">
					{{item.nickName}}
				</view>
			</view>
		</view>
		<view v-else>
			<u-empty></u-empty>
		</view>
	</view>
</template>

<script>
	import {
		loginByUserId
	} from '@/api/user'
	export default {
		data() {
			return {
				userList: []
			}
		},
		mounted() {
			this.getRegistrationID()
			const wechatList = uni.getStorageSync('wechatList')
			if (wechatList) {
				this.userList = wechatList
				uni.removeStorageSync('wechatList')
			}
		},
		methods: {
			getRegistrationID() {
				let registrationID = uni.getStorageSync("registrationID");
				if (!registrationID) {
					uni.getPushClientId({
						success: res => {
							uni.setStorageSync("registrationID", res.cid);
						}
					});
				}
			},
			async loginByUserIdFun(e) {
				const requestParam = uni.getStorageSync('requestParam')
				uni.removeStorageSync('requestParam')
				let params = {
					...requestParam,
					userId: e.userId,
					jpushId: uni.getStorageSync("registrationID")
				}
				const res = await loginByUserId(params)
				if (res.code == 200) {
					uni.setStorageSync('AppToken', res.token);
					uni.setStorageSync('userInfo', JSON.stringify(res.user));
					uni.$emit('refreshIM');
					uni.$emit('showHealthButler');
					this.goPage();
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			},
			goPage() {
				let pages = getCurrentPages();
				let url = pages[pages.length - 1];
				let openUrl = uni.getStorageSync("openUrl");
				if (openUrl) {
					uni.navigateTo({
						url: openUrl,
						success: function(res) {
							uni.removeStorageSync("openUrl")
						}
					})
				} else {
					this.$updateMsgDot();
					this.$setSource();
					uni.reLaunch({
						// url: '../course/index',
						url: '/pages_im/pages/conversation/conversationList/index',
						animationType: 'none',
						animationDuration: 2000
					});
					return;
					if (pages.length == 1) {
						uni.reLaunch({
							// url: '../course/index',
							url: '/pages_im/pages/conversation/conversationList/index',
							//url: '../course/video/living-app',
							animationType: 'none',
							animationDuration: 2000
						});
					} else {
						//this.$navBack();
					}
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.popupBox {
		padding: 48rpx 24rpx;
		padding-top: 0rpx;
		margin-top: 24rpx;
		width: 100vw;
		box-sizing: border-box;
		flex-direction: column;

		.popupBox-content {
			padding: 24rpx;
			padding-bottom: 0;
			border-radius: 16rpx;

			.popupBox-content-list {
				padding-bottom: 24rpx;
				border-bottom: 1rpx solid #F7F8FA;

				&:last-child {
					border-bottom: none;
				}
			}
		}
	}
</style>