<template>
	<view class="rzbox">
		<uni-forms ref="form" :model="user">
			<view class="f15 co23 fw5">请添加申请人相关企业 <text>(可添加多个)</text></view>
			<view v-for="(ite,idx) in qylist" :key="idx" class="mt24">
				<view class="flexcc mb20">
					<view class="carbox">
						<image :src="cardq" class="img"></image>
						<view class="tit">营业执照</view>
					</view>
				</view>
				<view class="mb28">
					<view class="cardtip">企业信息会跟进上传的营业执照图片自动识别，支持手动输入。</view>
					<view class="cardtip">如果识别错误，可尝试再次拍照</view>
				</view>
				<view @click="getDel(idx)" v-if="idx!=0" style="color: red;">删除</view>
				<!-- 身份信息 -->
				<uni-forms-item label="统一社会信用代码" name="nickName">
					<uni-easyinput v-model="user.email" :inputBorder='false' placeholder="自动识别" />
				</uni-forms-item>
				<uni-forms-item label="企业名称" name="phonenumber">
					<uni-easyinput v-model="user.email" :inputBorder='false' placeholder="自动识别" />
				</uni-forms-item>
				<block v-if="zheList[idx].zheflag">
					<uni-forms-item label="企业类型" name="email">
						<uni-easyinput v-model="user.email" :inputBorder='false' placeholder="自动识别" />
					</uni-forms-item>
					<uni-forms-item label="企业地址" name="email">
						<uni-easyinput type="textarea" :autoHeight="true" v-model="user.email" :inputBorder='false'
							placeholder="自动识别" />
					</uni-forms-item>
					<uni-forms-item label="法人姓名" name="nickName">
						<uni-easyinput v-model="user.email" :inputBorder='false' placeholder="自动识别" />
					</uni-forms-item>
					<uni-forms-item label="注册资金" name="phonenumber">
						<uni-easyinput v-model="user.email" :inputBorder='false' placeholder="自动识别" />
					</uni-forms-item>
					<uni-forms-item label="成立日期" name="email">
						<uni-easyinput v-model="user.email" :inputBorder='false' placeholder="自动识别" />
					</uni-forms-item>
					<uni-forms-item label="营业期限" name="email">
						<uni-easyinput v-model="user.email" :inputBorder='false' placeholder="自动识别" />
					</uni-forms-item>
					<uni-forms-item label="经营范围" name="email">
						<uni-easyinput type="textarea" :autoHeight="true" v-model="user.email" :inputBorder='false'
							placeholder="自动识别" />
					</uni-forms-item>
				</block>
				<view class="upbox" :class="zheList[idx].zheflag?'':'act'" @click="getZheFn(idx)">
					<image :src="upimg"></image>
					<view>{{zheList[idx].zheflag?'折叠企业信息':'展开企业信息'}}</view>
				</view>
			</view>

		</uni-forms>

		<view class="rzbfot">
			<view class="rzbtns bgb" @click="getAddQyFn">
				<image :src="addqy"></image>添加企业
			</view>
			<view class="rzbtns bga" @click="getNext">提交</view>
		</view>

	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import {uploadmore} from '@/utils/common.js'
	import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
	export default {
		components: {},
		data() {
			return {
				cardq: require('@/work/static/images/prove/cardq.png'),
				addqy: require('@/work/static/images/prove/addqy.png'),
				upimg: require('@/work/static/images/up.png'),
				user: {

				},
				zheList:[{zheflag:true}],
				qylist: [{
					"schoolId": "",
					"schoolName": "",
					"classId": "",
					"className": "",
					"studentName": "",
					"studentNumber": ""
				}],
			}
		},
		methods: {
			checkPermi,
			checkRole,
			getNext() {
				this.$tab.navigateTo("/work/pages/prove/zctype")
			},
			getZheFn(idx){
				this.zheList[idx].zheflag=!this.zheList[idx].zheflag
			},
			getAddQyFn(){
				var obj = {
					"schoolId": "",
					"schoolName": "",
					"classId": "",
					"className": "",
					"studentName": "",
					"studentNumber": ""
				}
				this.qylist.push(obj);
				var zheobj={zheflag:true}
				this.zheList.push(zheobj);
			},
			getDel(idx) {
				var that = this;
				uni.showModal({
					title: '确认删除',
					content: "是否确认删除",
					cancelText: '取消删除',
					confirmText: '确认删除',
					success: function(res) {
						if (res.confirm) {
							that.qylist.splice(idx, 1)
							that.zheList.splice(idx, 1)
						} else if (res.cancel) {
							
						}
					}
				});
			},
			getaddImage(e){
				let that = this;
				let file =[],count=9
				// if(e=='zj'){
				// 	file = that.zjfile;
				// 	count=9
				// }else{
				// 	file = that.mjfile;
				// 	count=9
				// }
				uni.chooseImage({
					count: 1,
					success:function(res){
						let img= res.tempFilePaths;
						if(img.length + file.length > count){
							uni.showToast({
								title: '最多上传'+count+'张图片',
								icon: 'none',
								duration: 2000
							})
						}else{
							let imglen = res.tempFilePaths.length;
							var fuwufile = [];
							uploadmore('/common/upload',img,0,0,0,imglen,fuwufile,function(rs){
								if(e=='zj'){
									that.zjfile = that.zjfile.concat(rs);
									that.datainfo.identificationPhoto=that.zjfile.join(',')
								}
							})	
						}
					}
				});
			},
			getSubmit() {
				var that = this;
				this.$refs.form.validate().then(res => {
					var params = JSON.parse(JSON.stringify(this.datainfob))
					var list=this.classlist;
					var newArr = []
					var a=0;
					Object.keys(list).some((key) => {
						if(!list[key].studentName){
							a=1;
							this.$toast("请输入学生姓名" )
							return
						}else if(!list[key].studentNumber){
							a=1;
							this.$toast("请输入学生身份证号" )
							return	
						}else if (list[key].schoolName && list[key].className) {
							let _IDRe18 =
								/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
							let _IDre15 = /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/
							// 校验身份证：
							if (_IDRe18.test(list[key].studentNumber) || _IDre15.test(list[key].studentNumber)) {
								newArr.push(list[key])
							}else{
								a=1;
								this.$toast('请输入学生'+ list[key].studentName + "正确身份证号")
								return
							}
						} else if (list[key].schoolName && !list[key].className) {
							a=1;
							this.$toast("请选择" + list[key].schoolName + "的班级")
							return
						} else if(!list[key].schoolName){
							a=1;
							this.$toast("请选择学校")
							return
						}
					})
					if(a==1){
						return
					}
					params.registerParentsStudentList = JSON.parse(JSON.stringify(newArr))
					this.$emit('getparentsregFn',params)
					
			
			
					// this.$tab.navigateTo(`/mine/pages/mine/success`)
				})
			
			},
		}
	}
