<template>
	<view class="leader">
		<view class="tips">
			提示：请输入您申报复工时同样的信息（名字，手机号，身份证）！
		</view>
		<form @submit="formSubmit" @reset="formReset">
			<view class="cu-form-group">
				<view class="title"><span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx">*</span>姓名</view>
				<input class="text-right" placeholder="注意简繁体，与复工申请时一致" :value="form.name" name="input" @input="updateInputVal($event,'name')"></input>
			</view>
		<view class="cu-form-group">
			<view class="title"><span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx">*</span>手机号码</view>
			<input class="text-right" placeholder="请输入手机号码" type="number" :value="form.phone" name="input" @input="updateInputVal($event,'phone')"></input>
		</view>
			<view class="cu-form-group">
				<view class="title"><span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx">*</span>身份证/护照号</view>
				<input class="text-right" placeholder="请输入身份证号码/护照号" :value="form.idCard" name="input" @input="updateInputVal($event,'idCard')"></input>
			</view>
			<view class="padding">
				<button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					name:'',
					phone:'',
					idCard:''
				}
			}
		},
		methods: {
			// 更新输入框绑定的表单内容
			updateInputVal(event, props) {
				this.form[props] = event.target.value
			},
			formSubmit(){
				if(this.form.name && this.form.phone.length == 11){
					this.$http.post(`/sict-ncov/user/vip/register?name=${this.form.name}&phone=${this.form.phone}&idCard=${this.form.idCard}`).then(res => {
						const d = res.data
						if(d.code == 1){
							uni.showToast({
								icon: 'success',
								title: '注册成功！'
							})
							uni.reLaunch({
								url: '/pages/index/index',
							});
						}else{
							uni.showToast({
								icon: 'none',
								title: d.message
							})
							uni.reLaunch({
								url: '/pages/index/index',
							});
						}
					}).catch(err => {
						console.log(err)
					})
				}else{
					uni.showToast({
						icon: 'none',
						title: '请填写完整真实资料！'
					})
				}
			}
		}
	}
</script>

<style scoped>
.tips{
	font-size: 32upx;
	padding:40upx;
}
</style>
