<template>
	<view class="container">

		<!-- 物品信息 -->
		<view class="form-card">

			<view class="form-item">
				<view class="item-label">
					<input class="input-field" placeholder="姓名" placeholder-class="placeholder" v-model="formInfo" />
				</view>
				<view class="item-control">
					<input class="input-field" placeholder="电话" placeholder-class="placeholder" v-model="formInfo" />
				</view>
			</view>
			<view class="form-item" @click="showTimePicker = true">
				<text class="time-value placeholder">省市区</text>
				<text class="time-value value">{{ selectedTime }}</text>
				<u-icon class="arrow" name='arrow-right' size="18"></u-icon>
			</view>

			<view class="form-item">
				<view class="item-control">
					<input class="input-field" placeholder="详细地址" placeholder-class="placeholder" v-model="formInfo" />
				</view>
			</view>


			<view class="form-item">
				<!-- 设置默认和清空 -->
				<view class="form-actions">
					<view class="action-left">
						<switch color="#007AFF" @change="onDefaultChange" />
						<text class="action-text">设为默认寄件地址</text>
					</view>
					<view class="action-right" @click="clearForm">
						<text class="clear-text">清空</text>
					</view>
				</view>
			</view>
		</view>


		<view class="section-title">最近使用地址</view>

		<!-- 最近使用地址 -->
		<view class="recent-address">
			<!-- 地址项1 -->
			<view class="address-item" @tap="selectAddress(0)">
				
					<AddressInfo v-if="addressSend.id" :address="addressSend" />
				<view class="address-info">
					<view class="address-name">袁添昊 13344642161</view>
					<view class="address-detail">湖北省荆州市新石南路747号</view>
				</view>
			<!-- 	<view class="address-select">
					
				</view> -->
			</view>

			<!-- 地址项2 -->
			<view class="address-item" @tap="selectAddress(1)">
				<view class="address-info">
					<view class="address-name">袁添昊 13344642161</view>
					<view class="address-detail">湖北省荆州市新石南路747号</view>
				</view>
				<!-- <view class="address-select">
					
				</view> -->
			</view>
		</view>
		<!-- 下单按钮 -->
		<view class="submit-btn" @click="onConfirm">
			确定
		</view>

		<!-- 安全区域占位 -->
		<view class="safe-area"></view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue'
	import {onLoad} from '@dcloudio/uni-app'
	import AddressInfo from '@/components/AddressInfo.vue'
	
	const addType = ref('1') //1 表示从创建订单过来  2 表示编辑  3表示创建
	
	// 表单数据
	const formData = reactive({
		name: '',
		phone: '',
		region: [],
		address: '',
		isDefault: false
	})
	
	// 最近地址列表
	const recentAddresses = ref([{
			name: '袁添昊',
			phone: '13344642161',
			address: '湖北省荆州市新石南路747号'
		},
		{
			name: '袁添昊',
			phone: '13344642161',
			address: '湖北省荆州市新石南路747号'
		}
	])
	
	onLoad((option)=>{
		
	})


	// 省市区选择
	const onRegionChange = (e) => {
		formData.region = e.detail.value
	}

	// 默认地址切换
	const onDefaultChange = (e) => {
		formData.isDefault = e.detail.value
	}

	// 清空表单
	const clearForm = () => {
		formData.name = ''
		formData.phone = ''
		formData.region = []
		formData.address = ''
		formData.isDefault = false
	}

	// 选择地址
	const selectAddress = (index) => {
		const address = recentAddresses.value[index]
		formData.name = address.name
		formData.phone = address.phone
		formData.address = address.address
	}

	// 确定提交
	const onConfirm = () => {
		// 这里可以添加表单验证
		if (!formData.name || !formData.phone || !formData.address) {
			uni.showToast({
				title: '请填写完整信息',
				icon: 'none'
			})
			return
		}

		// 提交逻辑
		console.log('提交数据:', formData)
		uni.showToast({
			title: '提交成功',
			icon: 'success'
		})

		// 返回上一页或执行其他操作
		// uni.navigateBack()
	}
