<template>
	<view class="container">
		<view class="form-box">
			<u-form :model="formData.form" ref="formRef" label-width="160" :label-style="{fontWeight: 'bold', fontSize: '26rpx'}">
				<u-form-item label="机构名称" prop="name"><u-input v-model="formData.form.name" :border="true"  type="text" placeholder="请输入缴交机构名称"/></u-form-item>
				<u-form-item label="机构备案证号" prop="number"><u-input v-model="formData.form.number" :border="true" type="text" placeholder="请输入缴交对象机构备案证号"/></u-form-item>
				<u-form-item label="缴费年限" prop="year"><u-input v-model="formData.form.year" :border="true" type="select" @click="showYear = true" placeholder="请选择缴费时间"/></u-form-item>
			</u-form>
		</view>
		<u-select v-model="showYear" :list="yearList" @confirm="onYearConfirm"></u-select>
		<view class="bottom-box">
			<u-button type="error" shape="circle" @click="onSubmit">点击缴费</u-button>
		</view>
	</view>
</template>

<script setup>
	import { ref, reactive } from 'vue'
	import { onLoad, onReady } from '@dcloudio/uni-app'
	
	const formRef = ref()
	const formData = reactive({
		form: {
			name: null, // 机构名称
			number: null, // 机构备案证号
			year: null // 缴费年限
		},
		rules: {
			name: [
				{ 
					required: true, 
					message: '请输入缴交对象机构名称', 
					// 可以单个或者同时写两个触发验证方式 
					trigger: 'blur',
				}
			],
			number: [
				{ 
					required: true, 
					message: '请输入缴交对象机构备案证号', 
					// 可以单个或者同时写两个触发验证方式 
					trigger: 'blur',
				}
			],
			year: [
				{ 
					required: true, 
					message: '请输入缴费年限', 
					// 可以单个或者同时写两个触发验证方式 
					trigger: 'change',
				}
			],
		}
	})
	const showYear = ref(false)
	const yearList = ref([
		{
			value: '2025',
			label: '2025'
		},
		{
			value: '2024',
			label: '2024'
		}
	])
	function onYearConfirm(val) {
		formData.form.year = val[0].value
	}
	
	function onSubmit() {
		formRef.value.validate((valid) => {
			if (valid) {
				// 查询到的ID
				const id = '1'
				uni.navigateTo({
					url: `/pages/daiJiaoDanWeiChaXunJieGuo/daiJiaoDanWeiChaXunJieGuo?id=${id}`
				})
			}
		})
	}
	
	onReady(() => {
		formRef.value.setRules(formData.rules)
	})
	
	onLoad(() => {
		console.log('onLoad')
	})
</script>

<style lang="scss" scoped>
	.container {
		height: 100vh;
		width: 100vw;
		background-color: $uni-bg-color;
		padding: 20rpx;
		
		.form-box {
			padding: 20rpx 0;
		}
		.bottom-box {
			margin-top: 100rpx;
			padding: 0 50rpx;
		}
	}
</style>