<template>
	<div class="container">
		<view class="white-content">
			<view class="content-title">
				<view class="content-weight">上传户口本本人页</view>
				<image class="content-img" src="https://www.focusnu.com/media/directive/index/bian.png" />
			</view>
			<view class="white-photo" @click="getMessage">
				<view class="photo-left">
					<view class="photo-weight">户口本本人页</view>
					<view class="photo-font">请上传户口本本人页</view>
				</view>
				<image class="photo" src="https://www.focusnu.com/media/directive/index/photoID.png" />
			</view>
			<view class="white-message">
				<view class="message-title">
					<view class="shu"></view>
					<view class="message-weight">
						确认户口本本人页信息
					</view>
				</view>
				<view style="margin-bottom: 20rpx;">
					<view v-for="(item,index) in nameArray" :key="index" class="one">
						<view class="one-left">{{item}}</view>
						<view class="one-right">自动获得</view>
					</view>
				</view>
			</view>
		</view>
		<view class="gray-font">
			<view class="">注意事项:</view>
			<view class="">1.所有上传信息均会被妥善保管，不用于其他商业用途或传输给第三方。</view>
		</view>
		<view class="finish-button" @click="goback">
			确认提交
		</view>
	</div>
</template>

<script setup>
	import {
		ref
	} from 'vue'

	const nameArray = ["姓名", "户主或与户主关系", "曾用名", "性别", "出生地", "民族", "籍贯", "出生日期", "本市(县)其他住址", "宗教信仰", "公民身份证件编号", "身高",
		"血型", "文化程度", "婚姻状况","兵役状况","服务住所","职业","何时由何地迁来本市(县)","何时由何地迁来本址"
	]

	// 本地保存的临时文件路径
	const tempImagePath = ref('')

	// 拍照并上传
	function getMessage() {
		// 使用 UniApp 的 API 调用摄像头
		uni.chooseImage({
			count: 1,
			sourceType: ['camera'],
			success: chooseRes => {
				tempImagePath.value = chooseRes.tempFilePaths[0]
				// 拍照成功后，调用上传函数
				uploadImage(tempImagePath.value)
			},
			fail: err => {
				console.error('拍照失败：', err)
			}
		})
	}

	// 上传图片到服务器
	function uploadImage(filePath) {
		uni.uploadFile({
			url: `${uni.getStorageSync('serverUrl')}/api/ocr/idCard`, // 替换为您的POST接口地址
			filePath,
			name: 'file', // 后端接收时的字段名
			header: {
				'X-Access-Token': uni.getStorageSync('token') || '',
			},
			formData: {
				// 可以根据接口需要添加额外表单字段
				// userId: '12345'
			},
			success: uploadRes => {
				console.log("????",JSON.parse(JSON.parse(uploadRes.data).result).data)

			},
			fail: err => {
				uni.showToast({
					title: '上传出错',
					icon: 'error'
				})

			}
		})
	}
	const goback = () =>{
		uni.redirectTo({
			url: `/pages/index/index`
		});
	}
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		width: 100%;
		background-color: rgb(239, 241, 252);
		position: relative;
		box-shadow: 2rpx 2rpx 4rpx rgba(0, 0, 0, 0.1);

		.white-content {
			width: 90%;
			margin-left: 5%;
			margin-top: 30rpx;
			// height: 1200rpx;
			border-radius: 35rpx;
			background-color: rgb(245, 251, 254);

			.content-title {
				display: flex;
				// align-items: center;
				height: 100rpx;
				position: relative;

				.content-weight {
					// font-size: 35rpx;
					font-weight: 600;
					margin-left: 20rpx;
					margin-top: 20rpx;
				}

				.content-img {
					position: absolute;
					right: 0;
					top: 0;
					width: 400rpx;
					height: 100%;
				}
			}
		}

		.white-photo {
			width: 90%;
			margin-left: 5%;
			// margin-top: 30rpx;
			height: 300rpx;
			border-radius: 35rpx;
			background-color: #fff;
			box-shadow: 4rpx 4rpx 8rpx rgba(0, 0, 0, 0.1);
			justify-content: space-around;
			align-items: center;
			display: flex;

			.photo {
				width: 300rpx;
				height: 200rpx;
			}
		}
		.white-message{
			width: 90%;
			margin-left: 5%;
			margin-top: 30rpx;
			margin-bottom: 30rpx;
			// height: 800rpx;
			border-radius: 35rpx;
			background-color: #fff;
			box-shadow: 4rpx 4rpx 8rpx rgba(0, 0, 0, 0.1);
			justify-content: space-around;
			// align-items: center;
			display: flex;
			flex-direction: column;
			.message-title{
				width: 100%;
				height: 100rpx;
				align-items: center;
				display: flex;
				.shu{
					width: 10rpx;
					height: 30rpx;
					background-color: #0097FF;
					border-radius: 10rpx;
					margin: 0 20rpx 0 30rpx;
				}
				.message-weight{
					font-size: 30rpx;
					// font-weight: 600;
				}
			}
			.one{
				width: 90%;
				margin-left: 5%;
				border-bottom: 1rpx solid #d7d7d7;
				height: 90rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10rpx;
				.one-left{
					margin-left: 10rpx;
				}
				.one-right{
					margin-right: 10rpx;
					color: #999999 ;
				}
			}
		}
	}

	.photo-left {
		.photo-weight {
			font-size: 26rpx;
			font-weight: 600;
		}

		.photo-font {
			font-size: 23rpx;
			margin-top: 10rpx;
		}

	}
	.gray-font{
		padding: 30rpx 60rpx;
		color: #999999;
	}
	.finish-button{
		display: flex;
		justify-content: center;
		align-items: center;
		width: 80%;
		height: 100rpx;
		margin: 0rpx auto;
		margin-bottom: 80rpx;
		color: #fff;
		background: linear-gradient(to right,#00C9FF,#0076FF );
		border-radius: 35rpx;
		font-size: 33rpx;
	}
</style>