<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
	<div>
		<el-dialog
			:title="title"
			:close-on-click-modal="false"
			draggable
			width="1300px"
			@close="close"
			@keyup.enter.native=""
			v-model="visible">
		<el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="status === 'audit' || status === 'taskFormDetail'|| method === 'view'"
				 label-width="160px" @submit.native.prevent>
			<el-divider content-position="left"><i class="el-icon-document"></i> 基础信息</el-divider>
			<el-row :gutter="26">
				<el-col :span="12">
					<el-form-item label="姓名" prop="name" :rules="[{required: true, message: '姓名不能为空', trigger: 'blur'}]">
						<el-input v-model="inputForm.name"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="身份证号码" prop="idCard" :rules="[{required: true,validator: validator.isCardId, trigger:'blur'}]">
						<el-input v-model="inputForm.idCard" @blur="decomposeIdCard(inputForm.idCard)"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="性别" prop="sex"
								  :rules="[
								  	{required: true, message: '性别不能为空', trigger: 'change'}
                 ]">
						<el-radio-group v-model="inputForm.sex">
							<el-radio v-for="item in $dictUtils.getDictList('sex')" :label="item.value" :key="item.value">{{item.label}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="年龄" prop="age" :rules="[{required: true, message: '年龄不能为空', trigger: 'change'}]">
						<el-input v-model="inputForm.age" type="number"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="出生日期" prop="birthday" :rules="[
                  {required: true, message:'请填写出生日期', trigger: 'blur'}
               ]">
						<el-date-picker
							style="width: 100%"
							v-model="inputForm.birthday"
							value-format="YYYY-MM-DD"
							placeholder="选择日期"
						>
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="政治面貌" prop="politicalOutlook" :rules="[ {required: true, message:'请选择政治面貌', trigger: 'blur'}]">
						<!--						<el-input v-model="inputForm.politicalOutlook"></el-input>-->
						<el-select v-model="inputForm.politicalOutlook" placeholder="请选择政治面貌" style="width:100%;">
							<el-option
								v-for="item in $dictUtils.getDictList('political_outlook')"
								:key="item.value"
								:label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="籍贯" prop="nativePlace" :rules="[{required: true, message:'请输入籍贯', trigger: 'blur'}]">
						<el-input v-model="inputForm.nativePlace"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="民族" prop="nation" :rules="[{required: true, message:'请输入民族', trigger: 'blur'}]">
						<el-input v-model="inputForm.nation"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="婚姻状况" prop="maritalStatus" :rules="[{required: true, message:'请选择婚姻状况', trigger: 'blur'}]">
						<el-select v-model="inputForm.maritalStatus" placeholder="请选择婚姻状况" clearable style="width: 100%;">
							<el-option
								v-for="item in $dictUtils.getDictList('marital_status')"
								:key="item.value"
								:label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>

				</el-col>
				<el-col :span="12">
					<el-form-item label="联系电话" prop="mobilePhone" :rules="[{required: true, message: '联系电话不能为空', trigger: 'change'}]">
						<el-input  v-model="inputForm.mobilePhone" @blur="mobilePhoneOnly(inputForm.mobilePhone)"></el-input>
					</el-form-item>
				</el-col>

				<el-col :span="12">
					<el-form-item label="家庭住址" prop="homeAddress" :rules="[]">
						<el-input v-model="inputForm.homeAddress"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="常住住址" prop="permanentAddress" :rules="[]">
						<el-input v-model="inputForm.permanentAddress"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="银行账号" prop="bankNumber" :rules="[]">
						<el-input v-model="inputForm.bankNumber"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="公积金账号" prop="fundNumber" :rules="[]">
						<el-input v-model="inputForm.fundNumber"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="邮箱" prop="email" :rules="[]">
						<el-input v-model="inputForm.email" @blur="checkEmail"></el-input>
					</el-form-item>
				</el-col>

			</el-row>
			<el-divider content-position="left"><i class="el-icon-document"></i> 学历信息</el-divider>
			<el-row :gutter="26">
				<el-col :span="12">
					<el-form-item label="毕业院校" prop="graduatedFrom" :rules="[{required: true, message: '毕业院校不能为空', trigger: 'change'}]">
						<el-input v-model="inputForm.graduatedFrom"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="专业" prop="speciality" :rules="[{required: true, message: '专业不能为空', trigger: 'change'}]">
						<el-input v-model="inputForm.speciality"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="入学时间" prop="startTime" :rules="[{required: true, message: '入学时间不能为空', trigger: 'change'}
               ]">
						<el-date-picker
							style="width: 100%"
							v-model="inputForm.startTime"
							value-format="YYYY-MM-DD"
							placeholder="选择日期"
						>
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="毕业时间" prop="endTime" :rules="[{required: true, message: '毕业时间不能为空', trigger: 'change'}
               ]">
						<el-date-picker
							style="width: 100%"
							v-model="inputForm.endTime"
							value-format="YYYY-MM-DD"
							placeholder="选择日期"
						>
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="学历" prop="education" :rules="[{required: true, message: '学历不能为空', trigger: 'change'}]">
						<el-select v-model="inputForm.education" placeholder="请选择学历" clearable style="width: 100%;">
							<el-option
								v-for="item in $dictUtils.getDictList('education')"
								:key="item.value"
								:label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="学历性质" prop="educationNature" :rules="[{required: true, message: '学历性质不能为空', trigger: 'change'}]">
						<el-select v-model="inputForm.educationNature" placeholder="请选择学历性质" clearable style="width: 100%;">
							<el-option
								v-for="item in $dictUtils.getDictList('education_nature')"
								:key="item.value"
								:label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="是否毕业" prop="graduatedOrNot" :rules="[{required: true, message: '是否毕业不能为空', trigger: 'change'}]">
						<el-radio-group v-model="inputForm.graduatedOrNot">
							<el-radio v-for="item in $dictUtils.getDictList('graduated_or_not')" :label="item.value" :key="item.value">{{item.label}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="英语等级" prop="englishLevel" :rules="[{required: true, message: '英语等级不能为空', trigger: 'change'}]">
						<el-select v-model="inputForm.englishLevel" placeholder="请选择英语等级" clearable style="width: 100%;">
							<el-option
								v-for="item in $dictUtils.getDictList('english_level')"
								:key="item.value"
								:label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="计算机等级" prop="ncre" :rules="[{required: true, message: '计算机等级不能为空', trigger: 'change'}]">
						<el-select v-model="inputForm.ncre" placeholder="请选择计算机等级" clearable style="width: 100%;">
							<el-option
								v-for="item in $dictUtils.getDictList('computer_level')"
								:key="item.value"
								:label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-divider content-position="left"><i class="el-icon-document"></i> 部门信息</el-divider>
			<el-row :gutter="26">
						<el-col :span="12">
							<el-form-item label="所属部门" prop="department" :rules="[
						{required: true, message:'请选择所属部门', trigger: 'change'}
					]">
								<SelectTree
									ref="officeTree"
									:props="{
										  value: 'id',             // ID字段名
										  label: 'name',         // 显示名称
										  children: 'children'    // 子级字段名
										}"
									:url="`/system-server/sys/office/treeData?type=2`"
									:value="inputForm.department"
									:accordion="true"
									size="default"
									@getValue="(value) => {inputForm.department=value}"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item  prop="managerOffice" label="管理部门" >
								<SelectTree
									ref="officeTree"
									:props="{
                  value: 'id',             // ID字段名
                  label: 'name',         // 显示名称
                  children: 'children'    // 子级字段名
                }"
									size="middle"
									:url="`/jeeplus-system/sys/office/treeData3?type=2`"
									:value="inputForm.managerOffice"
									:clearable="false"
									:accordion="true"
									:showCheckbox="true"
									:checkStrictly="true"
									:checkOnClickNode="true"
									@getValue="(value) => {inputForm.managerOffice=value}"/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="岗位" prop="postId">
								<el-select
									v-model="inputForm.postIdList"
									style="width: 100%"
									multiple
									placeholder="请选择"
								>
									<el-option
										v-for="item in postList"
										:key="item.id"
										:label="item.name"
										:value="item.id"
									>
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="角色" prop="roleIdList" :rules="[{required: true, message: '角色不能为空', trigger: 'change'}]">
								<el-select  v-model="inputForm.roleIdList" style="width:100%" multiple placeholder="请选择">
									<el-option
										v-for="role in roleList"
										:key="role.id"
										:label="role.name"
										:value="role.id">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="员工类型" prop="onJobStatus" :rules="[
								{required: true, message:'请选择员工类型', trigger: 'change'}
							]">
								<!--						<el-input v-model="inputForm.politicalOutlook"></el-input>-->
								<el-select v-model="inputForm.onJobStatus" placeholder="请选择员工类型" style="width:100%;" clearable>
									<el-option
										v-for="item in $dictUtils.getDictList('on_job_status')"
										:key="item.value"
										:label="item.label"
										:value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
				<el-col :span="12" v-if="inputForm.onJobStatus === '1'">
					<el-form-item label="试用期限" prop="timeLimit" :rules="[
							  {required: true, message:'请填写试用期限', trigger: 'blur'}
						   ]">
						<el-input style="width: 100%" v-model="inputForm.timeLimit" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10">
							<template #suffix>
								个月
							</template>
						</el-input>
					</el-form-item>
				</el-col>
						<el-col :span="12">
							<el-form-item label="入职时间" prop="inTime" :rules="[
                  {required: true, message:'请填写入职时间', trigger: 'blur'}
               ]">
								<el-date-picker
									style="width: 100%"
									v-model="inputForm.inTime"
									value-format="YYYY-MM-DD"
									type="date"
									placeholder="选择日期"
									:default-value="new Date()"
								>
								</el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item label="备注" prop="remarks"
										  :rules="[
                   ]">
								<el-input type="textarea" maxlength="500" v-model="inputForm.remarks" placeholder="请填写备注" show-word-limit></el-input>
							</el-form-item>
						</el-col>
			</el-row>

		</el-form>
		<!--		附件-->
		<UpLoadComponent ref="files"></UpLoadComponent>
		<!--		承诺书-->
		<UpLoadComponent ref="commitment"></UpLoadComponent>
		<!--		申请表-->
		<UpLoadComponent ref="applys"></UpLoadComponent>
		<!--		学历证明-->
		<UpLoadComponent ref="certificates"></UpLoadComponent>
		<!--		身份证-->
		<UpLoadComponent ref="idCards"></UpLoadComponent>
		<!--		培训证书-->
		<UpLoadComponent ref="trainings"></UpLoadComponent>
		<!--		职称-->
		<UpLoadComponent ref="professional"></UpLoadComponent>
		<!--		离职证明-->
		<UpLoadComponent ref="resignation"></UpLoadComponent>
			<template #footer>
			<span class="dialog-footer">
			  <el-button  @click="close()" icon="el-icon-circle-close">关闭</el-button>
			  <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
			</span>
			</template>
		</el-dialog>
	</div>
