<template>
	<view class="container">
		<view class="form-box">
			<u-form :model="formData.form" ref="formRef" label-position="top" :label-style="{fontWeight: 'bold', fontSize: '26rpx'}">
				<u-form-item label="姓名" prop="name"><u-input v-model="formData.form.name" :border="true"  type="text" placeholder="请输入缴交对象姓名" placeholder-style="font-size: 22rpx;"/></u-form-item>
				<u-form-item label="证件号码" prop="idNumber"><u-input v-model="formData.form.idNumber" :border="true" type="text" placeholder="请输入缴交对象的身份证号/手机号/业务水平证书编号" placeholder-style="font-size: 22rpx;"/></u-form-item>
				<u-form-item label="代缴人姓名" prop="giver">
					<u-input disabled v-model="formData.form.giver" :border="false" type="text" />
				</u-form-item>
				<u-form-item label="代缴人联系方式" prop="giverPhone">
					<u-input disabled v-model="formData.form.giverPhone" :border="false" type="text" />
				</u-form-item>
			</u-form>
		</view>
		<view class="desc-box">
			<!-- <rich-text :nodes="explain"></rich-text> -->
			<mp-html :content="explain" />
		</view>
		<view class="bottom-box">
			<u-button type="primary" shape="circle" @click="onSubmit">查询</u-button>
		</view>
	</view>
</template>

<script setup>
	import { ref, reactive } from 'vue'
	import { onLoad, onReady } from '@dcloudio/uni-app'
	import { person } from '@/api/cost.js'
	
	const explain = `<p><span style="font-size: 14px;">批量缴交请联系协会秘书处，刘小姐&nbsp;13326440363</span></p>`
	
	const formRef = ref()
	const formData = reactive({
		form: {
			name: null, // 姓名
			idNumber: null, // 证件号码
			giver: "", //默认当前用户名
			giverPhone: "" //默认当前用户手机号
		},
		rules: {
			name: [
				{ 
					required: true, 
					message: '请输入缴交对象姓名', 
					// 可以单个或者同时写两个触发验证方式 
					trigger: 'blur',
				}
			],
			idNumber: [
				{ 
					required: true, 
					message: '请输入缴交对象的身份证号/手机号/业务水平证书编号', 
					// 可以单个或者同时写两个触发验证方式 
					trigger: 'blur',
				}
			],
		}
	})
	
	function onSubmit() {
		formRef.value.validate((valid) => {
			if (valid) {
				// 查询到的ID
				const id = '1'
				
				person(formData.form).then(res => {
					if (res && res.code === 0) {
						if (res.data.userId) {
							uni.navigateTo({
								url: `/pages/daiJiaoGeRenChaXunJieGuo/daiJiaoGeRenChaXunJieGuo?name=${formData.form.name}&idNumber=${formData.form.idNumber}&giver=${formData.form.giver}&giverPhone=${formData.form.giverPhone}`
							})
						}
					}
				})
			}
		})
	}
	
	onReady(() => {
		formRef.value.setRules(formData.rules)
	})
	
	onLoad(() => {
		const user = uni.getStorageSync("USER_INFO")
		formData.form.giver = user.name
		formData.form.giverPhone = user.phone
		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: 150rpx;
			padding: 0 50rpx;
		}
	}
</style>