<template>
	<view class="visit-note-page">
		<navBar :title="'随访详情'" />
		<!-- <uni-nav-bar
			left-icon="left"
			title="随访详情"
			@clickLeft="goBack"
			fixed
			color="#8B2316"
			height="180rpx"
			:border="false"
			backgroundColor="#eee"
		>
		
		</uni-nav-bar> -->

		<!-- 患者行 -->
		<view class="contentbox">
			<view class="row" @click="noop">
			<text class="row-label">患者</text>
			<text class="row-value">{{ patientName }}</text>
		</view>
		<view class="row" @click="noop">
			<text class="row-label">日期</text>
			<text class="row-value">{{ datetime }}</text>
		</view>
		<!-- 标题栏 -->
		<view class="section-title">随访内容</view>

		<!-- 输入框区域 -->
		<view class="note-box">
			<textarea class="note-textarea" v-model.trim="note" placeholder="请填写随访内容" auto-height :maxlength="200" :adjust-position="false"/>
		</view>
		</view>
		<!-- 底部删除按钮 -->
		<view class="fixed-footer">
			<view class="fixed-btn" @click="deleteFollowUp">删除该条记录</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { onLoad,onShow } from '@dcloudio/uni-app'
    import api from '@/api/api.js'
	const patientName = ref('')
	import navBar from '@/components/navBar/navBar.vue'
	const note = ref('请近日来医院复诊、复查')
	const datetime = ref('')
	const followUpUuid = ref('')
	onLoad((options) => {
		patientName.value = options?.patient_name
	   if (options?.followUpUuid) followUpUuid.value = options.followUpUuid
	})
	onShow(() => {
		getFollowUp();
	})
	const deleteFollowUp = () => {
		api.deleteFollowUp({
			uuid: followUpUuid.value
		}).then(res => {
			console.log(res)
			if(res.code == 200){
				uni.showToast({
					title: '删除成功',
					icon: 'none'
				})
				setTimeout(() => goBack(), 600)
			}
		})
	}
	const getFollowUp = () => {
		api.getFollowUp({
			uuid: followUpUuid.value
		}).then(res => {
			console.log(res)
			if(res.code == 200){
				note.value = res.data.note
				datetime.value = res.data.datetime
			}
		})
	}
	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: 'none' })
		setTimeout(() => goBack(), 600)
	}
	const noop = () => {}
</script>

<style lang="scss" scoped>
  .contentbox{
	position: fixed;
	top: calc(var(--status-bar-height) + 44px);
	left: 0;
	right: 0;
	overflow-y: scroll;
	bottom:128rpx;
	z-index:1;
	
  }
	.visit-note-page{
		 background:#f5f5f5; padding-bottom: 120rpx;
	}
	.nav-right{ display:flex; align-items:center; }
	.submit-text{ color:#8B2316; font-size: 30rpx; }

	.row{
		 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{ background:#fff; padding: 22rpx 30rpx; color:#8B2316; font-size: 30rpx;border-bottom: 1rpx solid #eee; }

	.note-box{ background:#fff; padding: 20rpx 24rpx; }
	.note-textarea{
		box-sizing: border-box;
		width: 100%; min-height: 260rpx; background:#e5e5e5; border-radius: 0; padding: 20rpx; font-size: 32rpx; color:#111;
	}
	.fixed-footer{ position: fixed; left: 0; right: 0; bottom: 0; padding: 20rpx; background: transparent; }
	.fixed-btn{ background:#8B2316; border-radius: 12rpx; padding: 24rpx 30rpx; text-align:center; color:#fff; font-size:30rpx; margin: 0 20rpx; }
</style>

