<!--
 * @Author: ysh
 * @Date: 2025-05-15 18:24:27
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-05-19 15:26:20
-->
<template>
  <div class="business-cost">
    <table border="1" style="width:100%;">
      <tr style="background-color:#f8f8f9">
        <td style="width: 50px;">序号</td>
        <td>名称</td>
        <td>金额</td>
        <td class="adjust">核算金额</td>
        <td>备注</td>
      </tr>
      <tr>
        <td>{{ 1 }}</td>
        <td>外协费用</td>
        <td style="text-align:right;">
          {{ budgetForm.outExpense }}
        </td>
        <td style="text-align:right;">
          <template v-if="taskName === '核算编制'">
            <el-input-number :controls="false" v-model="budgetForm.outAdjust" :min="0" :step="0.01"
              @change="updateTotalJYAmount"></el-input-number>
          </template>
          <span v-else>{{ budgetForm.outAdjust }}</span>
        </td>
        <td class="remark-cell">{{ budgetForm.outRemark }}</td>
      </tr>
      <tr>
        <td>{{ 2 }}</td>
        <td>保函费用</td>
        <td style="text-align:right;">
          {{ budgetForm.letterExpense }}
        </td>
        <td style="text-align:right;">
          <template v-if="taskName === '核算编制'">
            <el-input-number :controls="false" v-model="budgetForm.letterAdjust" :min="0" :step="0.01"
              @change="updateTotalJYAmount"></el-input-number>
          </template>
          <span v-else>{{ budgetForm.letterAdjust }}</span>
        </td>
        <td class="remark-cell">{{ budgetForm.letterRemark }}</td>
      </tr>
      <tr>
        <td>{{ 3 }}</td>
        <td>中标服务费</td>
        <td style="text-align:right;">
          {{ budgetForm.winExpense }}
        </td>
        <td style="text-align:right;">
          <template v-if="taskName === '核算编制'">
            <el-input-number :controls="false" v-model="budgetForm.winAdjust" :min="0" :step="0.01"
              @change="updateTotalJYAmount"></el-input-number>
          </template>
          <span v-else>{{ budgetForm.winAdjust }}</span>
        </td>
        <td class="remark-cell">{{ budgetForm.winRemark }}</td>
      </tr>
      <tr>
        <td>{{ 4 }}</td>
        <td>税费</td>
        <td style="text-align:right;">
          {{ budgetForm.taxExpense }}
        </td>
        <td style="text-align:right;">
          <template v-if="taskName === '核算编制'">
            <el-input-number :controls="false" v-model="budgetForm.taxAdjust" :min="0" :step="0.01"
              @change="updateTotalJYAmount"></el-input-number>
          </template>
          <span v-else>{{ budgetForm.taxAdjust }}</span>
        </td>
        <td class="remark-cell">{{ budgetForm.taxRemark }}</td>
      </tr>
      <tr>
        <td>{{ 5 }}</td>
        <td>差旅费用</td>
        <td style="text-align:right;">
          {{ budgetForm.travelExpense }}
        </td>
        <td style="text-align:right;">
          <template v-if="taskName === '核算编制'">
            <el-input-number :controls="false" v-model="budgetForm.travelAdjust" :min="0" :step="0.01"
              @change="updateTotalJYAmount"></el-input-number>
          </template>
          <span v-else>{{ budgetForm.travelAdjust }}</span>
        </td>
        <td class="remark-cell">{{ budgetForm.travelRemark }}</td>
      </tr>
      <tr>
        <td colspan="2" class="amount">经营相关合计</td>
        <td class="amount" style="text-align:right;">
          {{ totalJYAmount }}
        </td>
        <td class="amount" style="text-align:right;">
          {{ totalJYAmountAdjust }}
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  props: {
    budgetForm: {
      type: Object,
      required: true
    },
    taskName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      totalJYAmount: 0,
      totalJYAmountAdjust: 0
    }
  },
  created() {
    this.initTotalJYAmount();
    this.updateTotalJYAmount();
  },
  methods: {
    initTotalJYAmount() {
      this.totalJYAmount = ((Number(this.budgetForm.outExpense) || 0) + (Number(this.budgetForm.letterExpense) || 0) + (Number(this.budgetForm.winExpense) || 0) + (Number(this.budgetForm.taxExpense) || 0) + (Number(this.budgetForm.travelExpense) || 0)).toFixed(2)

    },
    updateTotalJYAmount() {
      this.totalJYAmountAdjust = ((Number(this.budgetForm.outAdjust) || 0) + (Number(this.budgetForm.letterAdjust) || 0) + (Number(this.budgetForm.winAdjust) || 0) + (Number(this.budgetForm.taxAdjust) || 0) + (Number(this.budgetForm.travelAdjust) || 0)).toFixed(2)
      this.$emit('update:budgetForm', this.budgetForm);
    }
  }
}
</script>

<style lang="scss" scoped>
.business-cost {
  .add-staff {
    margin-bottom: 10px;
  }

  table {
    text-align: center;
    border-collapse: collapse;
    margin: 0 auto;

    td {
      padding: 5px;
    }
  }

  .adjust {
    color: #F56C6C;
    width: 120px;
  }
}

.amount {
  font-weight: bold;
  font-family: Arial, Helvetica, sans-serif;
}

.remark-cell {
  text-align: left;
}
</style>