<template>
  <view class="addbox">
	  <uni-forms ref="form" :rules="rules" :modelValue="datainfo">
	  		  <!-- 家长 -->
			<view class="ftit">基本信息</view>
			<view class="fbox">
				<!-- 选择学生 -->
				<picker range-key="dictLabel" v-if="roles!='parents'&&pagetype=='add'" :range="classlist"  :value="classidx"  @change="bindDateChangee">
					<uni-forms-item name="className"  label="班级">
						<view class="f15 flex1 txr co16" v-if="datainfo.className" >{{datainfo.className}}</view>
						<view class="f15 flex1 txr coa" v-else >请选择班级</view>
						<image :src="rimg" class="ilrmgr"></image>
					</uni-forms-item>
				</picker>
				<picker range-key="dictLabel" :disabled="pagetype=='update'||!stuflag" :range="studentlist"  :value="nameidx"  @change="bindDateChangef">
					<uni-forms-item name="name" :disabled="pagetype=='update'||!stuflag" required  label="姓名">
						<view class="f15 flex1 txr co16" v-if="datainfo.name" >{{datainfo.name}}</view>
						<view class="f15 flex1 txr coa" v-else >请选择姓名</view>
						<image :src="rimg" class="ilrmgr"></image>
					</uni-forms-item>
				</picker>
				<uni-forms-item label="身份证号"  name="idCard">
					<uni-easyinput :inputBorder="false" v-model="datainfo.idCard" @blur="getIdcardInfo"  placeholder="请输入身份证号">
					</uni-easyinput>
				</uni-forms-item>
				<!-- <uni-forms-item label="姓名" required name="name">
					<uni-easyinput :inputBorder="false" v-model="datainfo.name" placeholder="请输入姓名">
					</uni-easyinput>
				</uni-forms-item> -->
				<picker range-key="text" :range="sexrange"  :value="sexidx"  @change="bindDateChange">
					<uni-forms-item name="sex" required  label="性别">
						<view class="f15 flex1 txr co16" v-if="datainfo.sex" >{{datainfo.sex==1?'男':'女'}}</view>
						<view class="f15 flex1 txr coa" v-else >请选择性别</view>
						<image :src="rimg" class="ilrmgr"></image>
					</uni-forms-item>
				</picker>
				<uni-forms-item label="年龄"  name="age">
					<uni-easyinput :inputBorder="false" v-model="datainfo.age" placeholder="请输入年龄">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="民族"  name="familyName">
					<uni-easyinput :inputBorder="false" v-model="datainfo.familyName" placeholder="请输入民族">
					</uni-easyinput>
				</uni-forms-item>
				<picker range-key="dictLabel" :range="outlook"  :value="lookidx"  @change="bindDateChangea">
					<uni-forms-item name="politicalStatus"  label="政治面貌">
						<view class="f15 flex1 txr" :class="datainfo.politicalStatus?'co16':'coa'">{{datainfo.politicalStatus||'请选择政治面貌'}}</view>
						<image :src="rimg" class="ilrmgr"></image>
					</uni-forms-item>
				</picker>
				<picker range-key="dictLabel" :range="schoolval"  :value="schoolidx"  @change="bindDateChangeb">
					<uni-forms-item name="school"  label="学校">
						<view class="f15 flex1 txr" :class="datainfo.school?'co16':'coa'">{{datainfo.school||'请选择学校名称'}}</view>
					</uni-forms-item>
				</picker>
				<uni-forms-item label="学号"  name="studentNumber">
					<uni-easyinput :inputBorder="false" v-model="datainfo.studentNumber" placeholder="请输入学号">
					</uni-easyinput>
				</uni-forms-item>
			</view>
			<view class="ftit">照片信息</view>
			<view class="fbox">
				<uni-forms-item label="证件照"  name="identificationPhoto">
					<view class="flex1"></view>
					<view class="imgs">
						<view class="photos" v-for="(item,index) in zjfile" :key='index' @click="getPreview(zjfile,index)">
							<image :src="baseUrl+item" class="addimg"></image>
							<image :src="delimg" class="del" @click.stop="delimgFn('zj',index)" ></image>
						</view>
						<image :src="addimg" class="photos" v-if="zjfile.length<9" @click.stop="getphotoFn('zj')"></image>
					</view>
					
				</uni-forms-item>
				<uni-forms-item label="门禁照"  name="entrancePermit">
					<view class="flex1"></view>
					<view class="imgs">
						<view class="photos" v-for="(item,index) in mjfile" :key='index' @click="getPreview(mjfile,index)">
							<image :src="baseUrl+item" class="addimg"></image>
							<image :src="delimg" class="del" @click.stop="delimgFn('mj',index)" ></image>
						</view>
						<image :src="addimg" class="photos" v-if="mjfile.length<9" @click.stop="getphotoFn('mj')"></image>
					</view>
				</uni-forms-item>
			</view>
			<view class="ftit">其他信息</view>
			<view class="fbox">
				<uni-forms-item label="身高"  name="height">
					<uni-easyinput :inputBorder="false" :disabled="pagetype=='update'" v-model="datainfo.height" placeholder="请输入身高">
					</uni-easyinput>
					<view class="f16 co16 ml6">cm</view>
				</uni-forms-item>
				<uni-forms-item label="体重"  name="weight">
					<uni-easyinput :inputBorder="false" :disabled="pagetype=='update'" v-model="datainfo.weight" placeholder="请输入体重">
					</uni-easyinput>
					<view class="f16 co16 ml6">kg</view>
				</uni-forms-item>
				<!-- <uni-forms-item label="血型"  name="bloodType">
					<uni-easyinput :inputBorder="false" v-model="datainfo.bloodType" placeholder="请输入血型">
					</uni-easyinput>
				</uni-forms-item> -->
				<picker range-key="dictLabel" :range="bloodrange"  :value="bloodidx"  @change="bindDateChangeg">
					<uni-forms-item name="bloodType"  label="血型">
						<view class="f15 flex1 txr" :class="datainfo.bloodType?'co16':'coa'">{{datainfo.bloodType||'请选择血型'}}</view>
						<image :src="rimg" class="ilrmgr"></image>
					</uni-forms-item>
				</picker>
			</view>
			<view class="ftit">视力信息</view>
			<view class="fbox">
				<uni-forms-item label="是否近视"  name="isNearsightedness">
					<uni-data-checkbox v-model="datainfo.isNearsightedness" :localdata="isjinshi"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="近视度数"  name="degreeMyopia">
					<uni-easyinput :inputBorder="false" v-model="datainfo.degreeMyopia" placeholder="请输入度数，例:左300 右200">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="是否远视"  name="isFarsightedness">
					<uni-data-checkbox v-model="datainfo.isFarsightedness" :localdata="isjinshi"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="远视度数"  name="farsightedness">
					<uni-easyinput :inputBorder="false" v-model="datainfo.farsightedness" placeholder="请输入度数，例:左300 右200">
					</uni-easyinput>
				</uni-forms-item>
			</view>
			<view class="ftit">健康信息</view>
			<view class="fbox">
				<picker range-key="dictLabel" :range="healthrange"  :value="healthidx"  @change="bindDateChangec">
					<uni-forms-item name="health"   label="健康状态">
						<view class="f15 flex1 txr co16" v-if="datainfo.health" >{{datainfo.health}}</view>
						<view class="f15 flex1 txr coa" v-else >请选择健康状态</view>
						<image :src="rimg" class="ilrmgr"></image>
					</uni-forms-item>
				</picker>
				<uni-forms-item label="有无过往病史"  name="isMedicalHistory">
					<uni-data-checkbox v-model="datainfo.isMedicalHistory" :localdata="ynrange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="病史描述"  name="medicalDescription">
					<view class="comboxl">
						<textarea placeholder="请输入病史描述详情"  v-model="datainfo.medicalDescription" placeholder-style="color:#aaa;" :auto-height="autoHeight"  ></textarea>
					</view>
				</uni-forms-item>
				<picker range-key="dictLabel" :disabled="pagetype=='update'" :range="xlhealthrange"  :value="mindidx"  @change="bindDateChanged">
					<uni-forms-item name="mind"  label="心理健康状态">
						<view :class="pagetype=='update'?'is_disabled':''" class="flexc flex1">
							<view class="f15 flex1 txr co16"  v-if="datainfo.mind" >{{datainfo.mind}}</view>
							<view class="f15 flex1 txr coa" :class="pagetype=='update'?'is_disabled':''"  v-else >请选择心理健康状态</view>
							<image :src="rimg" class="ilrmgr"></image>
						</view>
						
					</uni-forms-item>
				</picker>
				<!-- <uni-forms-item label="心理健康状态"  name="health">
					<view class="health flexcc">
						<view class="flexc pl8 ml2" @click="heaidx=1">
							<image :src="mooda" v-if="heaidx==1"></image>
							<image :src="moodan" v-else></image>
							愉悦
						</view>
						<view class="flexc pl8 ml2" @click="heaidx=2">
							<image :src="moodb" v-if="heaidx==2"></image>
							<image :src="moodbn" v-else></image>
							难过
						</view>
						<view class="flexc pl8 ml2" @click="heaidx=3">
							<image :src="moodc" v-if="heaidx==3"></image>
							<image :src="moodcn" v-else></image>
							生病
						</view>
					</view>
				</uni-forms-item> -->
				<uni-forms-item label="心理健康描述"  name="psychologicalDescription">
					<view class="comboxl" :class="pagetype=='update'?'is_disabled':''">
						<textarea placeholder="请输入心理健康描述详情" placeholder-style="color:#aaa;"  :disabled="pagetype=='update'"  v-model="datainfo.psychologicalDescription" :auto-height="autoHeight"  ></textarea>
					</view>
				</uni-forms-item>
			</view>
			<view class="ftit">家庭信息</view>
			<view class="fbox">
				<uni-forms-item label="是否贫困"  name="isPoverty">
					<uni-data-checkbox v-model="datainfo.isPoverty" :localdata="ynrange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="是否留守儿童"  name="isLset">
					<uni-data-checkbox v-model="datainfo.isLset" :localdata="ynrange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="居住地址"  name="address" >
					<view @click="getMapFn" class="flexc flex1">
						<view class="flex1 f15 txr" :class="datainfo.address?'co16':'coa'">{{datainfo.address||'请选择居住地址'}}</view>
						<image :src="rimg" class="ilrmgr"></image>
					</view>
				</uni-forms-item>
				<!--  -->
				<uni-forms-item label="父亲姓名"  name="fatherName">
					<uni-easyinput :inputBorder="false" v-model="datainfo.fatherName" placeholder="请输入父亲姓名">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="联系方式"  name="fatherTelephone">
					<uni-easyinput :inputBorder="false" v-model="datainfo.fatherTelephone" placeholder="请输入联系方式">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="母亲姓名"  name="motherName">
					<uni-easyinput :inputBorder="false" v-model="datainfo.motherName" placeholder="请输入母亲姓名">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="联系方式"  name="motherTelephone">
					<uni-easyinput :inputBorder="false" v-model="datainfo.motherTelephone" placeholder="请输入联系方式">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="紧急联系人"  name="emergencyContact">
					<uni-easyinput :inputBorder="false" v-model="datainfo.emergencyContact" placeholder="请输入紧急联系人姓名">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="紧急联系方式"  name="emergencyContactTelephone">
					<uni-easyinput :inputBorder="false" v-model="datainfo.emergencyContactTelephone" placeholder="请输入紧急联系方式">
					</uni-easyinput>
				</uni-forms-item>
			</view>
			<view class="fbtns">
				<view class="rebtn" @click="getSubmit">确认</view>
			</view>
			
	  </uni-forms>
  </view>
