<template>
	<view>
		<view class="header">
			<view>{{ memberName }}</view>
			<text class="warning">计划阅读：{{ option.ExecDate }}前</text>
			<text class="warning" wx:if="{{option.IsRead}}">实际阅读：{{ option.ReadTime }}</text>
		</view>
		<view class="body">
			<view class="title">注意事项</view>
			<rich-text>
				{{ pushContent }}
			</rich-text>
		</view>
	</view>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue';
import Props from './props';
import { PatientRead } from '../../../service';

const props = defineProps(Props);

const list = ref([]);
const option = ref({} as any);
const isAllRead = ref(1);
const pushContent = ref('');

const init = async (datas) => {
	if (datas && !datas.length) return;
	pushContent.value = datas[0].PushContent;
	option.value = datas[0];
	let readRes = datas[0].IsRead;
	if (!readRes) {
		const resp = await PatientRead({
			Id: datas[0].Id,
		});
		readRes = !!resp;
		const pages = getCurrentPages();
		const homePage = pages.find((p: any) => p && p.route && p.route.indexOf('pagesCrm/business/home/home') !== -1);
		const target: any = homePage || (pages.length >= 2 ? pages[pages.length - 2] : undefined);
		const vm = target && (target as any).$vm;
		if (vm && typeof vm.changeItemReadStatus === 'function') {
			vm.changeItemReadStatus(props.date, props.index, 1);
		} else {
			uni.$emit('changeItemReadStatus', { date: props.date, index: props.index, status: 1 });
		}
	}
};

watch(
	() => props.content,
	(v) => {
		init(v);
	},
	{
		immediate: true,
		deep: true,
	}
);
</script>

<style lang="scss" scoped>
@import './common.scss';

.title {
	font-family: PingFang-SC, PingFang-SC;
	font-weight: bold;
	font-size: 36rpx;
	text-align: center;
	padding: 42rpx 0;
}
</style>
