<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="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="processpercent">
              <a-input-number v-model="model.processpercent" placeholder="请输入项目进度/来自科研任务" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="责任部门/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zrbm">
              <a-input v-model="model.zrbm" placeholder="请输入责任部门/来自科研任务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下达部门/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jycs">
              <a-input v-model="model.jycs" placeholder="请输入下达部门/来自科研任务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同额/来自收款合同的合同分配额 " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractfpe">
              <a-input-number v-model="model.contractfpe" placeholder="请输入合同额/来自收款合同的合同分配额 " style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="已收款/ 来自合同收款详细的任务收款额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskmoney">
              <a-input-number v-model="model.taskmoney" placeholder="请输入已收款/ 来自合同收款详细的任务收款额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前任务进度的年份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <a-input-number v-model="model.year" placeholder="请输入当前任务进度的年份" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前任务进度的月份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="month">
              <a-input-number v-model="model.month" placeholder="请输入当前任务进度的月份" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前任务进度的年月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ym">
              <a-input v-model="model.ym" placeholder="请输入当前任务进度的年月"  ></a-input>
            </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: 'KzksKpiProjectMonthForm',
    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: "/kpiProjectMonth/kzksKpiProjectMonth/add",
          edit: "/kpiProjectMonth/kzksKpiProjectMonth/edit",
          queryById: "/kpiProjectMonth/kzksKpiProjectMonth/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>