</script>

<style scoped lang="less">
	.container {
		background-color: #F5F7FA;
		min-height: 100vh;
		padding: 20rpx 20rpx 30rpx 20rpx;
	}

	.form-card {
		background-color: #fff;
		border-radius: 32rpx;
		padding: 0rpx 20rpx;
	}

	.form-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 32rpx;
	}


	.form-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
		border-bottom: 1rpx solid #F1F3F8;

		&:last-child {
			border-bottom: none;
			margin-bottom: 0;
		}

		.item-label {
			font-size: 28rpx;
			color: #666;
			font-weight: 400;

			&.required::before {
				content: '*';
				color: #ff4444;
				margin-right: 8rpx;
			}
		}

		.item-control {
			display: flex;
			align-items: center;

			&.btn {
				background: #fff;
				border: 1rpx solid #dcdfe6;
				border-radius: 5rpx;
				height: 59rpx;
				width: 266rpx;
				box-sizing: border-box;
			}

		}

		.input-field {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			padding: 0 24rpx;
			font-size: 28rpx;
			color: #333;
			text-align: left;


			&::placeholder {
				color: #999;
			}
		}

		.time-value {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			color: #333;
			line-height: 88rpx;
			height: 88rpx;
			padding: 0 24rpx;

			&.placeholder {
				color: #999;
			}

			.value {
				margin-right: 16rpx;
			}

			.arrow {
				margin-left: 32rpx;
				color: #999;
				font-size: 28rpx;
				font-weight: bold;
			}
		}
	}

	/* 寄件标识 */
	.send-tag {
		padding: 40rpx 30rpx 20rpx;
		background-color: #fff;
	}

	.send-circle {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		background-color: #007AFF;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-weight: bold;
	}

	/* 表单区域 */
	.form-container {
		background-color: #fff;
		padding: 0 30rpx;
		margin-bottom: 20rpx;
	}

	.form-title {
		font-size: 18px;
		font-weight: 500;
		color: #333;
		padding: 30rpx 0 20rpx;
		border-bottom: 1rpx solid #eee;
	}

	.form-item {
		width: 100%;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #eee;
	}

	.form-input {
		font-size: 16px;
		height: 40rpx;
		line-height: 40rpx;
		color: #333;
	}

	.form-input::placeholder {
		color: #999;
	}

	.picker-placeholder {
		font-size: 16px;
		height: 40rpx;
		line-height: 40rpx;
		color: #999;
	}

	.picker-placeholder.has-value {
		color: #333;
	}

	/* 表单操作 */
	.form-actions {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 0;
	}

	.action-left {
		display: flex;
		align-items: center;
	}

	.action-text {
		font-size: 28rpx;
		color: #333;
		margin-left: 10rpx;
	}

	.action-right {
		padding: 10rpx 20rpx;
	}

	.clear-text {
		height: 44rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #1B64F0;
		line-height: 44rpx;
	}

	/* 最近地址 */
	.recent-address {
		background-color: #fff;
		padding: 0 30rpx;
	}

	.section-title {
		height: 48rpx;
		font-size: 32rpx;
		color: #333333;
		line-height: 48rpx;
		margin: 20rpx 0rpx;
		font-weight: bold;
	}

	.address-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #eee;
	}

	.address-info {
		flex: 1;
	}

	.address-name {
		font-size: 16px;
		color: #333;
		margin-bottom: 10rpx;
	}

	.address-detail {
		font-size: 14px;
		color: #666;
		line-height: 1.4;
	}

	.address-select {
		width: 40rpx;
		height: 40rpx;
		border: 1rpx solid #007AFF;
		border-radius: 50%;
		margin-left: 20rpx;
	}


	.safe-area {
		height: 140rpx;
	}

	.submit-btn {
		position: fixed;
		bottom: 40rpx;
		left: 30rpx;
		right: 30rpx;
		width: 686rpx;
		height: 88rpx;
		background: #1B64F0;
		border-radius: 44rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		z-index: 10;
	}
</style>