<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="key" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="key">
              <a-input-number v-model="model.key" placeholder="请输入key" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报工任务号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskno">
              <a-input v-model="model.taskno" placeholder="请输入报工任务号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskname">
              <a-input v-model="model.taskname" placeholder="请输入任务名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workcontent">
              <a-input v-model="model.workcontent" placeholder="请输入工作内容"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当日用时（h）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workhour">
              <a-input-number v-model="model.workhour" placeholder="请输入当日用时（h）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xhname">
              <a-input v-model="model.xhname" placeholder="请输入型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="研制数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzsl">
              <a-input-number v-model="model.yzsl" placeholder="请输入研制数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="研制阶段" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzjdname">
              <a-input v-model="model.yzjdname" placeholder="请输入研制阶段"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tcdw">
              <a-input v-model="model.tcdw" placeholder="请输入用户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户简称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brief">
              <a-input v-model="model.brief" placeholder="请输入用户简称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input v-model="model.status" placeholder="请输入状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jhkssj">
              <j-date placeholder="请选择计划开始时间" v-model="model.jhkssj"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划完成时间（进度要求）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jhwcsj">
              <j-date placeholder="请选择计划完成时间（进度要求）" v-model="model.jhwcsj"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="worktime">
              <j-date placeholder="请选择工作日期" v-model="model.worktime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="填写时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createtime">
              <j-date placeholder="请选择填写时间" v-model="model.createtime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <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="userdept">
              <a-input v-model="model.userdept" placeholder="请输入填报部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shr">
              <a-input v-model="model.shr" placeholder="请输入审核人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spr">
              <a-input v-model="model.spr" placeholder="请输入审批人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="memo">
              <a-textarea v-model="model.memo" rows="4" placeholder="请输入备注" />
            </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: 'KyBgInfoForm',
    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: {
           key: [
              { required: true, message: '请输入key!'},
           ],
        },
        url: {
          add: "/kyBgInfo/kyBgInfo/add",
          edit: "/kyBgInfo/kyBgInfo/edit",
          queryById: "/kyBgInfo/kyBgInfo/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>