<template>
	<view style="">
		<view class="navTab">
			<view class="sintitle">
				<img src="/static/index/grxx.png" alt="">
				<p>认证信息</p>
			</view>
			<u-form :model="certobj"  ref="certobj" label-position='left' label-width='150'  border-bottom='false' >
				<u-form-item  label="姓名：" prop="name"  border-bottom='false' required='true'>
					<view class="sinput">
						<u-input style="width:100%;" :disabled='istest' v-model="certobj.name"  placeholder='输入姓名'/>
					</view>
				</u-form-item>
				<u-form-item  label="身份证号：" prop="idNumber"  border-bottom='false' required='true'>
					<view class="sinput">
						<u-input style="width:100%;" :disabled='istest' v-model="certobj.idNumber" placeholder='输入身份证号' />
					</view>
				</u-form-item>
			</u-form>
			<view style="margin-top: 30px;" v-if="testerStatus==3" >
				
				<span >注：</span>
				<span style="color:#fa3534">{{testerdata.auditOpinion?testerdata.auditOpinion:''}}，</span>
				<span>审核未能通过，请完善后再提交</span>
			</view>
		</view>
		<view class="bottbtn" v-if="testerStatus==0"  @click="resource">确定</view>
		<!-- <view class="bottbtn" v-if="testerStatus==1" style="background: linear-gradient(90deg, #e8a034,#ff9900)">审核中</view> -->
		<view class="bottbtn" v-if="testerStatus==2" style="background: #909399">已认证</view>
		<view class="bottbtn" v-if="testerStatus==3"  @click="resource">修改</view>
		<view style="height:10px"></view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cityshow:false,
				certobj:{applyId:'',name:'',idNumber:'',city:'',certificateUrl:'',testSkills:'',workExperience:''},
				wxUserInfo:null,
				headers:{
					Authorization:'Bearer '+uni.getStorageSync('accessToken'),
					
				},
				testerStatus:'',
				istest:false,
				testerdata:null,
				
				certRules: {
					name: [{required: true, message: '请输入姓名', trigger: 'blur',},
					{max: 20, message: '最多输入20个中文', trigger: 'blur' },
					{
					  pattern:
					     /^(?:[\u4e00-\u9fa5·]{2,16})$/,
					  message: "请输入中文",
					  trigger: "blur",
					},],
					idNumber: [{ required: true, message: '请输入身份证号', trigger: 'blur'},
					  {
					    pattern:
					      /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
					    message: "请输入正确的身份证号码",
					    trigger: "blur",
					  },
					  {max:18, message: '身份证长度为18', trigger: 'blur' },
					  {min:18, message: '身份证长度为18', trigger: 'blur' },
					],
					
				},
				
			}
		},
		onShow() {
			
			
		},
		onReady(){
			this.$refs.certobj.setRules(this.certRules);
		},
		onLoad() {
			// /tester/cert/apply/{userId}
			this.wxUserInfo = uni.getStorageSync('wxUserInfo');
			let userId=this.wxUserInfo.userId
			this.http.quickGet(`/tester/cert/apply/${userId}`,true).then(res=>{
				this.testerdata=res.data.data;
				if(this.testerdata){
					let {applyId,name,idNumber}=this.testerdata;
					this.certobj={applyId,name,idNumber}
				}
				if(this.testerdata){
					if(this.testerdata.status==0){
						this.testerStatus=3
						this.istest=false
					}else if(this.testerdata.status==1){
						this.testerStatus=2
						this.istest=true
					}else if(this.testerdata.status==2){
						this.testerStatus=3
					}else{
						this.testerStatus=0
					}
				}
				
			})
		
		},
		computed: {
		  
		  },
		methods: {
			resource(){
				this.$refs.certobj.validate(valid => {
					if (valid) { 
						let data={
							applyId:this.certobj.applyId,
							userId:this.wxUserInfo.userId,
							name:this.certobj.name,
							idNumber:this.certobj.idNumber,
						}
						// return;
						if(this.testerStatus==0){
							// return;/tester/cert/update
							this.http.quickPost(`/tester/cert/apply`,data,true).then(res=>{
								if(res.data.code==200){
									this.$refs.uToast.show({
										title: '认证成功',
										type: 'success',
										url: '/pages/personal/personal',
										isTab:true,
									})
								} else {
									this.$refs.uToast.show({
										title: res.data.msg,
										type: 'error',
										isTab:true,
									})
								}
							})
						}else{
							this.http.quickPost(`/tester/cert/update`,data,true).then(res=>{
								if(res.data.code==200){
									this.$refs.uToast.show({
										title: '认证成功',
										type: 'success',
										url: '/pages/personal/personal',
										isTab:true,
									})
								}else{
									this.$refs.uToast.show({
										title: res.data.msg,
										type: 'error',
										isTab:true,
									})
								}
							})
						}
					}else{
						console.log('验证失败',this.certobj)
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background: #FFFFFF!important;
	}
	.navTab{
		padding:13px 20px 13px 20px;
		
	}
	.sinput{
		display: flex;
		align-items: center;
		/* height: 50px; */
	}
	.u-form-left__content__label{
		color:#808080!important;
	}
	.sintitle{
		display: flex;
		align-items: center;
		/* height: 50px; */
		background: #F2F4F7;
		/* background:#20529c; */
		border-radius: 4rpx;
		padding:7px 15px; 
	}
	.sintitle img{
		width:20px;
		height:18px;
		margin-right:5px;
	}
	.sintitle p{
		font-size: 15px;
		color:#000000;
		font-weight: bold;
	}
	.sinput .u-input{
		
		height:35px;
		border-bottom: 1px solid #EBEBEB!important;
		
		
	}
	.sinput p{
		color: #808080;
	}
	.bottbtn{
		width:94vw;
		margin:30px 3vw 15px 3vw;
		height:75rpx;	
		background: linear-gradient(90deg, #5EA6FD, #1A81F9);
		border-radius:43rpx;
		text-align: center;
		line-height:75rpx;
		color: #FFFFFF;
		font-size: 33rpx;
		/* margin-left:13px; */
	}
	.sinputrt{
		display: flex;
		/* align-items: center; */
		/* height: 50px; */
		padding: 10px 0px;
	}
	.sinputrt .u-input{
		/* width:75vw; */
		height:100px;
		border: 1px solid #E6E6E6;
		background: #FFFFFF;
		border-radius: 10rpx 10rpx 0rpx 0rpx;
		padding-left: 10px!important;
	}
	.u-list-item{
		margin:0!important;
		zIndex:0!important;
	}
	.slot-btn {
		width:200rpx;
		height:0rpx;
		zIndex:99;
		/* display: flex;
		justify-content: center;
		align-items: center;
		background: rgb(244, 245, 246);
		border-radius: 10rpx; */
	}

	.slot-btn__hover {
		background-color: rgb(235, 236, 238);
	}
	.u-form-item{
		margin-bottom:-5px;
		color: #808080!important;
	}
	.u-form{
		margin-left: 20px;
	}
	.u-list-item{
		margin: 0 !important;
		background: transparent!important;
		color:transparent!important;
	}
		
		.upliacla{
			width: 100px;
			height: 100px;
			/* line-height:100px; */
			border-radius: 4px;
			background: #f4f5f6;
			color:#606266;
			display:flex;
			flex-direction: column;
			
			align-items: center;
			justify-content: center;
			
		}
		.wuploa{
			/* width: 100px;
			height: 100px;
			line-height: 100px;
			font-size: 12px;
			border: 1px solid #E6E6E6;
			text-align: center;
			border-radius: 4px; */
		}
</style>
