<template>
	<view>
		<cu-custom :backUrl="'/pages/human/practice/register/RegistrationAddForm'" :isBack="false" bgColor="bg-gradual-blue" >
			<block slot="content">实习登记</block>
		</cu-custom>
		<u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm">
			<u-form-item label="姓名" borderBottom prop="name" :required="true">
			     <u--input placeholder='请填写姓名'  v-model="inputForm.name"></u--input>
			</u-form-item>


			<!-- <u-form-item label="性别" borderBottom prop="sex">
			    <jp-picker v-model="inputForm.sex" rangeKey="label" rangeValue="value" :range="$dictUtils.getDictList('sex')"></jp-picker>
			</u-form-item> -->
			
			<u-form-item label="身份证号码" borderBottom prop="idCard" :required="true">
			     <u--input placeholder='请填写身份证号码'  v-model="inputForm.idCard" @blur="idCardOnly(inputForm.idCard)"></u--input>
			</u-form-item>
      <u-form-item label="性别" borderBottom prop="sex">
        <jp-picker v-model="inputForm.sex" rangeKey="label" :disabled="true" rangeValue="value" :range="[
			        { label: '男', value: '1' },
			        { label: '女', value: '2' }
			    ]"></jp-picker>
      </u-form-item>

      <u-form-item label="年龄" borderBottom prop="age">
        <u--input placeholder='请填写年龄' :disabled="true" v-model="inputForm.age"></u--input>
      </u-form-item>

      <u-form-item label="出生日期" borderBottom prop="birthday">
        <el-date-picker
            v-model="inputForm.birthday"
            type="date"
            placeholder="选择出生日期"
            style="width:100%"
            size="default"
            placement="bottom-start"
            :disabled="true"
            clearable>
        </el-date-picker>
      </u-form-item>

      <u-form-item label="籍贯" borderBottom prop="nativePlace" :required="true"
                   :rules="[
											{required: true, message:'籍贯不能为空', trigger:'change'}
											 ]">
        <SelectTree
            ref="areaTree"
            :props="{
												  value: 'id',             // ID字段名
												  label: 'name',         // 显示名称
												  children: 'children'    // 子级字段名
											}"
            url="/system-server/sys/area/treeData"
            :value="inputForm.nativePlace"
            :clearable="true"
            size="large"
            :accordion="true"
            @getValue="(value) => {inputForm.nativePlace=value}"/>
      </u-form-item>

      <u-form-item label="民族" borderBottom prop="nation" :required="true">
        <el-select v-model="inputForm.nation" placeholder="请选择民族" clearable
                   style="width: 100%;">
          <el-option v-for="item in $dictUtils.getDictList('sys_nation')"
                     :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </u-form-item>

			<u-form-item label="政治面貌" borderBottom prop="politicalOutlook" >
