<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="1寸白底照片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageHead1">
              <j-image-upload isMultiple  v-model="model.imageHead1" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="2寸白底彩照" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageHead2">
              <j-image-upload isMultiple  v-model="model.imageHead2" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="身份证正面照复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageCardFront">
              <j-image-upload isMultiple  v-model="model.imageCardFront" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="身份证反面照复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageCardfBack">
              <j-image-upload isMultiple  v-model="model.imageCardfBack" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="学历证书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageDiploma">
              <j-image-upload isMultiple  v-model="model.imageDiploma" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="操作证正面复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageOperationFront">
              <j-image-upload isMultiple  v-model="model.imageOperationFront" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="操作证反面复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageOperationBack">
              <j-image-upload isMultiple  v-model="model.imageOperationBack" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageApply">
              <j-image-upload isMultiple  v-model="model.imageApply" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="个人健康承诺书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageHealth">
              <j-image-upload isMultiple  v-model="model.imageHealth" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业执照复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageBusiness">
              <j-image-upload isMultiple  v-model="model.imageBusiness" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="户口本本人页复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageHousehold">
              <j-image-upload isMultiple  v-model="model.imageHousehold" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="健康码复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageHealthcode">
              <j-image-upload isMultiple  v-model="model.imageHealthcode" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行程码复印件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageRoutecode">
              <j-image-upload isMultiple  v-model="model.imageRoutecode" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageHead">
              <j-image-upload isMultiple  v-model="model.imageHead" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cerNo">
              <a-input v-model="model.cerNo" placeholder="请输入身份证号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyName">
              <a-input v-model="model.companyName" placeholder="请输入工作单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联证书id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cerId">
              <j-search-select-tag v-model="model.cerId" dict="employ_cert,name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联用户id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <j-search-select-tag v-model="model.userId" dict="han_hai_member,nick_name,id"  />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'EmployRedisterForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/employRedister/employRedister/add",
          edit: "/employRedister/employRedister/edit",
          queryById: "/employRedister/employRedister/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>