</template>

<script>
	// import tabSearch from "@/components/toptab/search.vue"
	import config from '@/config'
	const baseUrl = config.baseUrl
	import {uploadmore,selectDictLabel} from '@/utils/common.js'
	import {getDeptList,getselfList} from "@/api/mine/mine.js"
	import {getDictionaryFn} from '@/api/mine/register.js'
	import {getstuDetFn,getstuAddtFn,getstunoListFn,getstuPutFn} from "@/api/mine/files.js"
  export default {
	components:{},
	data(){
		return{
			// adddj
			addimg:require("@/mine/static/score/addd.png"),
			mooda:require("@/mine/static/score/mooda.png"),
			moodan:require("@/mine/static/score/moodan.png"),
			moodb:require("@/mine/static/score/moodb.png"),
			moodbn:require("@/mine/static/score/moodbn.png"),
			moodc:require("@/mine/static/score/moodc.png"),
			moodcn:require("@/mine/static/score/moodcn.png"),
			delimg: require("@/static/images/del.png"),
			rimg:require("@/mine/static/score/rimg.png"),
			heaidx:1,
			date:'',
			baseUrl:'',
			sexrange:[{"val": 1,"text":"男"},{"val":2,"text":"女"}],// 性别
			ynrange:[{"value": 1,"text": "是"},{"value": 2,"text": "否"}],
			zjfile:[],
			mjfile:[],
			autoHeight:true,
			bjrange: [{"value": 1,"text": "有"	},{"value": 2,"text": "无"}],
			rules: {
			  name: {rules: [{required: true,errorMessage: '请选择姓名'}]},
			  sex: {rules: [{required: true,errorMessage: '请选择性别'}]},
			  // subjectClass: {rules: [{required: true,errorMessage: '请选择调课班级'}]},
			  // subject: {rules: [{required: true,errorMessage: '请选择调课科目'}]},
			  // beSubject: {rules: [{required: true,errorMessage: '请选择被调科目'}]},
			  // week: {rules: [{required: true,errorMessage: '请选择时间(星期)'}]},
			},
			datainfo:{
				 "studentId":"",//学生id
				  "name":"",//姓名
				  "sex":"",//性别(1：男，2：女)
				  "age":"",//年龄
				  "familyName":"",//民族
				  "school":"",//学校(汉字)
				  "studentNumber":"",//学号
				  "idCard":"",//身份证号
				  "height":"",//身高
				  "weight":"",//体重
				  "bloodType":"",//血型
				  "politicalStatus":"",//政治面貌（字典值：political_outlook）
				  "identificationPhoto":"",//证件照(地址)
				  "entrancePermit":"",//门禁照(地址)
				  "fatherName":"",//父亲
				  "fatherTelephone":"",//父亲联系方式
				  "motherName":"",//母亲
				  "motherTelephone":"",//母亲联系方式
				  "emergencyContact":"",//紧急
				  "emergencyContactTelephone":"",//紧急联系方式
				  "address":"",//居住地址
				  "isNearsightedness":'',//近视,
				  "psychologicalDescription":'',
				  "isFarsightedness":'',//远视,
				  "farsightedness":'',
				  'health':'',
				  "mind":'',
				  "isMedicalHistory":'',
				  "medicalDescription":'',
				  "classId":'',
				  "className":''
				  
			},
			pagetype:'add',
			stulist:'',
			schoolval:[],
			outlook:[],
			isjinshi:[],
			healthrange:[],
			xlhealthrange:[],
			bloodrange:[],
			bloodidx:0,
			sexidx:0,
			lookidx:0,
			schoolidx:0,
			healthidx:0,
			mindidx:0,
			id:'',
			address:{},
			classlist:[],//班级
			roles:'',
			classidx:0,
			nameidx:0,
			studentlist:[],
			schoolId:'',
			stuflag:true
		}
	},
	onUnload(){
		uni.$off('refreshaddr')
	},
	onLoad: function(e) {
		var that=this;
		uni.$on('refreshaddr',(e) => {
			var addr=JSON.parse(JSON.stringify(e))
			this.datainfo.address=e.address
			this.datainfo.longitude=e.lng
			this.datainfo.latitude=e.lat
		})
		this.pagetype=e.type||'add';
		this.baseUrl=baseUrl;
		this.init()
		this.getDeptListFn()
		if(e.type=='update'){
			this.id=e.id
			this.getDataFn()
		}else{
			var roles=this.$store.state.user.choseroles;
			this.roles=roles;
			if(roles=='parents'){
				var newArr=this.$store.state.user.student;
				if(newArr&&newArr.length){
					if(newArr.length>1){
						this.studentlist = newArr.map(v => {
							return {
								dictLabel:v.studentName,
								dictValue: v.id,
								classId:v.classId,
								className:v.className
							}
						})
					}else{
						// 一个娃
						this.datainfo.name=newArr[0].studentName
						this.datainfo.studentId=newArr[0].id
						this.datainfo.classId=newArr[0].classId
						this.datainfo.className=newArr[0].className
						this.stuflag=false;
					}
				}
			}else if(roles=='teacher'){
				var id=this.$store.state.user.schoolId;
				this.schoolId=id;
				this.getselfList(id)
			}else{
				this.schoolId=this.$store.state.user.deptId;
				this.getselfList(0)
			}
		}
	},
	methods:{
		getselfList(id){
			var params={
				parentId:id,
			}
			params['params[role]']=this.$store.state.user.choseroles
			getselfList(params).then(res=>{
				if(res.code==200){
					var newArr=res.data;
					if(newArr&&newArr.length){
						this.classlist = newArr.map(v => {
							return {
								dictLabel: v.deptName,
								dictValue: v.deptId,
							}
						})
					}
				}else{
					this.$toast(res.msg)
				}
			})
		},
		getMapFn(){
			// #ifdef APP-PLUS
			if(this.datainfo.address){
				this.$tab.navigateTo('/mine/pages/files/maps?type=update&lng='+this.datainfo.longitude+'&lat='+this.datainfo.latitude+'&address='+this.datainfo.address)
			}else{
				this.$tab.navigateTo('/mine/pages/files/maps')
			}
			// #endif
			// #ifndef APP-PLUS
			if(this.datainfo.address){
				this.$tab.navigateTo('/mine/pages/files/map?type=update&lng='+this.datainfo.longitude+'&lat='+this.datainfo.latitude+'&address='+this.datainfo.address)
			}else{
				this.$tab.navigateTo('/mine/pages/files/map')
			}
			
			// #endif
		},
		getDataFn() {
			getstuDetFn(this.id).then(res => {
				if (res.code == 200) {
					this.datainfo = res.data;
					if(res.data.isNearsightedness){
						this.datainfo.isNearsightedness=Number(res.data.isNearsightedness)
					}
					if(res.data.isLset){
						this.datainfo.isLset=Number(res.data.isLset)
					}
					if(res.data.isPoverty){
						this.datainfo.isPoverty=Number(res.data.isPoverty)
					}
					if(res.data.isMedicalHistory){
						this.datainfo.isMedicalHistory=Number(res.data.isMedicalHistory)
					}
					if(res.data.identificationPhoto){
						this.zjfile=res.data.identificationPhoto.split(',')
					}else{
						this.zjfile=[];
					}
					if(res.data.entrancePermit){
						this.mjfile=res.data.entrancePermit.split(',')
					}else{
						this.mjfile=[];
					}
					if(res.data.sex){
						this.sexidx=res.data.sex==1?0:1
					}
					// 政治面貌
					if(res.data.politicalStatus){
						for(var i=0;i<this.outlook.length;i++){
							if(this.outlook[i].dictLabel==res.data.politicalStatus){
								this.lookidx=Number(i)
								break;
							}
						}
					}
					if(res.data.school){
						for(var i=0;i<this.schoolval.length;i++){
							if(this.schoolval[i].dictLabel==res.data.school){
								this.schoolidx=Number(i)
								break;
							}
						}
					}
					if(res.data.health){
						for(var i=0;i<this.healthrange.length;i++){
							if(this.healthrange[i].dictLabel==res.data.health){
								this.healthidx=Number(i)
								break;
							}
						}
					}
					if(res.data.mind){
						for(var i=0;i<this.xlhealthrange.length;i++){
							if(this.xlhealthrange[i].dictLabel==res.data.mind){
								this.mindidx=Number(i)
								break;
							}
						}
					}
					
					
				} else {
					this.$toast(res.msg)
				}
			})
		},
		go(idCard) {
			let sex = null;
			let birth = null;
			let myDate = new Date();
			let month = myDate.getMonth() + 1;
			let day = myDate.getDate();
			let age = 0;
							
			if (idCard.length === 18) {
			  age = myDate.getFullYear() - idCard.substring(6, 10) - 1;
			  sex = idCard.substring(16, 17);
			  birth = idCard.substring(6, 10) + "-" + idCard.substring(10, 12) + "-" + idCard.substring(12, 14);
			  if (idCard.substring(10, 12) < month || idCard.substring(10, 12) === month && idCard.substring(12, 14) <= day)
			    age++;
							
			}
			if (idCard.length === 15) {
			  age = myDate.getFullYear() - idCard.substring(6, 8) - 1901;
			  sex = idCard.substring(13, 14);
			  birth = "19" + idCard.substring(6, 8) + "-" + idCard.substring(8, 10) + "-" + idCard.substring(10, 12);
			  if (idCard.substring(8, 10) < month || idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day)
			    age++;
			}			
			if (sex % 2 === 0) sex = '2';
			else sex = '1';
			this.datainfo.sex = sex
			this.datainfo.age = age
			return {
			  age,
			  sex,
			  birth
			}
		},
		/* 上传后端获取身份证信息 */
		getIdcardInfo(val) {
			var idCard=this.datainfo.idCard;
			if(!idCard){
				return
			}
			// 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
			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(idCard) || _IDre15.test(idCard)) {
				this.go(idCard)		
			} else {
						
			}
		},
		getClassFn(){
			var that=this;
			var roles=that.$store.state.user.choseroles;
			that.roles=roles;
			if(roles=='parents'){
				this.$store.dispatch('GetInforoles').then(resd => {
					if(resd.code==200){
						var res=resd.data;
						if(res.user&&res.user.parentsStudent&&res.user.parentsStudent.length){
							that.stulist = res.user.parentsStudent
						}
					}
				})
			}
		},
		init(){
			// 政治面貌
			getDictionaryFn('political_outlook').then(res=>{
				if(res.code==200){
					this.outlook = res.data.map(v => {
						return {
							dictLabel: v.dictLabel,
							dictValue: v.dictValue
						}
					})
				}
			})
			//近视
			getDictionaryFn('isjinshi').then(res=>{
				if(res.code==200){
					this.isjinshi = res.data.map(v => {
						return {
							text: v.dictLabel,
							value: v.dictValue
						}
					})
				}
			})
			//健康状态 
			getDictionaryFn('health_status').then(res=>{
				if(res.code==200){
					this.healthrange = res.data.map(v => {
						return {
							dictLabel: v.dictLabel,
							dictValue:v.dictValue
						}
					})
				}
			})
			//心理健康状态
			getDictionaryFn('psychology').then(res=>{
				if(res.code==200){
					this.xlhealthrange = res.data.map(v => {
						return {
							dictLabel: v.dictLabel,
							dictValue: v.dictValue
						}
					})
				}
			})
			// 血型
			getDictionaryFn('blood_type').then(res=>{
				if(res.code==200){
					this.bloodrange = res.data.map(v => {
						return {
							dictLabel: v.dictLabel,
							dictValue: v.dictValue
						}
					})
				}
			})
		},
		// 学校列表
		getDeptListFn(){
			var params={
				parentId:0
			}
			getDeptList(0).then(res=>{
				if(res.code==200){
					this.schoolval = res.data.map(v => {
						return {
							dictLabel: v.deptName,
							dictValue:v.deptId
						}
					})
				}else{
					this.$toast(res.msg)
				}
			})
		},
		getstunoListFn(){
			var params={
				classId:this.datainfo.classId
			}
			params['params[role]']=this.$store.state.user.choseroles
			getstunoListFn(params).then(res=>{
				if(res.code==200){
					this.studentlist = res.rows.map(v => {
						return {
							dictLabel: v.studentName,
							dictValue: v.id,
							classId:v.classId
						}
					})
				}
			})
		},
		getSubmit(){
			var that = this;
			this.$refs.form.validate().then(res => {
				var params = JSON.parse(JSON.stringify(this.datainfo))
				if (this.pagetype == 'add') {
					if(params.idCard){
						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(params.idCard) || _IDre15.test(params.idCard)) {
						}else{
							this.$toast('请输入正确身份证号')
							return
						}
					}
					// 验证手机号
					let regphone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
					if(params.fatherTelephone&&!regphone.test(params.fatherTelephone)){
						this.$toast('请输入正确的父亲联系方式')
						return
					}
					if(params.motherTelephone&&!regphone.test(params.motherTelephone)){
						this.$toast('请输入正确的母亲联系方式')
						return
					}
					if(params.emergencyContactTelephone&&!regphone.test(params.emergencyContactTelephone)){
						this.$toast('请输入正确的紧急联系方式')
						return
					}
					getstuAddtFn(params).then(res => {
						if (res.code == 200) {
							that.$toast('新增成功')
							setTimeout(function() {
								uni.$emit('refreshdalist');
								uni.navigateBack({
									delta:1
								})
							}, 1500)
						} else {
							this.$toast(res.msg)
						}
					})
				} else {
					if(params.idCard){
						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(params.idCard) || _IDre15.test(params.idCard)) {
						}else{
							this.$toast('请输入正确身份证号')
							return
						}
					}
					// 验证手机号
					let regphone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
					if(params.fatherTelephone&&!regphone.test(params.fatherTelephone)){
						this.$toast('请输入正确的父亲联系方式')
						return
					}
					if(params.motherTelephone&&!regphone.test(params.motherTelephone)){
						this.$toast('请输入正确的母亲联系方式')
						return
					}
					getstuPutFn(params).then(res => {
						if (res.code == 200) {
							that.$toast('修改成功')
							setTimeout(function() {
								uni.$emit('refreshdadetail');
								uni.$emit('refreshdalist');
								uni.navigateBack({
									delta:1
								})
							}, 1500)
						} else {
							this.$toast(res.msg)
						}
					})
				}
			})
		},
		bindDateChange(e){
			var idx=e.detail.value
			this.datainfo.sex=this.sexrange[idx].val
		},
		bindDateChangea(e){
			var idx=e.detail.value
			this.datainfo.politicalStatus=this.outlook[idx].dictLabel
		},
		bindDateChangeb(e){
			var idx=e.detail.value
			this.datainfo.school=this.schoolval[idx].dictLabel
		},
		bindDateChangec(e){
			var idx=e.detail.value
			this.datainfo.health=this.healthrange[idx].dictLabel
		},
		bindDateChanged(e){
			var idx=e.detail.value
			this.datainfo.mind=this.xlhealthrange[idx].dictLabel
		},
		bindDateChangee(e){
			var idx=e.detail.value
			this.datainfo.className=this.classlist[idx].dictLabel;
			this.datainfo.classId=this.classlist[idx].dictValue;
			this.datainfo.name='';
			this.datainfo.studentId='';
			this.getstunoListFn()
		},
		bindDateChangef(e){
			var idx=e.detail.value
			this.datainfo.name=this.studentlist[idx].dictLabel
			this.datainfo.studentId=this.studentlist[idx].dictValue
		},
		bindDateChangeg(e){
			var idx=e.detail.value
			this.datainfo.bloodType=this.bloodrange[idx].dictLabel
			// this.datainfo.studentId=this.studentlist[idx].dictValue
		},
		// 查看照片
		getPreview(iurl,idx) {
			var newArr=[];
			iurl.forEach(ite=>{
				var ds=this.baseUrl+ite
				newArr.push(ds)
			})
			uni.previewImage({
				urls: newArr,
				current:idx,
				success: function(data) {
					
				},
				fail: function(err) {
					console.log(err.errMsg);
				}
			});
		},
		delimgFn(e,idx){
			var that = this;
			if(e=='zj'){
				that.zjfile.splice(idx,1);
				this.datainfo.identificationPhoto=that.zjfile.join(',')
			}else{
				that.mjfile.splice(idx,1);
				this.datainfo.entrancePermit=that.mjfile.join(',')
			}
			
		},
		getphotoFn(e){
			let that = this;
			let file =[],count=9
			if(e=='zj'){
				file = that.zjfile;
				count=9
			}else{
				file = that.mjfile;
				count=9
			}
			if(file.length < count){
				uni.chooseImage({
					count: count - parseInt(file.length),
					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(',')
								}else{
									that.mjfile = that.mjfile.concat(rs);
									that.datainfo.entrancePermit=that.mjfile.join(',')
								}
								// console.log(that.datainfo.image,85)
							})	
						}
					}
				});
			}
		},
	},
	
  }