<!--			     <u&#45;&#45;input placeholder='请填写政治面貌'  v-model="inputForm.politicalOutlook"></u&#45;&#45;input>-->
				<jp-picker v-model="inputForm.politicalOutlook" rangeKey="label" rangeValue="value" :range="[
						        { label: '中共党员', value: '1' },
						        { label: '中共预备党员', value: '2' },
						        { label: '共青团员', value: '3' },
						        { label: '民革党员', value: '4' },
						        { label: '民盟盟员', value: '5' },
						        { label: '民建会员', value: '6' },
						        { label: '民进会员', value: '7' },
						        { label: '农工党党员', value: '8' },
						        { label: '致公党党员', value: '9' },
						        { label: '九三学社社员', value: '10' },
						        { label: '台盟盟员', value: '11' },
						        { label: '无党派人士', value: '12' },
						        { label: '群众', value: '13' },
						    ]"></jp-picker>
			</u-form-item>
			<u-form-item label="毕业院校" borderBottom prop="graduatedFrom" :required="true">
			     <u--input placeholder='请填写毕业院校'  v-model="inputForm.graduatedFrom"></u--input>
			</u-form-item>
			<u-form-item label="专业" borderBottom prop="speciality" :required="true">
			     <u--input placeholder='请填写专业'  v-model="inputForm.speciality"></u--input>
			</u-form-item>
			<u-form-item label="联系电话" borderBottom prop="mobilePhone" :required="true">
			     <u--input placeholder='请填写联系电话'  v-model="inputForm.mobilePhone" maxlength="11" @blur="mobilePhoneOnly(inputForm.mobilePhone)"></u--input>
			</u-form-item>
			<u-form-item label="QQ号/微信号" borderBottom prop="qqNum" >
			     <u--input placeholder='请填写QQ号/微信号'  v-model="inputForm.qqNum" :maxlength="20"></u--input>
			</u-form-item>
			<u-form-item label="实习开始时间" borderBottom prop="practiceStartDay" :required="true">
				<el-date-picker
						v-model="inputForm.practiceStartDay"
						type="date"
						placeholder="选择实习开始时间"
						style="width:100%"
						size="default"
						placement="bottom-start"
						clearable>
				</el-date-picker>
			</u-form-item>
			<u-form-item label="实习结束时间" borderBottom prop="practiceCompleteDay"  :required="true">
				<el-date-picker
						v-model="inputForm.practiceCompleteDay"
						type="date"
						placeholder="选择实习结束时间"
						style="width:100%"
						size="default"
						placement="bottom-start"
						clearable>
				</el-date-picker>
			</u-form-item>
			<u-form-item label="简介" borderBottom prop="remarks">
			    <u--textarea  placeholder='请填写简介' :maxlength="200" v-model="inputForm.remarks" ></u--textarea>
			</u-form-item>
			
			 <!-- 添加按钮 -->
			      <!-- <u-form-item label="实习经验">
			        <el-button type="primary" @click="addRow">新增</el-button>
			      </u-form-item> -->
			
			      <!-- 表格 -->
			      <!-- <el-table :data="inputForm.experiences" style="width: 100%">
			        <el-table-column label="开始时间">
			          <template slot-scope="scope">
			            <el-date-picker
							v-model="scope.row.startTime"
							type="date"
							placeholder="选择开始时间"
							style="width:100%"
							size="default"
							placement="bottom-start"
							clearable>
						</el-date-picker>
			          </template>
			        </el-table-column>
			        <el-table-column label="结束时间">
			          <template slot-scope="scope">
			            <el-date-picker
							v-model="scope.row.endTime"
							type="date"
							placeholder="选择结束时间"
							style="width:100%"
							size="default"
							placement="bottom-start"
							clearable>
						</el-date-picker>
			          </template>
			        </el-table-column>
					<el-table-column label="实践单位">
					  <template slot-scope="scope">
					    <el-input  placeholder="请填写实践单位"  v-model="scope.row.practiceUnit"/>
					  </template>
					</el-table-column>
					<el-table-column label="岗位">
					  <template slot-scope="scope">
					    <el-input  placeholder="请填写岗位"  v-model="scope.row.post"/>
					  </template>
					</el-table-column> -->
			        <!-- 添加其他表格列 -->
			        <!-- <el-table-column label="操作">
			          <template slot-scope="scope">
			            <el-button @click="removeRow(scope.$index)" type="danger" icon="el-icon-delete">删除</el-button>
			          </template>
			        </el-table-column>
			      </el-table> -->
				  
				  
				  <el-row  :gutter="15" :key="index_experience" v-for="(item,index_experience) in this.inputForm.experiences">
				  	<el-col :span="24">
				  		<el-form-item label="" >
				  			<el-divider content-position="left"> 实习经验 {{index_experience + 1}}</el-divider>
				  		</el-form-item>
				  	</el-col>
				  	
				  	<el-col :span="24">
				  		<u-form-item label="开始时间" :prop="'experiences[' + index_experience + '].startTime'" :required="true"
				  					  :rules="[
				     ]">
				  			<el-date-picker
				  				v-model="inputForm.experiences[index_experience].startTime"
				  				type="date"
				  				placeholder="选择开始时间"
				  				style="width:100%"
				  				size="default"
				  				placement="bottom-start"
				  				clearable>
				  			</el-date-picker>
				  		</u-form-item>
				  	</el-col>
				  	<el-col :span="24">
				  		<u-form-item label="结束时间" :prop="'experiences[' + index_experience + '].endTime'" :required="true"
				  					  :rules="[
				  	 ]">
				  			<el-date-picker
				  				v-model="inputForm.experiences[index_experience].endTime"
				  				type="date"
				  				placeholder="选择开始时间"
				  				style="width:100%"
				  				size="default"
				  				placement="bottom-start"
				  				clearable>
				  			</el-date-picker>
				  		</u-form-item>
				  	</el-col>
					
				  	<el-col :span="24">
				  		<u-form-item label="实践单位" :prop="'experiences[' + index_experience + '].practiceUnit'" :required="true"
				  					 :rules="[
				     ]">
				  			<el-input v-model="inputForm.experiences[index_experience].practiceUnit" placeholder="请填写实践单位"     clearable></el-input>
				  		</u-form-item>
				  	</el-col>
				  
				  	<el-col :span="24">
				  		<u-form-item label="岗位" :prop="'experiences[' + index_experience + '].post'"  :required="true"
				  					 :rules="[
				     ]">
				  			<el-input v-model="inputForm.experiences[index_experience].post" placeholder="请填写岗位"     clearable></el-input>
				  		</u-form-item>
				  	</el-col>
				  
				  	<el-col :span="24" style="text-align: center">
				  		<u-form-item label="" >
				  			<el-button style="width: 100%" type="danger" @click="removeRow(index_experience)" plain>删除实习经验 {{index_experience + 1}}</el-button>
				  		</u-form-item>
				  	</el-col>
				  </el-row>
			<u-form-item label="" >
				<el-button style="width: 100%" type="primary" @click="addRow()" plain>新增实习经验</el-button>
			</u-form-item>
				  
				  
				  
				  <!--<u-form-item label="家庭成员">
					<el-button type="primary" @click="addRow2">新增</el-button>
				  </u-form-item>-->
				  
				  <!-- 表格 -->
				  <!--<el-table :data="inputForm.familyMembers" style="width: 100%">
					<el-table-column label="称呼">
					  <template slot-scope="scope">
						<el-input  placeholder="请填写称呼"  v-model="scope.row.callName"/>
					  </template>
					</el-table-column>
					<el-table-column label="姓名">
					  <template slot-scope="scope">
						<el-input  placeholder="请填写姓名"  v-model="scope.row.name"/>
					  </template>
					</el-table-column>
					<el-table-column label="联系方式">
					  <template slot-scope="scope">
						<el-input  placeholder="请填写联系方式"  v-model="scope.row.phone" @blur="checkMobile(scope.row)"/>
					  </template>
					</el-table-column>
					<el-table-column label="工作单位">
					  <template slot-scope="scope">
						<el-input  placeholder="请填写工作单位"  v-model="scope.row.workUnit"/>
					  </template>
					</el-table-column>
				    &lt;!&ndash; 添加其他表格列 &ndash;&gt;
				    <el-table-column label="操作">
				      <template slot-scope="scope">
				        <el-button @click="removeRow2(scope.$index)" type="danger" icon="el-icon-delete">删除</el-button>
				      </template>
				    </el-table-column>
				  </el-table>-->



			<el-row  :gutter="15" :key="index_family" v-for="(item,index_family) in this.inputForm.familyMembers">
				<el-col :span="24">
					<el-form-item label="" >
						<el-divider content-position="left"> 家庭成员 {{index_family + 1}}</el-divider>
					</el-form-item>
				</el-col>
				
				<el-col :span="24">
					<u-form-item label="关系" :prop="'familyMembers[' + index_family + '].callName'" :required="true"
								  :rules="[
               ]">
						<el-input v-model="inputForm.familyMembers[index_family].callName" placeholder="请填写成员关系"     clearable></el-input>
					</u-form-item>
				</el-col>
				<el-col :span="24">
					<u-form-item label="成员姓名" :prop="'familyMembers[' + index_family + '].name'" :required="true"
								  :rules="[
               ]">
						<el-input v-model="inputForm.familyMembers[index_family].name" placeholder="请填写成员姓名"     clearable></el-input>
					</u-form-item>
				</el-col>
				<el-col :span="24">
					<u-form-item label="联系方式" :prop="'familyMembers[' + index_family + '].phone'" :required="true"
								 :rules="[
               ]">
						<el-input v-model="inputForm.familyMembers[index_family].phone" placeholder="请填写联系方式"  @blur="checkMobile(scope.row)"   clearable></el-input>
					</u-form-item>
				</el-col>

				<el-col :span="24">
					<u-form-item label="工作单位" :prop="'familyMembers[' + index_family + '].workUnit'"
								 :rules="[
               ]">
						<el-input v-model="inputForm.familyMembers[index_family].workUnit" placeholder="请填写工作单位"     clearable></el-input>
					</u-form-item>
				</el-col>

				<el-col :span="24" style="text-align: center">
					<u-form-item label="" >
						<el-button style="width: 100%" type="danger" @click="removeRow2(index_family)" plain>删除家庭成员 {{index_family + 1}}</el-button>
					</u-form-item>
				</el-col>
			</el-row>

			<u-form-item label="" >
				<el-button style="width: 100%" type="primary" @click="addRow3()" plain>新增家庭成员</el-button>
			</u-form-item>
				  
				  
						  
			<u-form-item style="margin-top: 20px; text-align: center;">
				<el-button type="primary" @click="saveForm" style="width: 100%;">
					<span style="margin: 0 auto;">提交</span>
				</el-button>
			</u-form-item>
		</u--form>
	</view>
