<template>
	<view>
		<uni-notice-bar @click="toLogin" v-if="!isLogin" single showIcon text="当前未登录，如需提交问题请点击此处登录~">
		</uni-notice-bar>
		<view class="mainBox">
			<view class="contentBox">
				<image src="../../static/image/logo.png" class="logo"></image>
				<view class="logoText">
					快报嗨享平台
				</view>
				<view class="logoTextNext">
					一个好看有用的平台
				</view>
				<view class="btnBox">
					<view class="btn" v-if="isAuth" @click="toManage()">后台管理</view>
					<view class="btn" @click="toSquare()">快报帮</view>
					<view class="btn" v-if="isLive" @click="tolive()">打开直播</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapState
	} from 'vuex';
	import {
		findUserAuth
	} from '../../network/api'
	export default {
		data() {
			return {
				isAuth: false,
				isLogin: false,
				isLive: false,
				liveId: "sph2Kn7SwRTPGaO"
			};
		},
		mounted() {
			const _this = this;
			uni.getChannelsLiveInfo({
				finderUserName: _this.liveId,
				success: e => {
					_this.isLive = e.status === 2
				}
			})
		},
		computed: {
			...mapState(['userInfo'])
		},
		onShow() {
			let user = null;
			try {
				user = JSON.parse(uni.getStorageSync('userInfo'));
			} catch (e) {
				//TODO handle the exception
			}
			if (!user) return
			this.isLogin = true
			this.setUserInfo(user);
			this.findAuth()
		},
		methods: {
			...mapMutations(['setUserInfo']),
			async findAuth() {
				let params = {
					'mobile': this.userInfo.phone,
					'departmentId': 1
				}
				let res = await findUserAuth(params)
				console.log(res);
				if (res.data === true) this.isAuth = true
				// if(res.state == 200) {
				// 	this.isAuth = res.data
				// }
			},
			toLogin() {
				uni.navigateTo({
					url: '/pages/Login/Login?choose=1'
				});
			},
			toManage() {
				uni.navigateTo({
					url: `/pages/managePage/managePage?phone=${this.userInfo.phone}`
				});
			},
			tolive() {
				uni.openChannelsLive({
					finderUserName: this.liveId,
					success() {
						console.log("success")
					},
					fail() {
						uni.showToast({
							title: '已取消跳转视频号',
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},

			toSquare() {
				uni.navigateTo({
					url: '/pages/newsSquare/newsSquare'
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.mainBox {
		box-sizing: border-box;
		width: 100%;
		height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;

		.contentBox {
			width: 526rpx;
			// height: 770rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.logo {
				width: 150px;
				height: 150px;
			}

			.logoText {
				margin-top: 30px;
				font-size: 18px;
			}

			.logoTextNext {
				margin-top: 15px;
				font-size: 20px;
			}

			.btnBox {
				margin-top: auto;

				.btn {
					width: 526rpx;
					height: 44px;
					line-height: 40px;
					background-color: #007aff;
					color: #ffffff;
					text-align: center;
					margin-top: 72rpx;
					border-radius: 30px;
				}
			}
		}
	}
</style>
