<template>
	<view class="setting-page">
		<uni-nav-bar
			left-icon="left"
			title="常用设置"
			@clickLeft="goBack"
			fixed
			color="#8B2316"
			height="140rpx"
			:border="false"
			backgroundColor="#eee"
		>
		
		</uni-nav-bar>

		<view class="list-block">
			<view class="cell" @click="goRemark">
				<text class="cell-left">设置备注</text>
				<view class="cell-right">
					<text class="cell-desc">{{ groupInfo.nickname || '给患者添加备注名' }}</text>
					<uni-icons type="right" size="20" color="#999"></uni-icons>
				</view>
			</view>

			<view class="cell" @click="goGroup">
				<text class="cell-left">设置分组</text>
				<view class="cell-right">
					<text class="cell-desc">{{ groupInfo.name || '通过分组给患者分类' }}</text>
					<uni-icons type="right" size="20" color="#999"></uni-icons>
				</view>
			</view>

			<view class="cell" @click="goRemark">
				<text class="cell-left">患者描述</text>
				<view class="cell-right">
					<text class="cell-desc">{{ groupInfo.note || '补充患者关键信息，方便随访患者' }}</text>
					<uni-icons type="right" size="20" color="#999"></uni-icons>
				</view>
			</view>

			<view class="cell" @click="setNextFollow">
				<text class="cell-left">下次随访时间</text>
				<view class="cell-right">
					<text class="cell-desc">{{patientCardData.FollowUpDate? patientCardData.FollowUpDate : '添加随访提醒' }}</text>
					<uni-icons type="right" size="20" color="#999"></uni-icons>
				</view>
			</view>

			<view class="cell" @click="goFeedback">
				<text class="cell-left">投诉反馈</text>
				<view class="cell-right">
					<uni-icons type="right" size="20" color="#999"></uni-icons>
				</view>
			</view>
		</view>

		<view class="danger-block">
			<text class="danger-text" @click="visible=true">解除随访</text>
		</view>
	</view>
	<unidialog :visible="visible" :content="message" @close="visible=false" @confirm="deleteFollowUp" ></unidialog>
</template>

<script setup>
    	import { ref } from 'vue'
	import navTo from '@/utils/navTo.js'
	import { onLoad, onShow } from '@dcloudio/uni-app'
    import api from '@/api/api.js'
	import unidialog from '@/components/dialog/dialog.vue'
	const patientUuid = ref('')
	const patientName = ref('')
	const patientCardData = ref({})
	const groupInfo = ref({})
	const visible = ref(false)
	const message = ref('')
	const goBack = () => {
		uni.navigateBack();
	}
	const goRemark = () => {
		navTo({ url: '/pages_app/patientRemark/patientRemark?uuid=' + patientUuid.value })
	}
	
	const goGroup = () => {
		navTo({ url: '/pages_app/groupManage/groupManage?uuid=' + patientUuid.value })
	}
	onLoad((options) => {
		patientUuid.value = options.uuid;
		console.log(patientUuid.value)
	})
	onShow(() => {
		patientCard();
	})
	const setNextFollow = () => {
		if(patientCardData.value.FollowUpUuid){
			navTo({ url: '/pages_app/followDetail/followDetail?followUpUuid=' +patientCardData.value.FollowUpUuid+'&patient_name=' + patientName.value })
		}else{
			navTo({ url: '/pages_app/visit/visit?uuid=' + patientUuid.value+'&patient_name=' + patientName.value })
		}
		
	}
	const goFeedback = () => {
		navTo({ url: '/pages_app/feedback/feedback' })
	}
	const patientCard = () =>{
		api.patientCard({
			patient_uuid: patientUuid.value
		}).then(res => {
			if(res.code == 200){
				patientName.value = res.group.nickname || res.patient.realName
				message.value = `解除[${patientName.value}]的随访关系？`
				patientCardData.value = res
				groupInfo.value = res.group || {}
			}
		})
	}
	const deleteFollowUp = () => {
		api.cancelRes({
			patientUuid: patientUuid.value
		}).then(res => {
			if(res.code == 1){
			uni.showToast({
				title: '解除成功',
				icon: 'none'
			})
			uni.redirectTo({
				url: '/pages_app/patientMsg/patientMsg'
			})
		}
		visible.value = false
	})
}
</script>

<style lang="scss" scoped>
	.setting-page{
		min-height: 100vh;
		background:#f7f7f7;
	}
	.list-block{
		margin-top: 20rpx;
		background: #fff;
		.cell{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx;
			border-bottom: 1rpx solid #f0f0f0;
			&:last-child{ border-bottom: none; }
			.cell-left{
				font-size: 32rpx;
				color: #333;
			}
			.cell-right{
				display: flex;
				align-items: center;
				gap: 16rpx;
				.cell-desc{
					font-size: 26rpx;
					color: #999;
				}
			}
		}
	}
	.danger-block{
		margin-top: 30rpx;
		background: #fff;
		padding: 40rpx 0;
		display: flex;
		justify-content: center;
		.align-center{ align-items: center; }
		.danger-text{
			color: #8B2316;
			font-size: 32rpx;
		}
	}
</style>
