<template>
	<view class="page">
		<view v-for="(item,index) in listData" :key="index">
			<view class="itemBox" @click="jumpPage(item.key)">
				<view class="avatarBox">
					<image class="imgicon" :src="item.imgurl" mode="widthFix"></image>
					<u-badge size="mini" class="badge" :absolute="false"  :count="item.Num"></u-badge>
				</view>
				
				<view class="infoBox">
					<view class="infoTop">
						<view class="infoName">
							{{item.Title}}
						</view>
						<view class="infoDate">
							{{item.Time}}
						</view>
					</view>
					<view class="infoTipMsg" v-if="item.Description">
						{{item.Description}}
					</view>
					<view class="infoTipMsg" v-if="!item.Description">
						暂无新消息
					</view>
				</view>
			</view>
		</view>
		 <auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth>
	</view>
</template>

<script>
	import auth from "@/components/auth/index.vue";
	export default {
		components: {
		  auth
		},
		data() {
			return {
				pageTitle: "消息",
				listData: [],
				showAuth:false,
				u:{},
			}
		},
		methods: {
			jumpPage(key){
				let url="";
				if(key=="CircleModel"){
					url="/pages/blindDate/circleNews?pageType=1"
				}else if(key=="SystemModel"){
					url="/pages/blindDate/systemMsg"
				}else if(key=="PPPlusModel"){
					url="/pages/blindDate/circleNews?pageType=2"
				}else if(key=="VisitorModel"){
					url="/pages/blindDate/visitor"
				}
				uni.navigateTo({
					url:url
				})
			},
			getMiaiMessageCenter(){
				console.log('进入更新')
				this.request2(
				  	{
				  		url: '/api/AppletMiai/GetMiaiMessageCenter',
				  		data:{} 
				  	},
				  	res => {
						if(res.resultCode==1){
							this.listData=[]
							for(let key in res.data ){
								if(key=="CircleModel"){
									res.data.CircleModel.imgurl="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Blind-quan.png"
									res.data.CircleModel.key="CircleModel"
								}else if(key=="PPPlusModel"){
									res.data.PPPlusModel.imgurl="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Blind-xitong.png"
									res.data.PPPlusModel.key="PPPlusModel"
								}else if(key=="SystemModel"){
									res.data.SystemModel.imgurl="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Blind-ppplus.png"
									res.data.SystemModel.key="SystemModel"
								}else if(key=="VisitorModel"){
									res.data.VisitorModel.imgurl="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Blind-fangke.png"
									res.data.VisitorModel.key="VisitorModel"
								}
								this.listData.push(res.data[key])
							}
							console.log(this.listData)
						}
				  	}
				  );
			},
			reloadUserinfo() {
			  this.u = uni.getStorageSync("mall_UserInfo");
			  // this.showAuth=false;
			  this.getMiaiMessageCenter();
			},
			//关闭登录窗口
			gbAuth(){
				uni.navigateBack()
			},
		},
		onShow() {
			this.u = uni.getStorageSync("mall_UserInfo");
			if (!this.u) {
			  this.u = {
				nickName: "未登录",
				avatarUrl: ""
			  };
			  this.showAuth = true;
			}	else{
				this.getMiaiMessageCenter();
			}
			
		},
		mounted() {
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 0 30rpx;
	}

	.itemBox {
		width: 100%;
		height: 148rpx;
		display: flex;
		align-items: center;
		.avatarBox{
			position: relative;
			width: 88rpx;
			height: 88rpx;
			.imgicon{
				width: 88rpx;
				height: 88rpx;
			}
			/deep/.badge{
				position: absolute;
				top: 0rpx;
				right: 0rpx;
			}
		}
	}
	
	.infoBox{
		height: 148rpx;
		margin-left: 27rpx;
		flex-grow: 5;
		border-bottom: 1rpx solid #E2E2E2;
		padding-top: 40rpx;
		.infoTop{
			width: 100%;
			// height: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			// margin-bottom: 15rpx;
			.infoName{
				font-size: 30rpx;
				font-weight: bold;
				color: #000000;
				
			}
			.infoDate{
				font-size: 24rpx;
				// font-weight: 500;
				color: #999999;
			}
		}
		.infoTipMsg{
			font-size: 24rpx;
			font-weight: 500;
			color: #999999;
		}
	}
	
	
	
</style>
