<template>
	<view>
		<div>
			跳转中...
		</div>
		<!-- <div>
			token: {{ this.$store.state.app.token }}
		</div>
		<div>
			userinfo: {{ this.$store.state.userinfo }}
		</div> -->
	</view>
</template>

<script>
	import { _API_GetUserStatus } from '@/apis/user.js'
	export default {
		data() {
			return {
				
			}
		},
		onLoad(option) {
			const token = this.$store.state.app.token
			const userinfo = this.$store.state.userinfo
			if (option == 'dwbsChat') { // 从登录页进入
				_API_GetUserStatus().then(res => {
					if (res.code === 200) {
						if (res.data.user_type == 1) {
							const that = this
							uni.showModal({
								content: '抱歉，您没有权限进入系统',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {
										that.$store.commit('app/LOGOUT')
										that.toWxchatLogin(`/pages/login-reg/login-reg`, null)
									}
								}
							})
							return
						}
						window.location.href = `http://s-chat.cliu.cc?phone=${res.data.mobile}`
						// window.location.href = `http://s-chat.cliu.cc?phone=${res.data.mobile}&&openid=${res.data.openid}&&nickname=${res.data.nickname}&&tx=${res.data.headimgurl}`
					} else {
						uni.showModal({
							content: '获取信息失败',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									uni.reLaunch({
										url: '../index/index'
									})
								}
							}
						})
					}
				})
			}
			if (token && userinfo) {
				window.location.href = `http://s-chat.cliu.cc?phone=${userinfo.mobile}`
			} else {
				this.toWxchatLogin(`/pages/login-reg/login-reg?type=dwbsChat`, null)
			}
			
		},
		methods: {
			// 跳转微信登录
			toWxchatLogin(url, state) {
				url = url || '/pages/index/index';
				state = state || 'cli';
				const redirect_uri = encodeURIComponent(`${this.$config.redirect_uri}/api/gzh#${url}`);
				const auth = () =>
					(window.location.href = `${this.$config.wxURL}?appid=${
					this.$config.appid
				}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`);
				auth();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.course {
		width: 100%;
		margin: 0 auto;
		min-height: 100%;
		background: #fff;
	}

	.card {
		width: 702rpx;
		margin: 30rpx auto 0;

		.card_item {
			width: 340rpx;
			height: 168rpx;
			background: url(../../static/course/bg1.png) no-repeat;
			background-size: 100% 100%;

			view {
				font-size: 34rpx;
				color: #fff;
				margin-left: 16rpx;
				margin-top: -10rpx;
			}
		}

		.card_item:last-child {
			background: url(../../static/course/bg2.png) no-repeat;
			background-size: 100% 100%;
		}

	}

	.list {
		width: 702rpx;
		margin: 0 auto;

		.title {
			border-bottom: 2rpx solid #EEEEEE;
			padding: 30rpx 0;

			view {
				font-size: 36rpx;
				font-weight: bold;
			}

			text {
				font-size: 32rpx;
			}
		}

		.list_con {
			height: 106rpx;
			border-bottom: 2rpx solid #eeeeee;

			.chat-icon {
				color: #FB231F;
				margin-left: 28rpx;
			}

			.name {
				font-size: 36rpx;
				font-weight: bold;
			}
		}
	}
</style>