</script>

<style lang="scss" scoped>
page{
	background:#ffffff;
}
.rzbox /deep/ .uni-forms-item{min-height: 116rpx;box-sizing: border-box;display: flex;align-items: center;margin-bottom: 0;border-bottom: 2rpx solid #E6E6E6;padding:22rpx 0;}
.rzbox /deep/ .uni-forms-item__label{font-weight: bold;font-size: 30rpx;color: #222327;flex: 0 0 auto;width: auto !important;}
.rzbox /deep/ .uni-easyinput{flex: 1;text-align: right;font-size: 30rpx;color: #222327;}
.rzbox /deep/ .uni-easyinput__content-textarea{min-height: 40rpx;font-size: 30rpx;}
.rzbox /deep/ .uni-easyinput__placeholder-class{font-size: 30rpx;color: #AAAAAA;}
.rzbox /deep/ .uni-input-input{font-size: 30rpx;}
.rzbox /deep/ .uni-textarea-textarea{font-size: 30rpx;}
  
.rzbox{padding: 44rpx 34rpx 324rpx;
	.carbox{width: 320rpx;border-radius: 14rpx;overflow: hidden;
		.img{width: 320rpx;height: 216rpx;}
		.tit{width: 100%;height: 60rpx;background: #A0C6D5;text-align: center;font-weight: 500;
font-size: 26rpx;line-height: 60rpx;
color: #FFFFFF;}
	}
	.cardtip{font-weight: 500;font-size: 24rpx;color: #999999;line-height: 40rpx;}
	.inttxet{font-weight: 500;font-size: 30rpx;flex: 1;text-align: right;color: #222327;}
	.formtip{font-weight: 500;font-size: 24rpx;color: #FF6969;margin-top: 40rpx;text-align: right;}
	
	.upbox{display: flex;flex-direction: column;align-items: center;padding: 32rpx 0 28rpx;
		image{width: 30rpx;height: 26rpx;margin-bottom: 18rpx;transition: all 0.3s;}
		view{font-weight: 500;font-size: 24rpx;color: #AAAAAA;}
		&.act{
			image{transform: rotate(180deg);}
		}
	}
}
.rzbfot{
	.rzbtns{width: 100%;border-radius:10rpx;height: 100rpx;display: flex;align-items: center;justify-content: center;font-weight: bold;font-size: 30rpx;
		&.bga{background: #00A9F0;color: #FFFFFF;}
		&.bgb{background:#EBF3FF;color: $com-cd3;margin-bottom: 28rpx;
			image{width: 30rpx;height: 30rpx;margin-right: 10rpx;}
		}
	}
}
</style>
