budgetEdit.vue 3.17 KB
<template>
  <div>
    <a-row>
      <a-col :span="24">
        <div class="tb-title">
          <span>项目经费 <strong>(单位:万元)</strong></span>
        </div>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="6" class="bg-gray">
        预算科目
      </a-col>
      <a-col :span="3" class="bg-gray">
        总预算数
      </a-col>
      <a-col :span="5" class="bg-gray">
        市卫健委科技经费
      </a-col>
      <a-col :span="5" class="bg-gray">
        单位自筹经费
      </a-col>
      <a-col :span="5" class="bg-gray">
        备注
      </a-col>
    </a-row>

    <template v-for="(item, index) in budget">
      <a-row :key="'budget' + index" v-if="item.type ==='count'">
        <a-col :span="6">
          {{item.budgetName}}
        </a-col>
        <a-col :span="3">
          {{Count(item.source,'totalBudget',index)}}
        </a-col>
        <a-col :span="5">
          {{Count(item.source,'govBudget',index)}}
        </a-col>
        <a-col :span="5">
          {{Count(item.source,'unitBudget',index)}}
        </a-col>
        <a-col :span="5">
          <a-input v-model="item.remark" :maxLength="100" style="width: 80%;" />
        </a-col>
      </a-row>
      <a-row :key="'budget' + index" v-else>
        <a-col :span="6">
          {{item.budgetName}}
        </a-col>
        <a-col :span="3">
          {{Count1(index, item.govBudget, item.unitBudget)}}
        </a-col>
        <a-col :span="5">
          <a-input-number v-model="item.govBudget" :min="0" :step="0.01" style="width: 80%" :disabled="item.disabled === 'unitBudget'" />
        </a-col>
        <a-col :span="5">
          <a-input-number v-model="item.unitBudget" :min="0" :step="0.01" style="width: 80%" :disabled="item.disabled === 'govBudget'" />
        </a-col>
        <a-col :span="5">
          <a-input v-model="item.remark" :maxLength="100" style="width: 80%;" />
        </a-col>
      </a-row>
    </template>
  </div>
</template>
<script>
// 用法 <budget-edit  :budget.sync="formData.budget" />
export default {
  name: "BudgetEdit",
  data() {
    return {
      // budget: this.value,
    };
  },
  props: {
    budget: {
      type: Array,
      default: () => {
        return []
      }
    },
  },
  created() {

  },
  methods: {
    // 计算经费合计数值
    Count(source, type, index) {
      if (!source || !source.length) {
        return 0
      }
      let govBudget = 0, unitBudget = 0
      source.forEach(i => {
        govBudget = govBudget + this.budget[i].govBudget
        unitBudget = unitBudget + this.budget[i].unitBudget
      })
      if (type === 'govBudget') {
        this.budget[index].govBudget = govBudget.toFixed(2)
        return govBudget.toFixed(2)
      } else if (type === 'unitBudget') {
        this.budget[index].unitBudget = unitBudget.toFixed(2)
        return unitBudget.toFixed(2)
      } else {
        this.budget[index].totalBudget = (govBudget + unitBudget).toFixed(2)
        return (govBudget + unitBudget).toFixed(2)
      }
    },
    Count1(index, govBudget, unitBudget) {
      this.budget[index].totalBudget = (govBudget + unitBudget).toFixed(2)
      return (govBudget + unitBudget).toFixed(2)
    }
  },
};
</script>