<template>
	<view class="content">
		<view class="register-wrap">
			<view class="zhcx-table">	
				<view class="zhcx-table-row">
					<view class="name">
						<text>账号</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.accountName" placeholder="账号位11位手机号码"  />
					</view>
				</view>	
				<view class="zhcx-table-row">
					<view class="name">
						<text>密码</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.password"   />
					</view>
				</view>		
				<view class="zhcx-table-row">
					<view class="name">
						<text>姓名</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.name"  />
					</view>
				</view>						
				<view class="zhcx-table-row">
					<view class="name">
						<text>身份证</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.idCard"  />
					</view>
				</view>	
				<view class="zhcx-table-row">
					<view class="name">
						<text>性别</text>
					</view>
					<view class="text" >
						<radio-group @change="changeGender">
							<label>
								<radio value="0" :checked="form.gender==='0'"  /><text>男</text>
							</label>
							<label class="gender-item-woman">
								<radio value="1" :checked="form.gender==='1'"  /><text>女</text>
							</label>
						</radio-group>					
					</view>
				</view>		
				<view class="zhcx-table-row">
					<view class="name">
						<text>住址</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.address" />
					</view>
				</view>					
			</view>				
		</view>	
		<view class="handle-wrap">
			<view class="submit-BT" @click="submit">
				<text>提交</text>
			</view>			
		</view>
	</view>
</template>
<script>
	import { validPhone ,notEmpty} from '@/libs/index';
	import {register} from '@/api/user';
	export default {
		data() {
			return {
				form:{
					name:"",
					phoneNumber:"",
					idCard:"",
					gender:"",
					address:"",
					password:""				
				}
			}
		},
		methods: {
			changeGender({detail}){
				this.form.gender=detail.value;
			},
			submit(){	
				let form=this.form;
				if(!validPhone(form['accountName'])){
					uni.showToast({
						icon:"none",
						title:"账号必须位11位手机号码"
					})
					return;
				}
				if(!notEmpty(form['password'])){
					uni.showToast({
						icon:"none",
						title:"请设置登录密码"
					})
					return;				
				}				
				if(!notEmpty(form['name'])){
					uni.showToast({
						icon:"none",
						title:"请填写真实姓名"
					})
					return;				
				}
				if(!notEmpty(form['idCard'])){
					uni.showToast({
						icon:"none",
						title:"请填写身份证号码"
					})
					return;				
				}			
				var params={
					accountType:2,
					accountName:(form['accountName']).trim(),
					password:(form['password']).trim(),
					accountRealName:form['name'],
					accountTel:(form['accountName']).trim(),
					patientName:form['name'],
					patientSex:form['gender'],
					patientIdCard:form['idCard'],
					patientAddress:form['address']			
				}
				register(params).then(()=>{
					uni.showToast({
						title:"注册成功!"
					})
					setTimeout(()=>{
						uni.reLaunch({
							url:"/pages/login/index"
						})
					},1500)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		.register-wrap{
			.zhcx-table-row{
				.text{
					text-align: left;
					.gender-item-woman{
						margin-left: 40upx;
					}
				}
			}
		}
	}
	.handle-wrap{
		&{
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			padding: 10upx 0;
		}
		.submit-BT{
			width: 702upx;
			height: 100upx;
			line-height: 100upx;
			text-align: center;
			background-color: #3384FF;
			border-radius: 12upx;	
			color: #fff;
			font-size: 32upx;
			margin: 0 auto;
		}				
	}
</style>
