<template>
	<view class="setting-page">
		<navBar :title="'常用设置'"></navBar>
		<!-- <uni-nav-bar
			left-icon="left"
			title="常用设置"
			@clickLeft="goBack"
			fixed
			color="#8B2316"
			height="180rpx"
			: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="goRemark">
				<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 class="danger-action">
			<button class="danger-btn" @click="visible=true">解除随访</button>
		</view>
		</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,onBackPress} from '@dcloudio/uni-app'
	import navBar from '@/components/navBar/navBar.vue'
    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 from = ref('');
	onBackPress(() => {
		if(!from.value){
			plus.runtime.quit();
			return true;
		}
	});
	const goBack = () => {
		if(!from.value){
			plus.runtime.quit();
		}else{
			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;
		if(options.from){
			from.value = options.from;
		}
		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){
				console.log(res.patient)
				patientName.value = res.patient.nickname?res.patient.nickname:res.patient.realname;
				console.log(patientName.value)
				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'
			})
			setTimeout(() => {
				uni.navigateBack()
			}, 1000)
		}
		visible.value = false
	})
}
</script>

<style lang="scss" scoped>
	.setting-page{
		min-height: 100vh;
		background:#f7f7f7;
	}
	.list-block{
		position: fixed;
		top: calc(var(--status-bar-height) + 44px);
		left: 0;
		right: 0;
		bottom: 0rpx;
		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;
				white-space:nowrap;
				color: #333;
			}
			.cell-right{
				display: flex;
				align-items: center;
				justify-content: flex-end;
				flex: 1;
				margin-left: 20rpx;
				min-width: 0;
				
				.cell-desc{
					flex: 1;
					min-width: 0;
					display: block;
					font-size: 26rpx;
					color: #999;
					overflow: hidden;
					margin-right: 16rpx;
					text-overflow: ellipsis;
					white-space: nowrap;
					text-align: right;
					
				}
			}
		}
	}
	.danger-action{
	   margin-top: 30rpx;
		background: #fff;
		
		padding: 20rpx 30rpx calc(20rpx + env(safe-area-inset-bottom));
		display: flex;
		justify-content: center;
		.danger-btn{
			width: 100%;
			height: 92rpx;
			line-height: 92rpx;
			border: 1rpx solid #8B2316;
			background: #fff;
			border-radius: 12rpx;
			color: #8B2316;
			font-size: 32rpx;
		}
	}
</style>