</template>

<script>
	import XEUtils from 'xe-utils'
	import EntryService from '@/api/jy/EntryService'
	import { ElDatePicker } from 'element-plus';
	import UserSelectSignatory from '../workClientInfo/clientUserSelect'
	import UpLoadComponent from '@/views/common/UpLoadComponent'
	import CommonApi from '@/api/cw/common/CommonApi'
	import SelectTree from '@/components/treeSelect/treeSelect.vue'
	import postService from "@/api/sys/postService";
	import roleService from "@/api/sys/roleService";

	export default {
		props: {
			businessId: {
				type: String,
				default: ''
			},
			formReadOnly: {
				type: Boolean,
				default: false
			},
			status: {
				type: String,
				default: ''
			}
		},
		data () {
			return {
				title: '',
				method: '',
				loading: false,
				visible: false,
				inputForm: {
					id: '',
					name: '',
					sex: '',
					age: '',
					email:'',
					birthday: '',
					politicalOutlook: '',
					nativePlace: '',
					nation: '',
					maritalStatus: '',
					mobilePhone: '',
					idCard: '',
					homeAddress: '',
					permanentAddress: '',
					graduatedFrom: '',
					speciality: '',
					startTime: '',
					endTime: '',
					education: '',
					educationNature: '',
					graduatedOrNot: '',
					englishLevel: '',
					ncre: '',
					department: '',
					inTime: this.moment(new Date()).format('YYYY-MM-DD'),
					bankNumber:'',
					fundNumber:'',
					remarks: '',
					type: '',
					onJobStatus: '',
					files: [], // 附件信息
					commitment:[], //承诺书
					applys:[], //申请表
					certificates:[],//学历证明
					idCards:[], //身份证
					trainings:[], //培训证书
					professional:[], //职称
					resignation:[], //离职证明
					postIdList:[],
					roleIdList:[],
					managerOffice:'',
					procInsId:'',
					timeLimit:'',
				},
				baseKey: '',
				keyWatch: '',
				dateList:[],
				programRow:'',
				days:'',
				roleList:[],
				postList:[],


			}
		},
		EntryService:null,
		commonApi: null,
		created () {
			this.entryService=new EntryService()
			this.commonApi = new CommonApi()

		},
		mounted () {
		},
		activated () {
		},
		components: {
			ElDatePicker,
			UserSelectSignatory,
			UpLoadComponent,
			SelectTree,
		},
		computed: {
			bus: {
				get () {
					this.$refs.files.setDividerName('附件')
					this.$refs.commitment.setDividerName('承诺书')
					this.$refs.applys.setDividerName('申请表')
					this.$refs.certificates.setDividerName('学历证明')
					this.$refs.idCards.setDividerName('身份证')
					this.$refs.trainings.setDividerName('培训证书')
					this.$refs.professional.setDividerName('职称')
					this.$refs.resignation.setDividerName('离职证明')
					return this.businessId
				},
				set (val) {
					console.log('val', val)
					this.businessId = val
				}
			}
		},
		watch: {
			'keyWatch': {
				handler (newVal) {
					console.log('几里路')
					if (this.commonJS.isNotEmpty(this.bus)) {
						console.log('32423423')
						this.init('', this.bus)
					} else {
						this.$nextTick(() => {
							this.$refs.inputForm.resetFields()
						})
					}
				}
			},
			'loading': {
				handler (newVal) {
					this.$emit('changeLoading', newVal)
					this.$refs.files.changeLoading(newVal)
					this.$refs.commitment.changeLoading(newVal)
					this.$refs.applys.changeLoading(newVal)
					this.$refs.certificates.changeLoading(newVal)
					this.$refs.idCards.changeLoading(newVal)
					this.$refs.trainings.changeLoading(newVal)
					this.$refs.professional.changeLoading(newVal)
					this.$refs.resignation.changeLoading(newVal)
				}
			}
		},
		methods: {
			getKeyWatch(keyWatch) {
				this.keyWatch = keyWatch
			},
			init(method, id) {
				this.method = method
				this.inputForm={
					id: '',
					name: '',
					sex: '',
					age: '',
					birthday: '',
					politicalOutlook: '',
					nativePlace: '',
					nation: '',
					maritalStatus: '',
					mobilePhone: '',
					idCard: '',
					homeAddress: '',
					permanentAddress: '',
					graduatedFrom: '',
					speciality: '',
					startTime: '',
					endTime: '',
					education: '',
					educationNature: '',
					graduatedOrNot: '',
					englishLevel: '',
					ncre: '',
					department: '',
					inTime: '',
					bankNumber:'',
					fundNumber:'',
					email:'',
					remarks: '',
					type: '',
					onJobStatus: '',
					files: [], // 附件信息
					commitment:[], //承诺书
					applys:[], //申请表
					certificates:[],//学历证明
					idCards:[], //身份证
					trainings:[], //培训证书
					professional:[], //职称
					resignation:[], //离职证明
					postIdList:[],
					roleIdList:[],
					managerOffice:'',
					procInsId:'',
					timeLimit:''
				}
				this.inputForm.id = id
				this.loading = false
				this.visible = true
				this.$nextTick(() => {
					this.$refs.inputForm.resetFields()
					this.loading = true
					this.$refs.files.clearUpload()
					this.$refs.commitment.clearUpload()
					this.$refs.applys.clearUpload()
					this.$refs.certificates.clearUpload()
					this.$refs.idCards.clearUpload()
					this.$refs.trainings.clearUpload()
					this.$refs.professional.clearUpload()
					this.$refs.resignation.clearUpload()
					console.log('this.inputForm.id', this.inputForm.id)
					this.entryService.queryById(this.inputForm.id).then((data)=>{
						this.inputForm = this.recover(this.inputForm, data)
						this.days=data.days
						this.inputForm.files=data.files
						console.log('s',this.inputForm)
						if (this.status === 'taskFormDetail') {
							method = 'view'
						}
						if (this.commonJS.isNotEmpty(data.procInsId)){
							this.commonApi.getTaskNameByProcInsId(data.procInsId).then((da)=> {
								if (this.commonJS.isNotEmpty(da)) {
									if (da === '人事审核') {
										method = 'edit'
									}else {
										method = 'view'
									}
								}
							})
						}

						console.log('me',method)
						if (this.commonJS.isEmpty(this.inputForm.files)){
							this.inputForm.files=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.commitment)){
							this.inputForm.commitment=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.applys)){
							this.inputForm.applys=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.certificates)){
							this.inputForm.certificates=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.idCards)){
							this.inputForm.idCards=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.trainings)){
							this.inputForm.trainings=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.professional)){
							this.inputForm.professional=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.resignation)){
							this.inputForm.resignation=[]
						}
						if (this.commonJS.isEmpty(this.inputForm.roleIdList)){
							this.inputForm.roleIdList=[]
						}
						this.$refs.files.newUpload(method, this.inputForm.files, 'humanResources',null,'附件')
						this.$refs.commitment.newUpload(method, this.inputForm.commitment, 'commitment',null,'承诺书')
						this.$refs.applys.newUpload(method, this.inputForm.applys, 'applys',null,'申请表')
						this.$refs.certificates.newUpload(method, this.inputForm.certificates, 'certificates',null,'学历证明')
						this.$refs.idCards.newUpload(method, this.inputForm.idCards, 'idCards',null,'身份证')
						this.$refs.trainings.newUpload(method, this.inputForm.trainings, 'trainings',null,'培训证书')
						this.$refs.professional.newUpload(method, this.inputForm.professional, 'professional',null,'职称')
						this.$refs.resignation.newUpload(method, this.inputForm.resignation, 'resignation',null,'离职证明')
						this.loading = false
					})
					roleService.list2({current: 1, size: -1}).then((data) => {
						this.roleList = data
					})
					postService.list2({current: 1, size: -1}).then((data) => {
						this.postList = data.records
					})

				})
			},
			saveForm(callback) {
				this.doSubmit('save', callback)
			},
			startForm(callback) {
				this.loading = true
				if (this.commonJS.isNotEmpty(this.inputForm.id)) {
					this.entryService.queryById(this.inputForm.id).then((data) => {
						if (data.type !== '0' && data.type !== '1' && data.type !== '3') { // 审核状态不是“未发起”或“暂存”或“撤回”，就弹出提示
							this.loading = false
							this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
							throw new Error()
						} else {
							this.doSubmit('start', callback)
						}
					})
				} else {
					this.doSubmit('start', callback)
				}
			},
			async agreeForm(callback) {
				console.log('进入方法')
				this.loading = true
				this.inputForm.files = this.$refs.files.getDataList()
				this.inputForm.commitment = this.$refs.commitment.getDataList()
				this.inputForm.applys = this.$refs.applys.getDataList()
				this.inputForm.certificates = this.$refs.certificates.getDataList()
				this.inputForm.idCards = this.$refs.idCards.getDataList()
				this.inputForm.trainings = this.$refs.trainings.getDataList()
				this.inputForm.professional = this.$refs.professional.getDataList()
				this.inputForm.resignation = this.$refs.resignation.getDataList()
				await this.entryService.queryById(this.inputForm.id).then((data) => {
					if (data.type !== '2' ) { // status的值不等于“审核中”，就弹出提示
						this.loading = false
						this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
						throw new Error()
					} else {
						this.inputForm.type= '2'
							this.commonApi.getTaskNameByProcInsId(this.inputForm.procInsId).then((da)=>{
								if (this.commonJS.isNotEmpty(da)) {
									if (da === '人事审核') {
										this.inputForm.type = '5'
									}
								}
								let param = {type: this.inputForm.type, id: this.inputForm.id}
								this.inputForm=JSON.stringify(this.inputForm)
								this.entryService.saveForm(this.inputForm).then(() => {
									callback(data.businessTable, data.businessId, this.inputForm)
									this.loading = false
								}).catch(() => {
									this.loading = false
								})
							})

					}
				})
			},
			reapplyForm(callback) {
				this.loading = true
				this.entryService.queryById(this.inputForm.id).then((data) => {
					if (data.type !== '4') { // 审核状态不是“驳回”，就弹出提示
						this.loading = false
						this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
						throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
					} else {
						this.doSubmit('reapply', callback)
					}
				})
			},
			// 表单提交
			async doSubmit(status, callback) {
				this.loading = true
				if (await this.$refs.files.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				if (await this.$refs.commitment.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				if (await this.$refs.applys.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				if (await this.$refs.certificates.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				if (await this.$refs.idCards.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				if (await this.$refs.trainings.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				if (await this.$refs.professional.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				if (await this.$refs.resignation.checkProgress()) {
					this.loading = false
					throw new Error()
				}
				console.log('5',this.inputForm)
				if (status === 'save') {
					// 暂存
					this.loading = true
					this.inputForm.type = '1'
					this.inputForm.files = this.$refs.files.getDataList()
					this.inputForm.commitment = this.$refs.commitment.getDataList()
					this.inputForm.applys = this.$refs.applys.getDataList()
					this.inputForm.certificates = this.$refs.certificates.getDataList()
					this.inputForm.idCards = this.$refs.idCards.getDataList()
					this.inputForm.trainings = this.$refs.trainings.getDataList()
					this.inputForm.professional = this.$refs.professional.getDataList()
					this.inputForm.resignation = this.$refs.resignation.getDataList()
					this.entryService.saveForm(this.inputForm).then((data) => {
						callback(data.businessTable, data.businessId, this.inputForm,data.days)
						this.loading = false
					}).catch(() => {
						this.loading = false
					})
					return
				} else if (status === 'start') {
					if (this.commonJS.isEmpty(this.inputForm.name)){
						this.$message.error('请输入名字')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.sex)){
						this.$message.error('请选择性别')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.age)){
						this.$message.error('请输入年龄')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.birthday)){
						this.$message.error('请选择出生日期')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.politicalOutlook)){
						this.$message.error('请选择政治面貌')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.nativePlace)){
						this.$message.error('请输入籍贯')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.nation)){
						this.$message.error('请输入民族')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.maritalStatus)){
						this.$message.error('请选择婚姻状况')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.mobilePhone)){
						this.$message.error('请输入联系电话')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.idCard)){
						this.$message.error('请输入身份证号')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.graduatedFrom)){
						this.$message.error('请输入毕业院校')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.speciality)){
						this.$message.error('请输入专业')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.startTime)){
						this.$message.error('请选择入学时间')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.endTime)){
						this.$message.error('请选择毕业时间')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.education)){
						this.$message.error('请选择学历')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.educationNature)){
						this.$message.error('请选择学历性质')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.graduatedOrNot)){
						this.$message.error('请选择是否毕业')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.englishLevel)){
						this.$message.error('请选择英语等级')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.ncre)){
						this.$message.error('请选择计算机等级')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.department)){
						this.$message.error('请选择所属部门')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.roleIdList)){
						this.$message.error('请选择角色')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.onJobStatus)){
						this.$message.error('请选择员工类型')
						this.loading = false
					}
					if (this.commonJS.isEmpty(this.inputForm.inTime)){
						this.$message.error('请选择入职时间')
						this.loading = false
					}

					// 送审  待审核
					this.inputForm.type = '2'
				} else if (status === 'agree') {
					this.inputForm.type= '5'
				} else if (status === 'reapply') {
					this.inputForm.type = '2'
				}
				this.inputForm.files = this.$refs.files.getDataList()
				this.inputForm.commitment = this.$refs.commitment.getDataList()
				this.inputForm.applys = this.$refs.applys.getDataList()
				this.inputForm.certificates = this.$refs.certificates.getDataList()
				this.inputForm.idCards = this.$refs.idCards.getDataList()
				this.inputForm.trainings = this.$refs.trainings.getDataList()
				this.inputForm.professional = this.$refs.professional.getDataList()
				this.inputForm.resignation = this.$refs.resignation.getDataList()
				this.$refs['inputForm'].validate((valid) => {
					if (valid) {
						this.loading = true
						console.log('form',this.inputForm)
						this.inputForm=JSON.parse(JSON.stringify(this.inputForm))
						this.entryService.saveForm(this.inputForm).then((data) => {
							this.visible = false
							this.$emit('refreshList')
						}).catch(() => {
							this.$refs.inputForm.resetFields()
							this.loading = false
						})
					} else {
						this.loading = false
					}
				})
			},
			close() {
				this.inputForm = {
					id:'',
					projectList:[],
					name:'',
					no:'',
					projectLeader:'',
					projectCreateDate:'',
					createById:'',
					createByName:'',
					createDate:'',
					remarks:'',
					files: [], // 附件信息
					types:[], //用印类型
					number:'', //用印份数
					projectId:'',
				}
				this.visible = false
			},
			async updateStatusById(type, callback) {
				this.loading = true
				if (type === 'reject' || type === 'reback') {
					this.entryService.queryById(this.inputForm.id).then((data) => {
						if (data.type !== '2') { // status的值不等于“审核中”，就弹出提示
							this.loading = false
							this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
							throw new Error()
						} else {
							// if (type === 'agree') {
							//   // 同意
							//   this.inputForm.status = '5'
							// }
							if (type === 'reject') {
								// 驳回
								this.inputForm.type = '4'
							}
							if (type === 'reback') {
								// 撤回
								this.inputForm.type = '3'
							}
							if (type === 'reject' || type === 'reback') {
								let param = {type: this.inputForm.type, id: this.inputForm.id}
								this.entryService.updateStatusById(param).then(() => {
									this.loading = false
									callback()
								})
							}
						}
					})
				} else if (type === 'hold') {
					this.entryService.queryById(this.inputForm.id).then((data) => {
						if (data.type !== '4') { // status的值不等于“驳回”就弹出提示
							this.loading = false
							this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
							throw new Error()
						} else {
							// 终止
							let param = {type: '1', id: this.inputForm.id}
							this.entryService.updateStatusById(param).then(() => {
								this.loading = false
								callback()
							})
						}
					})
				}

			},
			/**
			 * 从身份证号中获取出生日期、性别、年龄
			 * @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'
				}
				this.inputForm.age=age
				this.inputForm.sex=sex
				this.inputForm.birthday=birth
				return {age, sex, birth}
			},
			//联系电话唯一性判断
			mobilePhoneOnly(mobilePhone) {
				if (!this.validateXG.isPhoneOrMobile(mobilePhone)) {
					this.$message.error('”联系电话“填写不正确，请重新填写')
					this.loading = false
					this.inputForm.mobilePhone = ''
					throw new Error('”联系电话“填写不正确，请重新填写')
				}

			},
			//验证邮箱
			checkEmail() {
				if (this.commonJS.isNotEmpty(this.inputForm.email)){
					if (!this.validateXG.isEmail(this.inputForm.email)) {
						this.$message.error("请输入正确的邮箱地址")
						this.loading = false
						this.inputForm.email=''
						throw new Error("请输入正确的邮箱地址")
					}
				}
			}


		}

	}
</script>
<style scoped>
	/deep/ .el-input-number .el-input__inner {
		text-align: left;
	}
	/deep/ .vxe-footer--row .vxe-footer--column:nth-child(1) .vxe-cell--item {
		font-weight:700;
	}
</style>
