﻿<template>
	<transition name="el-zoom-in-center">
		<div class="NCC-preview-main">
			<div class="NCC-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="24">
						<el-form-item label-width="0">
							<groupTitle content-position="left" content="基本信息"></groupTitle>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="姓名" prop="realName">
							<el-input v-model="dataForm.realName" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="性别" prop="gender">
							<el-select v-model="dataForm.gender" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in genderOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="证件类型" prop="certificatesType">
							<el-select v-model="dataForm.certificatesType" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in certificatesTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="证件号码" prop="certificatesNumber">
							<el-input v-model="dataForm.certificatesNumber" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="联系电话" prop="mobilePhone">
							<el-input v-model="dataForm.mobilePhone" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="邮箱" prop="email">
							<el-input v-model="dataForm.email" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="学历" prop="education">
							<el-select v-model="dataForm.education" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in educationOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="民族" prop="nation">
							<el-select v-model="dataForm.nation" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in nationOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="毕业院校" prop="school">
							<el-input v-model="dataForm.school" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="所学专业" prop="specialty">
							<el-input v-model="dataForm.specialty" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="银行账号" prop="bankAccount">
							<el-input v-model="dataForm.bankAccount" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="开户行" prop="bank">
							<el-input v-model="dataForm.bank" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="通讯地址" prop="postalAddress">
							<el-input v-model="dataForm.postalAddress" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label-width="0">
							<groupTitle content-position="left" content="技能能力"></groupTitle>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="擅长领域" prop="field">
							<el-select v-model="dataForm.field" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in fieldOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="技术资格/职称" prop="professional">
							<el-input v-model="dataForm.professional" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="工作单位" prop="workUnit">
							<el-input v-model="dataForm.workUnit" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="工作日期" prop="workDate">
							<el-date-picker v-model="dataForm.workDate" placeholder="请选择" clearable :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="证件/资料" prop="appendix">
							<NCC-UploadFz v-model="dataForm.appendix" :fileSize="2" sizeUnit="MB" :limit="9" buttonText="点击上传" >
							</NCC-UploadFz>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建用户" prop="creatorUserId">
							<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建时间" prop="creatorTime">
							<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改用户" prop="lastModifyUserId">
							<el-input v-model="dataForm.lastModifyUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改时间" prop="lastModifyTime">
							<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					id:'',
					realName:undefined,
					gender:undefined,
					certificatesType:undefined,
					certificatesNumber:undefined,
					mobilePhone:undefined,
					email:undefined,
					education:undefined,
					nation:undefined,
					school:undefined,
					specialty:undefined,
					bankAccount:undefined,
					bank:undefined,
					postalAddress:undefined,
					field:undefined,
					professional:undefined,
					workUnit:undefined,
					workDate:undefined,
					appendix:[],
					remark:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					realName:[
						{
							required:true,
							message:'请输入姓名',
							trigger:'blur'
						},
					],
					gender:[
						{
							required:true,
							message:'请输入性别',
							trigger:'change'
						},
					],
					certificatesType:[
						{
							required:true,
							message:'请输入证件类型',
							trigger:'change'
						},
					],
					certificatesNumber:[
						{
							required:true,
							message:'请输入证件号码',
							trigger:'blur'
						},
					],
					mobilePhone:[
						{
							required:true,
							message:'请输入联系电话',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$/,
							message:'请输入正确的手机号码',
							trigger:'blur'
						},
					],
					email:[
						{
							pattern:/^[a-z0-9]+([._\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/,
							message:'请输入正确的邮箱',
							trigger:'blur'
						},
					],
					education:[
						{
							required:true,
							message:'请输入学历',
							trigger:'change'
						},
					],
					field:[
						{
							required:true,
							message:'请输入擅长领域',
							trigger:'change'
						},
					],
				},
				genderOptions : [],
				certificatesTypeOptions : [],
				educationOptions : [],
				nationOptions : [],
				fieldOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getgenderOptions();
			this.getcertificatesTypeOptions();
			this.geteducationOptions();
			this.getnationOptions();
			this.getfieldOptions();
		},
		mounted() {
        },
		methods: {
			getgenderOptions(){
				getDictionaryDataSelector('963255a34ea64a2584c5d1ba269c1fe6').then(res => {
					this.genderOptions = res.data.list
				});
			},
			getcertificatesTypeOptions(){
				getDictionaryDataSelector('7866376d5f694d4d851c7164bd00ebfc').then(res => {
					this.certificatesTypeOptions = res.data.list
				});
			},
			geteducationOptions(){
				getDictionaryDataSelector('6a6d6fb541b742fbae7e8888528baa16').then(res => {
					this.educationOptions = res.data.list
				});
			},
			getnationOptions(){
				getDictionaryDataSelector('b6cd65a763fa45eb9fe98e5057693e40').then(res => {
					this.nationOptions = res.data.list
				});
			},
			getfieldOptions(){
				getDictionaryDataSelector('206702191098987781').then(res => {
					this.fieldOptions = res.data.list
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyZbExpert/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
							if(!this.dataForm.appendix)this.dataForm.appendix=[];
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyZbExpert`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyZbExpert/' + this.dataForm.id,
                                method: 'PUT',
                                data: this.dataForm
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
