<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="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="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="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="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="processpercent">
              <a-input v-model="model.processpercent" placeholder="请输入项目进度/来自科研任务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本进度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costPercent">
              <a-input v-model="model.costPercent" 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="单台收入/（合同额or预估价）/研制数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oneIncome">
              <a-input-number v-model="model.oneIncome" placeholder="请输入单台收入/（合同额or预估价）/研制数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单台成本/  总成本额/研制数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oneCost">
              <a-input-number v-model="model.oneCost" placeholder="请输入单台成本/  总成本额/研制数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单台利润/  利润额/研制数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oneProfit">
              <a-input-number v-model="model.oneProfit" placeholder="请输入单台利润/  利润额/研制数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="利润额/（合同额or预估价）-总成本额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lre">
              <a-input-number v-model="model.lre" placeholder="请输入利润额/（合同额or预估价）-总成本额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="利润率/ 利润额/（合同额or预估价）*100%" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lrl">
              <a-input-number v-model="model.lrl" placeholder="请输入利润率/ 利润额/（合同额or预估价）*100%" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预估价/来自财务预算" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="estimationcoat">
              <a-input-number v-model="model.estimationcoat" placeholder="请输入预估价/来自财务预算" style="width: 100%" />
            </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="zcb">
              <a-input-number v-model="model.zcb" placeholder="请输入总成本/ 直接成本+间接费用/直接成本=材料费（出库）+外协费+专用费+事务费/间接费用=工资费+管理费+燃动费+固资费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="材料费/物资出库单明细 实发主数量*采购单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="clf">
              <a-input-number v-model="model.clf" placeholder="请输入材料费/物资出库单明细 实发主数量*采购单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="专用费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zyf">
              <a-input-number v-model="model.zyf" placeholder="请输入专用费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事务费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="swf">
              <a-input-number v-model="model.swf" placeholder="请输入事务费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外协费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wxf">
              <a-input-number v-model="model.wxf" placeholder="请输入外协费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="燃料动力费/（材料费+外协费+事务费+专用费）×1.5%" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rldlf">
              <a-input-number v-model="model.rldlf" placeholder="请输入燃料动力费/（材料费+外协费+事务费+专用费）×1.5%" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="固定资产折旧/（材料费+外协费+事务费+专用费）×2.5%" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gdzczj">
              <a-input-number v-model="model.gdzczj" placeholder="请输入固定资产折旧/（材料费+外协费+事务费+专用费）×2.5%" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工资及劳务费/（材料费+外协费+事务费+专用费）×17%" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gzjlwf">
              <a-input-number v-model="model.gzjlwf" placeholder="请输入工资及劳务费/（材料费+外协费+事务费+专用费）×17%" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管理费/（材料费+外协费+事务费+专用费）×5%" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="glf">
              <a-input-number v-model="model.glf" placeholder="请输入管理费/（材料费+外协费+事务费+专用费）×5%" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="装机成本/ mes装机信息卡的采购单价*数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zjcb">
              <a-input-number v-model="model.zjcb" placeholder="请输入装机成本/ mes装机信息卡的采购单价*数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="内部试验" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lbsy">
              <a-input-number v-model="model.lbsy" placeholder="请输入内部试验" style="width: 100%" />
            </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="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="下达部门id/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jycsid">
              <a-input-number v-model="model.jycsid" placeholder="请输入下达部门id/来自科研任务" style="width: 100%" />
            </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="1：横向 2：纵向/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hxzxid">
              <a-input-number v-model="model.hxzxid" placeholder="请输入1：横向 2：纵向/来自科研任务" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="横向纵向/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hxzxname">
              <a-input v-model="model.hxzxname" placeholder="请输入横向纵向/来自科研任务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务类型/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tasktype">
              <a-input v-model="model.tasktype" placeholder="请输入任务类型/来自科研任务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审计审价/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditprice">
              <a-input v-model="model.auditprice" placeholder="请输入审计审价/来自科研任务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务状态/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="iflag">
              <a-input v-model="model.iflag" 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="reftaskno">
              <a-input-number v-model="model.reftaskno" placeholder="请输入父级任务/来自科研任务" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="批产任务号/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pccode">
              <a-input-number v-model="model.pccode" placeholder="请输入批产任务号/来自科研任务" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备产任务号/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bccode">
              <a-input-number v-model="model.bccode" placeholder="请输入备产任务号/来自科研任务" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备料任务号/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="blcode">
              <a-input-number v-model="model.blcode" placeholder="请输入备料任务号/来自科研任务" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务员/来自科研任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessman">
              <a-input v-model="model.businessman" placeholder="请输入业务员/来自科研任务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计工时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjgs">
              <a-input-number v-model="model.sjgs" placeholder="请输入设计工时" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产工时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scgs">
              <a-input-number v-model="model.scgs" placeholder="请输入生产工时" 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: 'ProjectCostHuijiForm',
    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: {
           xhname: [
              { required: true, message: '请输入型号/来自科研报工!'},
           ],
           yzsl: [
              { required: true, message: '请输入研制数量/来自科研任务!'},
           ],
           wxf: [
              { required: true, message: '请输入外协费!'},
           ],
           tasktype: [
              { required: true, message: '请输入任务类型/来自科研任务!'},
           ],
        },
        url: {
          add: "/projectCostHuiji/projectCostHuiji/add",
          edit: "/projectCostHuiji/projectCostHuiji/edit",
          queryById: "/projectCostHuiji/projectCostHuiji/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>