<template>
	<view>
		<cu-custom :backUrl="'/pages/human/enrollment/registration/EnrollmentRegistrationAddForm'" :isBack="false" bgColor="bg-gradual-blue" >
<!--			<block slot="backText">返回</block>-->
			<block slot="content">入职登记</block>
<!--			<block slot="right" >-->
<!--				<view  @click="back()">-->
<!--					刷新-->
<!--				</view>-->
<!--			</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="politicalOutlook" :required="true">
				<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="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="maritalStatus" :required="true">
<!--			     <u&#45;&#45;input placeholder='请填写婚姻状况'  v-model="inputForm.maritalStatus"></u&#45;&#45;input>-->
				<jp-picker v-model="inputForm.maritalStatus" rangeKey="label" rangeValue="value" :range="[
						        { label: '未婚', value: '1' },
						        { label: '已婚', value: '2' },
						        { label: '丧偶', value: '3' },
						        { label: '离婚', value: '4' }
						    ]"></jp-picker>
			</u-form-item>
			
			<u-form-item label="联系电话" borderBottom prop="mobilePhone" :required="true">
			     <u--input placeholder='请填写联系电话' @blur="mobilePhoneOnly(inputForm.mobilePhone)" maxlength="11" v-model="inputForm.mobilePhone"></u--input>
			</u-form-item>
			
			<u-form-item label="家庭住址" borderBottom prop="homeAddress" :required="true">
			     <u--input placeholder='请填写家庭住址'  v-model="inputForm.homeAddress"></u--input>
			</u-form-item>
			
			<u-form-item label="常住住址" borderBottom prop="permanentAddress" >
			     <u--input placeholder='请填写常住住址'  v-model="inputForm.permanentAddress"></u--input>
			</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="startTime" :required="true">
			     <el-date-picker
			     	v-model="inputForm.startTime"
			     	type="date"
			     	placeholder="选择入学时间"
			     	style="width:100%"
			     	size="default"
			     	placement="bottom-start"
			     	clearable>
			     </el-date-picker>
			</u-form-item>
			
			<u-form-item label="毕业时间" borderBottom prop="endTime" :required="true">
			     <el-date-picker
			     	v-model="inputForm.endTime"
			     	type="date"
			     	placeholder="选择毕业时间"
			     	style="width:100%"
			     	size="default"
			     	placement="bottom-start"
			     	clearable>
			     </el-date-picker>
			</u-form-item>
			
			<u-form-item label="学历" borderBottom prop="education" :required="true">
				<jp-picker v-model="inputForm.education" rangeKey="label" rangeValue="value" :range="[
						        { label: '小学', value: '1' },
						        { label: '初中', value: '2' },
						        { label: '高中', value: '3' },
						        { label: '大专', value: '4' },
						        { label: '本科', value: '5' },
						        { label: '研究生', value: '6' },
						    ]"></jp-picker>
			</u-form-item>
			
			<u-form-item label="学历性质" borderBottom prop="educationNature" :required="true">
				<jp-picker v-model="inputForm.educationNature" rangeKey="label" rangeValue="value" :range="[
						        { label: '统招全日制学历', value: '1' },
						        { label: '国家开放大学', value: '2' },
						        { label: '成人高考学历', value: '3' },
						        { label: '网络远程教育学历', value: '4' },
						        { label: '自考学历', value: '5' },
						    ]"></jp-picker>
			</u-form-item>
			
			<u-form-item label="是否毕业" borderBottom prop="graduatedOrNot" :required="true">
				<jp-picker v-model="inputForm.graduatedOrNot" rangeKey="label" rangeValue="value" :range="[
						        { label: '是', value: '1' },
						        { label: '否', value: '2' },
						    ]"></jp-picker>
			</u-form-item>
			
			<u-form-item label="英语等级" borderBottom prop="englishLevel" :required="true">
				<jp-picker v-model="inputForm.englishLevel" rangeKey="label" rangeValue="value" :range="[
						        { label: '无', value: '6' },
						        { label: '三级', value: '5' },
						        { label: 'CET-4', value: '1' },
						        { label: 'CET-6', value: '2' },
						        { label: 'TEM-4', value: '3' },
						        { label: 'TEM-8', value: '4' },
						    ]"></jp-picker>
			</u-form-item>
			
			<u-form-item label="计算机等级" borderBottom prop="ncre" :required="true">
				<jp-picker v-model="inputForm.ncre" rangeKey="label" rangeValue="value" :range="[
						        { label: '无', value: '5' },
						        { label: '一级', value: '1' },
						        { label: '二级', value: '2' },
						        { label: '三级', value: '3' },
						        { label: '四级', value: '4' },
						    ]"></jp-picker>
			</u-form-item>
			
			<u-form-item label="个人简历" borderBottom prop="remarks">
			    <u--textarea  placeholder='请填写个人简历'  v-model="inputForm.remarks" ></u--textarea>
			</u-form-item>
			
			<!--<u-form-item label="社保编号(选填)" borderBottom prop="socialSecurityNumber">
			    <u&#45;&#45;input  placeholder='请填写社保编号'  v-model="inputForm.socialSecurityNumber" maxlength="10" @input="validateInput"></u&#45;&#45;input>
			</u-form-item>
			
			<u-form-item label="社保银行卡号(选填)" borderBottom prop="socialSecurityBankNumber">
			    <u&#45;&#45;input  placeholder='请填写社保银行卡号'  v-model="inputForm.socialSecurityBankNumber" @change="checkBankNumber(inputForm.socialSecurityBankNumber)" maxlength="19"></u&#45;&#45;input>
			</u-form-item>
			
			<u-form-item label="社保卡照片正面" borderBottom prop="socialSecurityPictureFront">
				
				<el-upload
				  class="upload-demo"
				  :action="`http://localhost:2800/api/public-modules-server/oss/file/webUpload/upload`"
				  :on-remove="handleRemove"
				  :on-success="handleAvatarSuccess"
				  :file-list="fileList"
				  :limit="1"
				  list-type="picture">
				  <el-button size="small" type="primary">点击上传</el-button>
				  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
				</el-upload>
				
			</u-form-item>
			
			<u-form-item label="社保卡照片反面" borderBottom prop="socialSecurityPictureOpposite">
				
				<el-upload
				  class="upload-demo"
				  :action="`http://localhost:2800/api/public-modules-server/oss/file/webUpload/upload`"
				  :on-success="handleAvatarSuccess2"
				  :on-remove="handleRemove2"
				  :file-list="fileList2"
				  :limit="1"
				  list-type="picture">
				  <el-button size="small" type="primary">点击上传</el-button>
				  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
				</el-upload>
				
			</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 SelectTree from '@/components/treeSelect/treeSelect.vue'
	import enrollmentRegistrationService from '@/api/human/enrollment/EnrollmentRegistrationService'
	import OSSSerivce, {
			httpRequest,
			fileName,
			toHref,
		} from '@/api/sys/OSSService'
	export default {
		data () {
			return {
				fileList: [],
				fileList2: [],
				title: '',
				method: '',
				loading: false,
				inputForm: {
					userId: '',
					name: '',
					sex: '',
					age: '',
					birthday: '',
					politicalOutlook: '',
					nativePlace: '',
					nation: '',
					maritalStatus: '',
					mobilePhone: '',
					idCard: '',
					homeAddress: '',
					permanentAddress: '',
					graduatedFrom: '',
					speciality: '',
					startTime: '',
					endTime: '',
					education: '',
					educationNature: '',
					graduatedOrNot: '',
					englishLevel: '',
					ncre: '',
					department: '',
					entryDate: '',
					contractStartDate: '',
					remarks: '',
					type: '',
					socialSecurityNumber: '',
					socialSecurityBankNumber: '',
					socialSecurityPictureFront: '',
					socialSecurityPictureFrontUrl: '',
					socialSecurityPictureOpposite: '',
					socialSecurityPictureOppositeUrl: '',
				},
				// tableData:[],// 存储表格数据
				amountKey: '',
				membersKey: '',
				rules: {
					  'sex': [
					  {
							required: true,
							message: '性别不能为空',
							trigger: ['blur', 'change']
					  }],
					  'name': [
						  {
							  required: true,
							  message: '姓名不能为空',
							  trigger: ['blur', 'change']
						  }
					  ],
					  'mobilePhone': [
						  {
								required: true,
								message: '联系电话不能为空',
								trigger: ['blur', 'change']
						  },
						  {
							  validator: (rule, value, callback) => this.validatePhone(value, callback),
							  trigger: ['blur', 'change']
						  }
					  ],
					'idCard': [
						{
							validator: (rule, value, callback) => this.isCardId(value, callback),
							trigger: ['blur']
						}
					],
					'politicalOutlook': [
						{
							required: true,
							message: '政治面貌不能为空',
							trigger: ['blur', 'change']
						},
					],
					'nativePlace': [
						{
							required: true,
							message: '籍贯不能为空',
							trigger: ['blur', 'change']
						},
					],
					'nation': [
						{
							required: true,
							message: '民族不能为空',
							trigger: ['blur', 'change']
						},
					],
					'maritalStatus': [
						{
							required: true,
							message: '婚姻状况不能为空',
							trigger: ['blur', 'change']
						},
					],
					'homeAddress': [
						{
							required: true,
							message: '家庭住址不能为空',
							trigger: ['blur', 'change']
						},
					],
					/*'permanentAddress': [
						{
							required: true,
							message: '常住住址不能为空',
							trigger: ['blur', 'change']
						},
					],*/
					'graduatedFrom': [
						{
							required: true,
							message: '毕业院校不能为空',
							trigger: ['blur', 'change']
						},
					],
					'speciality': [
						{
							required: true,
							message: '专业不能为空',
							trigger: ['blur', 'change']
						},
					],
					'startTime': [
						{
							required: true,
							message: '开始时间不能为空',
							trigger: ['blur', 'change']
						},
					],
					'endTime': [
						{
							required: true,
							message: '毕业时间不能为空',
							trigger: ['blur', 'change']
						},
					],
					'education': [
						{
							required: true,
							message: '学历不能为空',
							trigger: ['blur', 'change']
						},
					],
					'educationNature': [
						{
							required: true,
							message: '学历性质不能为空',
							trigger: ['blur', 'change']
						},
					],
					'graduatedOrNot': [
						{
							required: true,
							message: '是否毕业不能为空',
							trigger: ['blur', 'change']
						},
					],
					'englishLevel': [
						{
							required: true,
							message: '英语等级不能为空',
							trigger: ['blur', 'change']
						},
					],
					'ncre': [
						{
							required: true,
							message: '计算机等级不能为空',
							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
		  }
		},
    components: {
      SelectTree,
    },
    methods: {
			handleAvatarSuccess (res, file, fileList) {
				this.inputForm.socialSecurityPictureFront = file.response.url
				this.inputForm.socialSecurityPictureFrontUrl = file.response.lsUrl
			},
			handleRemove(file, fileList) {
				this.inputForm.socialSecurityPictureFront = ''
				this.inputForm.socialSecurityPictureFrontUrl = ''
			},
			handleAvatarSuccess2 (res, file, fileList) {
				this.inputForm.socialSecurityPictureOpposite = file.response.url
				this.inputForm.socialSecurityPictureOppositeUrl = file.response.lsUrl
			},
			handleRemove2(file, fileList) {
				this.inputForm.socialSecurityPictureOpposite = ''
				this.inputForm.socialSecurityPictureOppositeUrl = ''
			},
			init (id) {
			  if (id) {
				  enrollmentRegistrationService.findById(id).then((data) => {
			        this.inputForm = this.recover(this.inputForm, data)
			      })
			  }
			},
			async saveForm () {
					var flag = false
					//定义表单规则
					if (this.isNotEmpty(this.inputForm.socialSecurityNumber) && (this.isEmpty(this.inputForm.socialSecurityBankNumber) || isEmpty(this.inputForm.socialSecurityPictureFront))) {
							this.loading = false
							// this.$message.error('社保银行卡号与社保卡照片不能为空');
							// throw new Error('社保银行卡号与社保卡照片不能为空')
							uni.showToast({
								title: '社保银行卡号与社保卡照片不能为空',
								icon: "none",
								duration:2000
							})
						}
						if (this.isNotEmpty(this.inputForm.socialSecurityBankNumber) && (this.isEmpty(this.inputForm.socialSecurityNumber) || this.isEmpty(this.inputForm.socialSecurityPictureFront))) {
							this.loading = false
							// this.$message.error('社保编号与社保卡照片不能为空');
							// throw new Error('社保编号与社保卡照片不能为空')
							uni.showToast({
								title: '社保编号与社保卡照片不能为空',
								icon: "none",
								duration:2000
							})
						}
						if (this.isNotEmpty(this.inputForm.socialSecurityPictureFront) && (this.isEmpty(this.inputForm.socialSecurityNumber) || this.isEmpty(this.inputForm.socialSecurityBankNumber))) {
							this.loading = false
							// this.$message.error('社保编号与社保银行卡号不能为空');
							// throw new Error('社保编号与社保银行卡号不能为空')
							uni.showToast({
								title: '社保编号与社保银行卡号不能为空',
								icon: "none",
								duration:2000
							})
						}
						if (this.isNotEmpty(this.inputForm.startTime)) {
							this.inputForm.startTime = this.formatDate(this.inputForm.startTime);
						}
						if (this.isNotEmpty(this.inputForm.endTime)) {
							this.inputForm.endTime = this.formatDate(this.inputForm.endTime);
						}

				await enrollmentRegistrationService.findIdCardOnly(this.inputForm.idCard,"").then((data) => {
					if (data !== 0) {
						uni.showToast({
							title: '身份证号码已存在，请重新确认',
							icon: "none",
							duration:2000
						})
					}
				})
				if (this.isNotEmpty(this.inputForm.mobilePhone)) {
					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'
					enrollmentRegistrationService.save(this.inputForm).then((data) => {
						  // callback(data.businessTable, data.businessId)
						// 接口调用成功，隐藏加载动画
						uni.hideLoading();
						//提交成功跳转页面
						this.$router.push('/pages/human/enrollment/registration/saveOk'); // 替换 '/new-page' 为你想要跳转的页面路径
					}).catch((e)=>{
					})
				}).catch((e)=>{
				})
			},
			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}`;
			},
			//身份证号码唯一性判断
			idCardOnly(idCard) {
				if (this.isNotEmpty(idCard)) {
					enrollmentRegistrationService.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) {
				if (this.isEmpty(mobilePhone)) {

				} else {
					enrollmentRegistrationService.findMobilePhoneOnly(mobilePhone).then((data) => {
						if (data !== 0) {
							// this.$message.error('手机码已存在，请重新确认')
							// this.inputForm.mobilePhone = ''
							// throw new Error('联系电话已存在，请重新确认')
							uni.showToast({
								title: '联系电话已存在，请重新确认',
								icon: "none",
								duration:2000
							})
							this.inputForm.mobilePhone = ''
						}
					})
				}


			},
			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)
			  	},
			back () {
				uni.navigateTo({
					url: '/pages/human/enrollment/registration/EnrollmentRegistrationAddForm'
				})
			},
			/**
			 * 从身份证号中获取出生日期、性别、年龄
			 * @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}
			},
			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()
				}
			},
			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;
			},
			validateInput() {
				// 使用正则表达式验证输入内容，禁止中文
				this.inputForm.socialSecurityNumber = this.inputForm.socialSecurityNumber.replace(/[\u4e00-\u9fa5]/g, '');
			},
			checkBankNumber(bankNumber) {
				this.isBankNum(bankNumber)
			},
			/**
			 * 银行卡号验证
			 * 银行卡号:12位 16位 17 18 19
			 * @param str
			 * @returns {boolean}
			 */
			isBankNum (str) {
				const bankNumber = /^([1-9]{1})(\d{11}|\d{15}|\d{16}|\d{17}|\d{18})$/
				if (!bankNumber.test(str)) {
					uni.showToast({
						title: '银行卡号填写不正确，请重新填写',
						icon: "none",
						duration:2000
					})
					this.inputForm.socialSecurityBankNumber = ''
				}
			}
		}
	  }
</script>

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


</style>
