<template>
	<view class="content safe-area-inset-bottom">
		<MessageNotification />
		<!-- 描述 -->
		<view class="card" v-for="item in list" :key="item.id" @click="toInfo(item.id)">
			<image :src="item.content['avatar']||'/static/mine/avatar_1.png'" mode=""></image>
			<view class="info">
				<view class="infos_title">
					<text class="infos">{{item.content['doctor']}}医生</text>
					<text class="time">{{item.notice_at}}</text>
				</view>
				<view class="preview">
					<view class="pre_">
						{{item.content['content']}}
					</view>
					<view class="text">查看详情</view>
				</view>
			</view>
		</view>
		
		<!-- 为空 -->
		<view class="empty">
			<u-empty text="暂无医生消息" mode="list" v-if="list.length==0"></u-empty>
		</view>
	</view>
</template>

<script>
	import {
		getDoctorNewsApi
	} from '../../request/api/systemNotice'
	export default {
		data() {
			return {
				list: [],
			}
		},
		onLoad() {

		},
		methods: {
			async goInfo() {
				try {
					const res = await getDoctorNewsApi({
						store_id: uni.getStorageSync('store_id') || 11001
					})
					if (res.data && res.data.result && res.data.result.items) {
						this.list = res.data.result.items
					}
				} catch (error) {
					console.error('获取医生消息失败:', error)
				}
			},
			toInfo(e) {
				uni.navigateTo({
					url: '/subPackages/doctor/doctor_newsinfo?id=' + e
				})
			}
		},
		mounted() {
			this.goInfo()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 750rpx;
		max-height: 100%;
		min-height: 100vh;
		padding-bottom: env(safe-area-inset-bottom);
		background: #F5F5F5;
		
		.empty {
			width: 100vw;
			max-height: 100vh;
			margin: 0 auto;
			padding: 300rpx 0;
		}

		.card {
			width: 100%;
			height: 136rpx;
			padding: 28rpx 40rpx;
			background: #FFFFFF;
			margin-top: 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			image {
				width: 80rpx;
				height: 80rpx;
				margin-right: 16rpx;
				vertical-align: middle;
				border-radius: 50%;
				background: #1777FF;
			}

			.info {
				width: 82%;

				.infos_title {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 8rpx;

					.infos {
						font-size: 28rpx;
						font-weight: bold;
						color: #232323;
						line-height: 42rpx;
					}

					.time {
						font-size: 22rpx;
						font-weight: 400;
						color: #999999;
					}
				}

				.preview {
					margin-top: 16rpx;
					display: flex;
					justify-content: space-between;
					font-size: 24rpx;
					font-weight: 400;
					color: #999999;

					.pre_ {
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						text-overflow: ellipsis;
						overflow: hidden;
					}

					.text {
						text-align: right;
						min-width: 160rpx;
						max-width: 200rpx;
						color: #1777FF;
					}
				}
			}
		}
	}
</style>