<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="userName">
              <a-input v-model="model.userName" placeholder="请输入用户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工人名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workName">
              <a-input v-model="model.workName" placeholder="请输入工人名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="头像图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="headPic">
              <j-image-upload isMultiple  v-model="model.headPic" ></j-image-upload>
            </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="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="工人出发地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workerAddress">
              <a-input v-model="model.workerAddress" placeholder="请输入工人出发地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出行方式 0出租车 1 网约车 2 公交地铁 3无" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="travelType">
              <j-dict-select-tag type="list" v-model="model.travelType" dictCode="travel_type" placeholder="请选择出行方式 0出租车 1 网约车 2 公交地铁 3无" />
            </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="industryName">
              <a-input v-model="model.industryName" placeholder="请输入行业/工种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工人个人简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detail">
              <j-editor v-model="model.detail" />
            </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="workPic">
              <j-image-upload isMultiple  v-model="model.workPic" ></j-image-upload>
            </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="bossPhone">
              <a-input v-model="model.bossPhone" placeholder="请输入招聘方联系方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="角色 0招聘方 1 求职方" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="role">
              <j-dict-select-tag type="list" v-model="model.role" dictCode="user_role" placeholder="请选择角色 0招聘方 1 求职方" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年龄" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="age">
              <a-input-number v-model="model.age" placeholder="请输入年龄" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gender">
              <j-dict-select-tag type="list" v-model="model.gender" dictCode="sex" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期望日薪" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dayMoney">
              <a-input-number v-model="model.dayMoney" placeholder="请输入期望日薪" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime">
              <j-date placeholder="请选择时间范围"  v-model="model.startTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime">
              <j-date placeholder="请选择时间范围"  v-model="model.endTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作时长" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workTime">
              <a-input v-model="model.workTime" placeholder="请输入工作时长"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期望薪资最小值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moneymin">
              <a-input-number v-model="model.moneymin" placeholder="请输入期望薪资最小值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期望薪资最大值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moneymax">
              <a-input-number v-model="model.moneymax" placeholder="请输入期望薪资最大值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核状态 0审核中 1 审核通过 2审核未通过" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">
              <j-dict-select-tag type="list" v-model="model.auditStatus" dictCode="audit_status" placeholder="请选择审核状态 0审核中 1 审核通过 2审核未通过" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算方式 0提前支付 1 试用后支付" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payType">
              <j-dict-select-tag type="list" v-model="model.payType" dictCode="pay_type" placeholder="请选择结算方式 0提前支付 1 试用后支付" />
            </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: 'TbTaskForm',
    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: "/tbTask/tbTask/add",
          edit: "/tbTask/tbTask/edit",
          queryById: "/tbTask/tbTask/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>