<template>
	<view class="feedback-container">
		<!-- 状态栏占位 -->
		<view class="status-bar"></view>
		
		<!-- 顶部导航栏 -->
		<view class="nav-bar">
			<view class="nav-left" @click="goBack">
				<text class="back-arrow">‹</text>
			</view>
			<text class="nav-title">意见反馈</text>
		</view>
		
		<!-- 反馈输入区域 -->
		<view class="feedback-input-container">
			<view class="input-area">
				<textarea 
					class="feedback-textarea" 
					v-model="feedbackText"
					:maxlength="200"
					placeholder=""
					@input="onInput"
					disabled
				></textarea>
				<!-- <view class="voice-button" @click="toggleVoiceInput">
					<text class="voice-icon">🎙</text>
				</view> -->
			</view>
		</view>
		
		<!-- 底部提交按钮 -->
		<view class="submit-container">
			<button class="submit-btn" @click="submitFeedback" :disabled="!feedbackText.trim()">
				已确认风险，提交注销申请
			</button>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import api from '@/api/api';
	const feedbackText = ref('账户注销后不可恢复，您将永久放弃此账户现有权益\n1.您将不能再使用此账户随访患者，不能接收随访患者发送的信息\n2.您所有的咨询、订单、下载记录将被清除且不能找回\n3.肝胆相照平台提供的文献、视频等服务将结束\n4.申请注销账户前，请确保账户相关权益已结清收到您的注销申请后，我们将在10个工作日内帮您完成注销及数据清除工作');
	
	// 返回上一页
	const goBack = () => {
		uni.navigateBack();
	};
	
	// 输入处理
	const onInput = (e) => {
		feedbackText.value = e.detail.value;
	};
	
	// 语音输入切换
	const toggleVoiceInput = () => {
		uni.showToast({
			title: '语音输入功能',
			icon: 'none'
		});
	};
	
	// 提交反馈
	const submitFeedback = () => {
		if (!feedbackText.value.trim()) {
			uni.showToast({
				title: '请输入反馈内容',
				icon: 'none'
			});
			return;
		}
		
		api.patientListByGBKU().then(res => {
			console.log(res);
			if(res.code == 200 && res.data.length == 0){
				// 显示确认弹框
				uni.showModal({
					title: '确认注销',
					content: '注销账户后，您的所有数据将被永久删除且无法恢复。确定要提交注销申请吗？',
					confirmText: '确认注销',
					cancelText: '取消',
					confirmColor: '#ff0000',
					success: (res) => {
						if (res.confirm) {
							// 用户确认后执行注销
							uni.showLoading({
								title: '提交中...'
							});
							
							api.addFeedBack({
								content: feedbackText.value
							}).then(res => {
								console.log(res);
								uni.hideLoading();
								uni.showToast({ title: '注销申请已提交', icon: 'success' });
								setTimeout(() => {
									uni.navigateBack();
								}, 1500);
							}).catch(err => {
								uni.hideLoading();
								uni.showToast({ title: '提交失败，请重试', icon: 'none' });
							});
						}
					}
				});
			}else{
				uni.showToast({ title: "请您解除所有随访患者后再提交注销申请", icon: 'none', duration: 5000 });
			}
		});
		
	};
</script>

<style scoped>
	.feedback-container {
		background-color: #ffffff;
		min-height: 100vh;
		position: relative;
	}
	
	/* 状态栏占位 */
	.status-bar {
		height: 44rpx;
		background-color: #ffffff;
	}
	
	/* 导航栏样式 */
	.nav-bar {
		display: flex;
		align-items: center;
		height: 88rpx;
		background-color: #f5f5f5;
		padding: 0 30rpx;
		position: relative;
		border-bottom: 1rpx solid #e0e0e0;
	}
	
	.nav-left {
		position: absolute;
		left: 30rpx;
		z-index: 1;
	}
	
	.back-arrow {
		font-size: 48rpx;
		color: #ff0000;
		font-weight: bold;
		line-height: 1;
	}
	
	.nav-title {
		flex: 1;
		text-align: center;
		font-size: 36rpx;
		color: #ff0000;
		font-weight: 500;
	}
	
	/* 反馈输入区域 */
	.feedback-input-container {
		padding: 30rpx;
		flex: 1;
	}
	
	.input-area {
		position: relative;
		background-color: #ffffff;
		border: 2rpx solid #e0e0e0;
		border-radius: 8rpx;
		min-height: 400rpx;
		padding: 30rpx;
	}
	
	.input-placeholder {
		position: absolute;
		top: 30rpx;
		left: 30rpx;
		font-size: 28rpx;
		color: #999999;
		line-height: 1.5;
		pointer-events: none;
		z-index: 1;
		width: calc(100% - 100rpx);
	}
	
	.feedback-textarea {
		width: 100%;
		min-height: 300rpx;
		font-size: 28rpx;
		color: #333333;
		line-height: 1.5;
		background: transparent;
		border: none;
		outline: none;
		resize: none;
		position: relative;
		z-index: 2;
	}
	
	.voice-button {
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
		width: 60rpx;
		height: 60rpx;
		background-color: #ff0000;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 3;
	}
	
	.voice-icon {
		font-size: 32rpx;
		color: #ffffff;
	}
	
	/* 底部提交按钮 */
	.submit-container {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 30rpx;
		background-color: #ffffff;
		border-top: 1rpx solid #e0e0e0;
		z-index: 999;
	}
	
	.submit-btn {
		width: 100%;
		height: 88rpx;
		background-color: #ffffff;
		border: 2rpx solid #e0e0e0;
		border-radius: 8rpx;
		color: #ff0000;
		font-size: 32rpx;
		font-weight: 500;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.submit-btn:active {
		background-color: #fff0f0;
	}
	
	.submit-btn:disabled {
		color: #cccccc;
		border-color: #f0f0f0;
	}
</style>
