<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="xuhao">
              <a-input v-model="model.xuhao" placeholder="请输入序号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskNumber">
              <a-input v-model="model.taskNumber" 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="model">
              <a-input v-model="model.model" placeholder="请输入型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="材料费（物资处采购项目）(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cailiaofei">
              <a-input v-model="model.cailiaofei" placeholder="请输入材料费（物资处采购项目）(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="可靠性设计(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kkxSheji">
              <a-input v-model="model.kkxSheji" placeholder="请输入可靠性设计(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结构加工(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jgJiagong">
              <a-input v-model="model.jgJiagong" placeholder="请输入结构加工(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="表面处理(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bmChuli">
              <a-input v-model="model.bmChuli" placeholder="请输入表面处理(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="环境试验(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hjShiyan">
              <a-input v-model="model.hjShiyan" placeholder="请输入环境试验(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电缆加工(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dlJiagong">
              <a-input v-model="model.dlJiagong" placeholder="请输入电缆加工(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="印制板设计及加工(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzbSheji">
              <a-input v-model="model.yzbSheji" placeholder="请输入印制板设计及加工(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试验工装(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="syGongzhuang">
              <a-input v-model="model.syGongzhuang" placeholder="请输入试验工装(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="测试工装(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="csGongzhuang">
              <a-input v-model="model.csGongzhuang" placeholder="请输入测试工装(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="包装箱(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baozhuangxiang">
              <a-input v-model="model.baozhuangxiang" placeholder="请输入包装箱(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="软件设计(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rjSheji">
              <a-input v-model="model.rjSheji" placeholder="请输入软件设计(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他项目(万)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qtXiangmu">
              <a-input v-model="model.qtXiangmu" placeholder="请输入其他项目(万)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务板块" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ywBankuai">
              <a-input v-model="model.ywBankuai" placeholder="请输入业务板块"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="研制数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzNumber">
              <a-input v-model="model.yzNumber" placeholder="请输入研制数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="研制阶段" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzJieduan">
              <a-input v-model="model.yzJieduan" placeholder="请输入研制阶段"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rwLaiyuan">
              <a-input v-model="model.rwLaiyuan" placeholder="请输入任务来源"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="责任部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zrDepartment">
              <a-input v-model="model.zrDepartment" placeholder="请输入责任部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jhLaishi">
              <j-date placeholder="请选择计划开始时间"  v-model="model.jhLaishi" :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="jhWancheng">
              <j-date placeholder="请选择计划完成时间"  v-model="model.jhWancheng" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" 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: 'ProjectBudgetForm',
    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: "/projectBudget/projectBudget/add",
          edit: "/projectBudget/projectBudget/edit",
          queryById: "/projectBudget/projectBudget/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>