</template>

<script>
	import registerService from '@/api/human/register/RegisterService'
	import enrollmentRegistrationService from '@/api/human/enrollment/EnrollmentRegistrationService'
  import SelectTree from "@/components/treeSelect/treeSelect.vue";
	export default {
    components: {SelectTree},
		data () {
			return {
				loading: false,
				inputForm: {
					userId: '',
					practiceOffice: '',
					name: '',
					practiceUnitName: '',
					qqNum: '',
					sex: '',
					politicalOutlook: '',
					nativePlace: '',
					nation: '',
					mobilePhone: '',
					idCard: '',
					age: '',
          birthday: '',
					graduatedFrom: '',
					speciality: '',
					practiceStartDay: '',
					practiceCompleteDay: '',
					remarks: '',
					type: '',
					projectManager: '',
					experiences: [],
					familyMembers: [],
				},
				// tableData:[],// 存储表格数据
				amountKey: '',
				membersKey: '',
				rules: {
					  'sex': [
						  {
								required: true,
								message: '性别不能为空',
								trigger: ['blur', 'change']
						  }
					  ],
					  'nativePlace': [
						  {
								required: true,
								message: '出生地不能为空',
								trigger: ['blur', 'change']
						  }
					  ],
					  'nation': [
							{
								required: true,
								message: '民族不能为空',
								trigger: ['blur', 'change']
							}
					  ],
					  'graduatedFrom': [
							{
								required: true,
								message: '毕业院校不能为空',
								trigger: ['blur', 'change']
							}
					  ],
					  'speciality': [
						{
							required: true,
							message: '专业不能为空',
							trigger: ['blur', 'change']
						}
					  ],
					  'name': [
						  {
							  required: true,
							  message: '姓名不能为空',
							  trigger: ['blur', 'change']
						  }
					  ],
					  'mobilePhone': [
						  {
								required: true,
								message: '联系电话不能为空',
								trigger: ['blur', 'change']
						  }
					  ],
					'idCard': [
						{
							validator: (rule, value, callback) => this.isCardId(value, callback),
							trigger: ['blur']
						}
					],
					'qqNum': [
						{
							validator: (rule, value, callback) => this.qqNumCheck(value, callback),
							trigger: ['blur', 'change']
						}
					],
				}
			}
		},
		props: {
		  businessId: {
		    type: String,
		    default: ''
		  },
		  formReadOnly: {
		    type: Boolean,
		    default: false
		  }
		},
		watch: {
		  'businessId': {
		    handler (newVal) {
		      if (this.businessId) {
		        this.init(this.businessId)
		      } else {
		        this.$nextTick(() => {
		          // this.$refs.inputForm.reset()
		        })
		      }
		    },
		    immediate: true,
		    deep: false
		  }
		},
		methods: {
			init (id) {
			  if (id) {
				  registerService.findById(id).then((data) => {
			        this.inputForm = this.recover(this.inputForm, data)
			      })
			  }
			},
			async saveForm () {

				await registerService.findIdCardOnly(this.inputForm.idCard).then((data) => {
					if (data !== 0) {
						uni.showToast({
							title: '身份证号码已存在，请重新确认',
							icon: "none",
							duration:2000
						})
						this.inputForm.idCard = ''
					}
					
					
					if (this.isEmpty(this.inputForm.practiceStartDay)) {
						uni.showToast({
							title: '实习开始时间不能为空',
							icon: "none",
							duration:2000
						})
						throw new Error('实习开始时间不能为空')
					}
					if (this.isEmpty(this.inputForm.practiceCompleteDay)) {
						uni.showToast({
							title: '实习结束时间不能为空',
							icon: "none",
							duration:2000
						})
						throw new Error('实习结束时间不能为空')
					}
					
					
					if (this.isEmpty(this.inputForm.familyMembers)) {
						uni.showToast({
							title: '请至少填写一条家庭成员信息',
							icon: "none",
							duration:2000
						})
						throw new Error('请至少填写一条家庭成员信息')
					} else {
						console.log(this.inputForm.familyMembers)
						this.inputForm.familyMembers.forEach((item, index) => {
							if (this.isEmpty(item.callName)) {
								uni.showToast({
									title: '家庭成员明细中第' + (index + 1) + '条数据的 “关系” 不能为空',
									icon: "none",
									duration:2000
								})
								throw new Error('家庭成员明细中第' + (index + 1) + '条数据的 “关系” 不能为空')
							}
							if (this.isEmpty(item.name)) {
								uni.showToast({
									title: '家庭成员明细中第' + (index + 1) + '条数据的 “姓名” 不能为空',
									icon: "none",
									duration:2000
								})
								throw new Error('家庭成员明细中第' + (index + 1) + '条数据的 “姓名” 不能为空')
							}
							if (this.isEmpty(item.phone)) {
								uni.showToast({
									title: '家庭成员明细中第' + (index + 1) + '条数据的 “联系方式” 不能为空',
									icon: "none",
									duration:2000
								})
								throw new Error('家庭成员明细中第' + (index + 1) + '条数据的 “联系方式” 不能为空')
							}
						});

					}
				})
				await enrollmentRegistrationService.findMobilePhoneOnly(this.inputForm.mobilePhone).then((data) => {
					if (data !== 0) {
						uni.showToast({
							title: '联系电话已存在，请重新填写',
							icon: "none",
							duration:2000
						})
						this.inputForm.mobilePhone = ''
					}
				})
					//定义表单规则
				this.$refs.inputForm.validate().then(res => {
					uni.showLoading()
					this.inputForm.type = '2'
					this.inputForm.experiences.forEach(experience => {
						experience.startTime = this.formatDate(experience.startTime);
						experience.endTime = this.formatDate(experience.endTime);
					});
					
					if(this.inputForm.practiceStartDay){
					this.inputForm.practiceStartDay = this.formatDate(this.inputForm.practiceStartDay)
					}
					if(this.inputForm.practiceCompleteDay){
					this.inputForm.practiceCompleteDay = this.formatDate(this.inputForm.practiceCompleteDay)
					}
					console.log(this.inputForm)
					registerService.save(this.inputForm).then((data) => {
						// 接口调用成功，隐藏加载动画
						uni.hideLoading();
						//提交成功跳转页面
						this.$router.push('/pages/human/enrollment/registration/saveOk'); // 替换 '/new-page' 为你想要跳转的页面路径
					}).catch((e)=>{
					})
				}).catch((e)=>{
				})
			},
			addRow() {
			      // 点击新增按钮时，向表格中添加一行空数据
			      this.inputForm.experiences.push({ startTime: '', endTime: '' });
			    },
			removeRow(index) {
			  // 点击删除按钮时，从表格中移除指定行
			  // this.tableData.splice(index, 1);
			  this.inputForm.experiences.splice(index, 1);
			},
			addRow2() {
			      // 点击新增按钮时，向表格中添加一行空数据
			      this.inputForm.familyMembers.push({ startTime: '', endTime: '' });
			    },
			addRow3() {
			      // 点击新增按钮时，向表格中添加一行空数据
			      this.inputForm.familyMembers.push({ startTime: '', endTime: '' });
			    },

			removeRow2(index) {
			  // 点击删除按钮时，从表格中移除指定行
			  // this.tableData.splice(index, 1);
			  this.inputForm.familyMembers.splice(index, 1);
			},
			validatePhone (str,callback) {
				const phone = /(^(\d{3,4}-)?\d{6,8}$)|(^(\d{3,4}-)?\d{6,8}(-\d{1,5})?$)|(^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(19[0-9]{1}))+\d{8})$)/
				if (str && !phone.test(str)) {
					callback(new Error('请输入正确的电话号码'))
				} else {
					callback()
				}
			},
			formatDate(date) {
				const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
				const year = dateNew.getFullYear();
				const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
				const day = dateNew.getDate().toString().padStart(2, '0');
				return `${year}-${month}-${day}`;
			},
			isEmpty(value) {
				let result = false;
				if (value == null || value == undefined) {
					result = true;
				}
				if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
					result = true;
				}
				if (typeof value == "object" && value instanceof Array && value.length === 0) {
					result = true;
				}
				return result;
			},
			isNotEmpty (value) {
				return !this.isEmpty(value)
			},
			isCardId(code,callback) {
				let msg = "";
				const city = {
					11: "北京",
					12: "天津",
					13: "河北",
					14: "山西",
					15: "内蒙古",
					21: "辽宁",
					22: "吉林",
					23: "黑龙江 ",
					31: "上海",
					32: "江苏",
					33: "浙江",
					34: "安徽",
					35: "福建",
					36: "江西",
					37: "山东",
					41: "河南",
					42: "湖北 ",
					43: "湖南",
					44: "广东",
					45: "广西",
					46: "海南",
					50: "重庆",
					51: "四川",
					52: "贵州",
					53: "云南",
					54: "西藏 ",
					61: "陕西",
					62: "甘肃",
					63: "青海",
					64: "宁夏",
					65: "新疆",
					71: "台湾",
					81: "香港",
					82: "澳门",
					91: "国外 ",
				};
				if (!this.isNull(code)) {
					if (code.length === 18) {
						if (!code || !/(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(code)) {
							msg = "证件号码格式错误";
							this.inputForm.idCard = ''
							callback(new Error(msg));
						} else if (!city[code.substr(0, 2)]) {
							msg = "地址编码错误";
							this.inputForm.idCard = ''
							callback(new Error(msg));
						} else {
							// 18位身份证需要验证最后一位校验位
							code = code.split("");
							// ∑(ai×Wi)(mod 11)
							// 加权因子
							let factor = [
								7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2,
							];
							// 校验位
							let parity = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2, "x"];
							let sum = 0;
							let ai = 0;
							let wi = 0;
							for (let i = 0; i < 17; i++) {
								ai = code[i];
								wi = factor[i];
								sum += ai * wi;
							}
							let last = parity[sum % 11];
							if ("" + last !== "" + code[17]) {
								msg = "证件号码校验位错误";
								this.inputForm.idCard = ''
								callback(new Error(msg));
							}
						}
					} else {
						msg = "证件号码长度不为18位";
						this.inputForm.idCard = ''
						callback(new Error(msg));
					}
				} else {
					msg = "证件号码不能为空";
					this.inputForm.idCard = ''
					callback(new Error(msg));
				}
				if (msg) {
					callback();
				}
				return true;
			},
			/**
			 * 判断是否为空
			 */
			isNull(val) {
				if (val instanceof Array) {
					if (val.length === 0) return true;
				} else if (val instanceof Object) {
					if (JSON.stringify(val) === "{}") return true;
				} else {
					if (
							val === "null" ||
							val == null ||
							val === "undefined" ||
							val === undefined ||
							val === ""
					)
						return true;
					return false;
				}
				return false;
			},
			qqNumCheck(qqNum,callback) {
				//判断是否是汉字
				if (this.isNotEmpty(qqNum)) {
					const chineseRegex = /[\u4e00-\u9fa5]/;
					if (chineseRegex.test(this.inputForm.qqNum)){
						var msg = 'QQ号/微信号填写不正确，请重新填写'
						callback(new Error(msg));
					} else {
						callback();
					}
				} else {
					callback();
				}

			},
			//身份证号码唯一性判断
			idCardOnly(idCard) {
				if (this.isNotEmpty(idCard)) {
					registerService.findIdCardOnly(idCard).then((data) => {
						if (data !== 0) {
							// this.$message.error('身份证号码已存在，请重新确认')
							// this.inputForm.idCard = ''
							// throw new Error('身份证号码已存在，请重新确认')
							uni.showToast({
								title: '身份证号码已存在，请重新确认',
								icon: "none",
								duration:2000
							})
							this.inputForm.idCard = ''
						} else {
              const info = this.decomposeIdCard(idCard)
              this.inputForm.sex = info.sex
              this.inputForm.age = info.age
              this.inputForm.birthday = info.birth
              this.inputForm.nativePlace = info.nativePlace
            }
					})
				}

			},
			//联系电话唯一性判断
			mobilePhoneOnly(mobilePhone) {
				enrollmentRegistrationService.findMobilePhoneOnly(mobilePhone).then((data) => {
					if (data !== 0) {
						uni.showToast({
							title: '联系电话已存在，请重新填写',
							icon: "none",
							duration:2000
						})
						this.inputForm.mobilePhone = ''
					}
				})

			},
			checkMobile (str) {
				const phone = /(^(\d{3,4}-)?\d{6,8}$)|(^(\d{3,4}-)?\d{6,8}(-\d{1,5})?$)|(^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(19[0-9]{1}))+\d{8})$)/
				if (str && !phone.test(str.phone)) {
					uni.showToast({
						title: '联系电话填写不正确，请重新填写',
						icon: "none",
						duration:2000
					})
					str.phone = ''
				}
			},
			/**
			 * 从身份证号中获取出生日期、性别、年龄
			 * @param idCard
			 * @returns {{sex: string, birth: null, age: number}}
			 */
			decomposeIdCard(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)
					// eslint-disable-next-line no-mixed-operators
					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)
					// eslint-disable-next-line no-mixed-operators
					if (idCard.substring(8, 10) < month || idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day) age++
				}

				if (sex % 2 === 0) {
					sex = '2'  // 性别代码 1代表男，2代表女，暂时不涉及其他类型性别
				} else {
					sex = '1'
				}
        //获取户籍所在地
        const nativePlace = idCard.substring(0, 6);
        return {age, sex, birth, nativePlace}
			},
		}
	  }
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 40px);
	}
</style>
