<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="合同文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fileContract">
              <j-upload v-model="model.fileContract"   ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司签署" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signCompany">
              <j-dict-select-tag type="list" v-model="model.signCompany" dictCode="contract_status" placeholder="请选择公司签署" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="求职者签署" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signPerson">
              <j-dict-select-tag type="list" v-model="model.signPerson" dictCode="contract_status" placeholder="请选择求职者签署" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title">
              <a-input v-model="model.title" placeholder="请输入合同标题"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同甲方名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nameA">
              <a-input v-model="model.nameA" placeholder="请输入合同甲方名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同乙方名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nameB">
              <a-input v-model="model.nameB" placeholder="请输入合同乙方名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联招聘者id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bossId">
              <j-dict-select-tag type="list" v-model="model.bossId" dictCode="han_hai_member,nick_name,id" placeholder="请选择关联招聘者id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联求职者id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="personId">
              <j-dict-select-tag type="list" v-model="model.personId" dictCode="han_hai_member,nick_name,id" placeholder="请选择关联求职者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: 'EmployContractForm',
    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: "/employContract/employContract/add",
          edit: "/employContract/employContract/edit",
          queryById: "/employContract/employContract/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>