<template>
	<view class="page">
		<view v-if="msg" class="card">
			<!-- 顶部：图标 + 标题 + 标签 -->
			<view class="header-row">
				<text class="header-icon">📢</text>
				<text class="header-title">审核通知</text>
				<view class="tag" :class="msg.type === 1 ? 'tag-success' : 'tag-fail'">
					{{ msg.type === 1 ? '已通过' : '已驳回' }}
				</view>
			</view>

			<!-- 大标题 -->
			<view class="main-title">{{ msg.type === 1 ? '您提交的资料已通过审核' : '您提交的资料未通过审核' }}</view>
			<view class="time">{{ msg.create_time }}</view>

			<!-- 正文 -->
			<view class="body">
				<text class="greeting">尊敬的{{ msg.patient_name || '' }}：</text>
				<text class="body-text" v-if="msg.type === 1">您提交的个人资料经审核已通过。</text>
				<text class="body-text" v-else>您于 {{ formatDate(msg.create_time) }} 提交的个人资料经审核未通过。</text>
				<text class="body-text" v-if="msg.type === 2">请根据以下原因修改后重新提交。</text>
			</view>

			<!-- 驳回原因 -->
			<view v-if="msg.type === 2 && msg.reason" class="reason-box">
				<text class="reason-label">驳回原因：</text>
				<text class="reason-text">{{ msg.reason }}</text>
			</view>

			<!-- 操作按钮 -->
			<view v-if="msg.type === 2" class="btn-area">
				<u-button text="重新提交资料" @click="goMyInfo" color="#0E63E3" size="large" />
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { get } from '@/utils/request.js'

const msg = ref(null)

onLoad(async (options) => {
	if (!options.id) return
	try {
		const res = await get('/api/mp/messageDetail', { id: options.id })
		msg.value = res.data
	} catch (e) {
		if (e && e.msg) uni.showToast({ title: e.msg, icon: 'none' })
	}
})

const formatDate = (dateStr) => {
	if (!dateStr) return ''
	const d = new Date(dateStr)
	return `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日`
}

const goMyInfo = () => {
	uni.navigateTo({ url: '/pages/myinfo/myinfo' })
}
</script>

<style lang="scss" scoped>
.page {
	min-height: 100vh;
	background: #f4f4f5;
	padding: 24rpx;
}

.card {
	background: #fff;
	border-radius: 10rpx;
	padding: 36rpx 32rpx;
	border: 1rpx solid #ebeef5;
}

.header-row {
	display: flex;
	align-items: center;
	gap: 12rpx;
	margin-bottom: 28rpx;
}

.header-icon {
	font-size: 32rpx;
}

.header-title {
	font-size: 30rpx;
	font-weight: 600;
	color: #333;
}

.tag {
	font-size: 22rpx;
	padding: 4rpx 16rpx;
	border-radius: 6rpx;

	&.tag-success {
		background: #f6ffed;
		color: #52c41a;
		border: 1rpx solid #b7eb8f;
	}

	&.tag-fail {
		background: #fff2f0;
		color: #f5222d;
		border: 1rpx solid #ffa39e;
	}
}

.main-title {
	font-size: 36rpx;
	font-weight: 700;
	color: #222;
	line-height: 1.4;
}

.time {
	font-size: 26rpx;
	color: #999;
	margin-top: 12rpx;
	margin-bottom: 36rpx;
}

.body {
	display: flex;
	flex-direction: column;
	gap: 20rpx;
}

.greeting {
	font-size: 30rpx;
	color: #333;
}

.body-text {
	font-size: 30rpx;
	color: #333;
	line-height: 1.7;
}

.reason-box {
	margin-top: 36rpx;
	background: #f0f5ff;
	border-left: 6rpx solid #0e63e3;
	border-radius: 8rpx;
	padding: 28rpx 24rpx;
}

.reason-label {
	font-size: 28rpx;
	font-weight: 600;
	color: #f5222d;
	display: block;
	margin-bottom: 12rpx;
}

.reason-text {
	font-size: 28rpx;
	color: #555;
	line-height: 1.7;
}

.btn-area {
	margin-top: 48rpx;
}
</style>
