<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="nd">
              <a-input v-model="model.nd" placeholder="请输入年度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="凭证日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pzrq">
              <a-input v-model="model.pzrq" placeholder="请输入凭证日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="凭证号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pzh">
              <a-input v-model="model.pzh" placeholder="请输入凭证号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="摘要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zy">
              <a-input v-model="model.zy" placeholder="请输入摘要"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="科目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kmbh">
              <a-input v-model="model.kmbh" placeholder="请输入科目编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="科目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="km">
              <a-input v-model="model.km" placeholder="请输入科目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="方向" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fx">
              <a-input v-model="model.fx" placeholder="请输入方向"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="je">
              <a-input v-model="model.je" placeholder="请输入金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bm">
              <a-input v-model="model.bm" placeholder="请输入部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="往来单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wldw">
              <a-input v-model="model.wldw" placeholder="请输入往来单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="辅助金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fzje">
              <a-input v-model="model.fzje" placeholder="请输入辅助金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制单人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zdr">
              <a-input v-model="model.zdr" placeholder="请输入制单人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="会计期间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kjqj">
              <a-input v-model="model.kjqj" placeholder="请输入会计期间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="凭证内码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pznm">
              <a-input v-model="model.pznm" placeholder="请输入凭证内码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xmbh">
              <a-input v-model="model.xmbh" placeholder="请输入项目编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xmmc">
              <a-input v-model="model.xmmc" placeholder="请输入项目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xmlb">
              <a-input v-model="model.xmlb" placeholder="请输入项目类别"  ></a-input>
            </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-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: 'ProjectChbWxfForm',
    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: "/projectChbWxf/projectChbWxf/add",
          edit: "/projectChbWxf/projectChbWxf/edit",
          queryById: "/projectChbWxf/projectChbWxf/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>