<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="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="workAddress">
              <a-input v-model="model.workAddress" placeholder="请输入工作地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工龄要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workAge">
              <a-input v-model="model.workAge" placeholder="请输入工龄要求"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="学历要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qulification">
              <a-input v-model="model.qulification" placeholder="请输入学历要求"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="薪资下限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salaryLow">
              <a-input-number v-model="model.salaryLow" placeholder="请输入薪资下限" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="薪资上限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salaryUp">
              <a-input-number v-model="model.salaryUp" placeholder="请输入薪资上限" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="招聘者职位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="career">
              <a-input v-model="model.career" placeholder="请输入招聘者职位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="职位详情" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workDetail">
              <j-editor v-model="model.workDetail" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="招聘公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="company">
              <j-dict-select-tag type="list" v-model="model.company" dictCode="employ_company,company_name,id" placeholder="请选择招聘公司名称" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tab">
              <a-input v-model="model.tab" placeholder="请输入标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工种类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="typeId">
              <j-dict-select-tag type="list" v-model="model.typeId" dictCode="employ_job_type,name,id" placeholder="请选择工种类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="natureId">
              <j-dict-select-tag type="list" v-model="model.natureId" dictCode="employ_nature,name,id" placeholder="请选择工作性质" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联用户id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <j-dict-select-tag type="list" v-model="model.userId" 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="areaId">
              <j-dict-select-tag type="list" v-model="model.areaId" dictCode="employ_address,adress,id" placeholder="请选择关联区域id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longitude">
              <a-input-number v-model="model.longitude" placeholder="请输入经度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="纬度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latitude">
              <a-input-number v-model="model.latitude" placeholder="请输入纬度" style="width: 100%" />
            </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: 'EmployJobForm',
    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: "/employJob/employJob/add",
          edit: "/employJob/employJob/edit",
          queryById: "/employJob/employJob/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>