<template>
	<view>
		<view class="lf-row-center lf-flex-column head" v-if="$isRight(canteen)">
			<image :src="canteen.avatar" v-if="canteen.avatar"></image>
			<image src="../../static/images/default_avatar.png" v-else></image>
			<view class="lf-m-t-20 lf-font-32 lf-font-bold lf-color-black">{{ canteen.name }}</view>
			<view class="lf-font-28 lf-color-555 lf-m-t-10">{{ canteen.role }}</view>
		</view>
		<view class="list">
			<view class="lf-row-between list-item" hover-class="lf-opacity" v-for="(item, index) in block_list"
				:key="index" @click="$url(item.path)">
				<view class="lf-row-center">
					<image class="icon-img" :src="item.icon"></image>
					<text class="lf-text-vertical lf-m-l-20 lf-font-28 lf-color-black">{{ item.name }}</text>
				</view>
				<view class="lf-flex">
					<view v-if="item.unread">
						<view class="message-tag" v-if="item.unread < 99">{{item.unread}}</view>
						<view class="message-tag" v-else>99+</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<view style="height: 170rpx;"></view>
		<view class="btn-bottom exit" v-if="$isRight(canteen)">
			<button class="lf-w-100" @click="loginOut">退出登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				canteen: {},
				block_list: []
			}
		},
		onShow() {
			// todo 优化：显示订单角标
			this.getHomeData();
		},
		onReady() {
			// #ifndef MP
			var a = document.getElementsByClassName('uni-page-head-hd')[0];
			a.style.display = 'none';
			// #endif
		},
		methods: {
			getHomeData() {
				this.$http(this.API.API_CANTEEN_INDEX).then(res => {
					console.log("getHomeData", res);
					this.block_list = res.data.block;
					this.canteen = res.data.canteen;
					uni.setNavigationBarTitle({
						title: this.canteen.user.canteen.canteen_name
					})
				})
			},
			// 退出登录
			loginOut() {
				uni.showModal({
					title: '温馨提示',
					content: '确定退出登录吗？',
					confirmColor: '#11D189',
					success: result => {
						if (result.confirm) {
							uni.removeStorageSync('canteen_token');
							this.$redirectToLogin('您已退出登录, 即将跳转...');
						}
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F6F6F6;
	}
</style>
<style lang="scss" scoped="scoped">
	.message-tag {
		width: 60rpx;
		height: 40rpx;
		font-size: 28rpx;
		background-color: red;
		border-radius: 20rpx;
		margin-right: 10rpx;
		text-align: center;
		align-items: center;
		color: white;
		display: flex;
		justify-content: space-around;
	}

	.head {
		height: 374rpx;
		width: 750rpx;
		background-color: #FFFFFF;

		image {
			width: 200rpx;
			height: 200rpx;
			border: 2rpx solid #FFFFFF;
			border-radius: 50%;
		}
	}

	.list {
		margin-top: 20rpx;
		padding: 0 32rpx;
		background-color: #FFFFFF;
		width: 100%;
		height: auto;
	}

	.list-item {
		border-bottom: 1rpx solid #EEEEEE;
		height: 110rpx;
		box-sizing: border-box;
		position: relative;

		.icon-img {
			width: 50rpx;
			height: 50rpx;
		}

		.feedback-btn {
			position: absolute;
			width: 100%;
			height: 100%;
			z-index: 1;
			background: transparent;
		}

		&:last-child {
			border-bottom: none;
		}
	}

	.exit {
		padding: 0 32rpx;
		// bottom: 50rpx; 
		padding-top: 10rpx;
		padding-bottom: 50rpx;
		box-sizing: border-box;
		background-color: #F6F6F6;

		button {
			background-color: #f0f0f0;
			color: #777777;
		}
	}
</style>
