<template>
	<view class="message-index">
		<view class="message-item" @click="$navigateTo('/pages/messageList/messageList?type=2')">
			<uni-badge class="uni-badge-left-margin" :text="testCount[2]" absolute="rightTop" size="small">
				<view class="message-icon">
					<uni-icons type="email" size="30" color="#fff"></uni-icons>
				</view>
			</uni-badge>
			<view class="message-content">
				<view class="message-title">
					项目邀请通知
				</view>
				<view class="message-sub-label">
					{{!testCount[2] ?'暂无消息通知' : `您有${testCount[2]}条未读消息，请查看～`}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMessageTest
	} from '@/request/api/message.js'
	export default {
		data() {
			return {
				testCount: {}
			}
		},
		onShow() {
			this.init();
		},
		methods: {
			init() {
				getMessageTest(this.$store.getters.user.userId || 3).then(res => {
					if (res.code == 200) {
						let obj = {};
						for (var i = 0; i < res.data.length; i++) {
							obj[res.data[i].messageType] = res.data[i].count;
						}
						this.testCount = obj;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.message-index {
		padding-top: 20rpx;

		.message-item {
			display: flex;
			align-items: center;
			padding: 20rpx 30rpx;
			background: $uni-white;
		}

		.message-icon {
			background: #55bc9c;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100rpx;
			height: 100rpx;
			border-radius: 20rpx;
		}

		.message-content {
			margin-left: 20rpx;
		}

		.message-title {
			font-size: 32rpx;
			font-weight: 500;
		}

		.message-sub-label {
			color: $uni-extra-color;
			font-size: 24rpx;
			margin-top: 10rpx;
		}
	}
</style>