<template>
	<view class="container">
		<view class="search-box">
			<u-search
				v-model="searchForm.keyword"
				:clearabled="true"
				bg-color="#E5E5E5"
				:input-style="searchInputStyle"
				placeholder="请输入搜索内容"
			></u-search>
		</view>
		<view class="list-box">
			<view class="list-item-box" v-for="item in list" :key="item.id" @click="onChatClick(item)">
				<view class="main-box">
					<view class="icon-box">
						<cover-image class="icon" :src="`/static/chat-icon/${item.type}.png`"></cover-image>
						<view class="tag" v-show="item.isRead"></view>
					</view>
					<view class="content-box">
						<view class="title">
							{{item.title}}
						</view>
						<view class="text">
							{{item.content}}
						</view>
					</view>
					<view class="other-box">
						<view class="date">
							{{item.time}}
						</view>
					</view>
				</view>
				<view class="line-box"></view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	
	const uToast = ref()
	
	const searchInputStyle = {
		backgroundColor: '#E5E5E5'
	}
	const searchForm = ref({
		keyword: ''
	})
	const list = ref([
		{
			id: '1',
			title: '会费缴交成功通知',
			content: '尊敬的用户,您在2023年8月16日15:00成交缴交会费……',
			type: 'zhifu',
			time: '8/16',
			isRead: true
		},
		{
			id: '2',
			title: '继续教育通知',
			content: '尊敬的用户,您预约2023年8月16日《广州市存量房网……',
			type: 'jiaoyu',
			time: '8/16',
			isRead: true
		},
		{
			id: '3',
			title: '课程购买成功通知',
			content: '尊敬的用户,您在成功购买2023年8月16日《广州市存……',
			type: 'goumai',
			time: '8/16',
			isRead: true
		},
		{
			id: '4',
			title: '个人会员生日祝福',
			content: '尊敬的用户,今日是您的生日,协会祝你在……',
			type: 'shengri',
			time: '8/16',
			isRead: false
		}
	])
	function onChatClick(chat) {
		uni.navigateTo({
			url: `/pages/chatDetail/chatDetail?id=${chat.id}&title=${chat.title}`
		})
	}
	onLoad(() => {
		uni.setTabBarBadge({ //显示数字  
			index: 1, //tabbar下标
			text: '999' //数字
		})
	})
</script>

<style lang="scss" scoped>
	.container {
		height: 100vh;
		width: 100vw;
		background-color: $uni-bg-color;
		padding: 0 20rpx;
		
		.search-box {
			margin-bottom: 20rpx;
			::v-deep(.u-search) {
				background-color: #e5e5e5;
				border-radius: 50rpx;
				
				.u-action {
					width: 18%;
					background-color: $uni-color-primary;
					border-radius: 50rpx;
					color: $uni-text-color-inverse;
					margin-right: 8rpx;
					font-size: 28rpx;
					line-height: 50rpx;
					letter-spacing: 3rpx;
					text-align: center;
				}
			}
		}
	
		.list-box {
			padding: 0 20rpx;
			.list-item-box {
				.main-box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 30rpx 0;
					
					&:active {
						background-color: $uni-bg-color-hover;
					}
					.icon-box {
						width: 15%;
						display: flex;
						justify-content: center;
						align-items: center;
						position: relative;
						.icon {
							width: 70rpx;
							height: 70rpx;
						}
						.tag {
							position: absolute;
							right: 5rpx;
							top: -3rpx;
							width: 15rpx;
							height: 15rpx;
							background-color: $uni-color-error;
							border-radius: 50%;
						}
					}
					.content-box {
						width: 67%;
						display: flex;
						flex-direction: column;
						justify-content: space-around;
						gap: 10rpx;
						.title {
							height: calc(70% - 5rpx);
							font-size: $uni-title-font-size-2;
							font-weight: bold;
						}
						.text {
							height: calc(30% - 5rpx);
							font-size: $uni-font-size-3;
							color: $uni-text-color-grey;
							@include text-overflow();
						}
					}
					.other-box {
						width: 18%;
						display: flex;
						flex-direction: column;
						justify-content: space-around;
						align-items: center;
						gap: 10rpx;
						.date {
							font-size: $uni-font-size-3;
							color: $uni-text-color-grey;
						}
					}
				}
				.line-box {
					height: 1rpx;
					width: 80%;
					background-color: #E5E5E5;
					margin: 0 auto;
				}
			}
		}
	}
		
	
</style>