<template>
	<view class="visit-note-page">
		<uni-nav-bar
			left-icon="left"
			title="添加随访计划"
			@clickLeft="goBack"
			fixed
			color="#8B2316"
			height="140rpx"
			:border="false"
			backgroundColor="#eee"
		>
			<template #right>
				<view class="nav-right" @click="submit" v-if="!followUpUuid">
					<text class="submit-text">添加</text>
				</view>
			</template>
		</uni-nav-bar>

		<!-- 患者行 -->
		<view class="row" @click="noop">
			<text class="row-label">患者</text>
			<text class="row-value">{{ patientName }}</text>
		</view>

		<!-- 标题栏 -->
		<view class="section-title">随访内容</view>

		<!-- 输入框区域 -->
		<view class="note-box">
			<textarea class="note-textarea" v-model.trim="note" placeholder="请填写随访内容" auto-height :maxlength="200" />
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'

	const patientName = ref('')
	const note = ref('请近日来医院复诊、复查')
	const idx = ref(0)
	onLoad((options) => {
		patientName.value =decodeURIComponent( options?.patient_name )
		if (options?.note) note.value = decodeURIComponent(options.note)
		if (options?.idx) idx.value = options.idx
		
	})

	const goBack = () => uni.navigateBack()
	const submit = () => {
		try {
			const pages = getCurrentPages()
			const curr = pages[pages.length - 1]
			const ec = curr?.getOpenerEventChannel?.()
			ec?.emit && ec.emit('onVisitNoteSubmit', { note: note.value, idx: Number(idx.value) })
		} catch (e) {}
		uni.showToast({ title: '已添加', icon: 'success' })
		setTimeout(() => goBack(), 600)
	}
	const noop = () => {}
</script>

<style lang="scss" scoped>
	.visit-note-page{
		min-height: 100vh; background:#f5f5f5;
	}
	.nav-right{ display:flex; align-items:center; }
	.submit-text{ color:#8B2316; font-size: 30rpx; }

	.row{
		margin-top: 20rpx; background:#fff; padding: 26rpx 30rpx; display:flex; align-items:center; justify-content:space-between; border-bottom: 1rpx solid #eee;
		.row-label{ font-size: 32rpx; color:#8B2316; font-weight: 500; }
		.row-value{ font-size: 32rpx; color:#333; }
	}

	.section-title{box-sizing: border-box; margin-top: 20rpx; background:#fff; padding: 22rpx 30rpx; color:#8B2316; font-size: 30rpx; border-top: 1rpx solid #eee; border-bottom: 1rpx solid #eee; }

	.note-box{ background:#fff; padding: 20rpx 24rpx; }
	.note-textarea{
		width: 100%; min-height: 260rpx; background:#e5e5e5; border-radius: 0; padding: 20rpx; font-size: 32rpx; color:#111;
	}
</style>