</script>

<style lang="scss" scoped>
.addbox{padding: 24rpx 36rpx 180rpx;}
.ftit{font-size: 30rpx;font-weight: 500;color: #666666;padding: 8rpx;margin-bottom: 16rpx;}
.fbox{background: #FFFFFF;border-radius: 18rpx;padding: 12rpx 0;margin-bottom: 32rpx;
	.addimg{width: 120rpx;height: 120rpx;}
}
.ilrmgr{width: 14rpx;height: 24rpx;margin-left: 20rpx;flex: 0 0 auto;}
.addbtn{height: 98rpx;width: 100%;
background: #1f57e6;
border-radius: 48rpx;display: flex;align-items: center;justify-content: center;font-size: 34rpx;font-weight: 500;
color: #FFFFFF;}
.comboxl{min-height: 70rpx;padding:15rpx 0rpx;box-sizing: border-box;line-height: 40rpx;flex: 1;
		textarea{width: 100%;font-size: 30rpx;color: #161616;text-align: right;}
	}
.imgs{display: flex;align-items: center;flex-wrap: wrap;justify-content: flex-end;
	.photos{width: 120rpx;height: 120rpx;position: relative;margin: 0 0rpx 16rpx 16rpx;
	// &:nth-child(3n){margin-left: 0;}
	.rimg{width: 100%;height: 100%;}
	.del{width: 36rpx;height: 36rpx;position: absolute;right: 0rpx;top: 0rpx;}
	}
}
.is_disabled{background-color: #f7f6f6;min-height:70rpx;display: flex;align-items: center;justify-content: flex-end;color: #d5d5d5;
	textarea{color: #d5d5d5;}
}
// 心理
.health{display: flex;align-items: center;justify-content: flex-end;flex-wrap: wrap;flex: 1;
	image{width: 36rpx;height: 36rpx;margin-right: 12rpx;font-size: 32rpx;color: #161616;flex:0 0 auto;}
}

.addbox /deep/ .uni-forms{flex: 1;}
.addbox /deep/ .uni-forms-item__label{flex: 0 0 auto;width: auto !important;font-size: 30rpx;font-weight: bold;
color: #161616;}
.addbox /deep/ .uni-forms .uni-forms-item{margin-bottom: 0;padding: 4rpx 32rpx;
	// &:nth-of-type(3){margin-bottom: 0;border-bottom: 0;}
}
.addbox /deep/  .uni-easyinput{height: 70rpx;}
// .addbox /deep/  .uni-textarea-textarea{height: auto;}
.addbox /deep/ .uni-forms-item__content{display: flex;align-items: center;flex-direction: row;}
.addbox /deep/ .uni-easyinput{flex: 1;text-align: right;}
.addbox /deep/ .uni-easyinput__placeholder-class{font-size: 30rpx;}
.addbox /deep/ .uni-easyinput__content-input{font-size: 30rpx;}
 .addbox /deep/ .uni-forms-item__error{margin-top:-12rpx;left: auto;right: 0;}
 .addbox /deep/ .uni-data-checklist .checklist-group .checklist-box{margin-right: 30rpx;}
  .addbox /deep/ .uni-data-checklist .checklist-group{justify-content: flex-end;}
</style>
