<!--
 * @Author: ysh
 * @Date: 2024-05-10 15:50:41
 * @LastEditors: wrh
 * @LastEditTime: 2024-06-20 14:54:00
-->
<template>
  <div>
    <h2 style="text-align:center;">项目直接生产成本预算表</h2>
    <table border="1" class="table">
      <tr>
        <td style="width: 100px;">项目名称</td>
        <td colspan="6">{{ projectForm.projectName }}</td>
        <td>项目编号</td>
        <td colspan="1">{{ projectForm.projectNumber }}</td>
      </tr>
      <tr>
        <td :rowspan="workLen+2">直接成本</td>
        <td>工作简述</td>
        <td>工作内容</td>
        <td>数量</td>
        <td>单价</td>
        <td>单位</td>
        <td>系数</td>
        <td>金额</td>
        <td style="width: 250px;">备注</td>
      </tr>
      <tr v-for="work in budgetForm.contentList">
        <td>{{ work.content }}</td>
        <td>{{ work.workItem }}</td>
        <td>{{ work.workload }}</td>
        <td>{{ work.price }}</td>
        <td>{{ work.unit }}</td>
        <td>{{ work.coefficient }}</td>
        <td>{{ work.settle }}</td>
        <td>{{ work.remark ? work.remark : '' }}</td>
      </tr>
      <tr>
        <td :colspan="6" class="head">直接成本合计</td>
        <td :colspan="1" class="head">{{ budgetForm.settleExpense }}</td>
        <td></td>
      </tr>
      <tr>
        <td :rowspan="userLen + carLen + deviceLen + 2">间接成本</td>
      </tr>
      <tr v-if="userLen != 1">
        <td :rowspan="userLen">人员</td>
        <td>姓名</td>
        <td>基本工资</td>
        <td>岗位工资</td>
        <td>人员成本（天）</td>
        <!-- <td>进出场单价</td> -->
        <td>预算天数</td>
        <td>金额</td>
        <td></td>
      </tr>
      <tr v-for="user in budgetForm.chooseUser" :key="'user' + user.userId">
        <td>{{ user.nickName }}</td>
        <td>1780</td>
        <td>{{ user.salary.salary }}</td>
        <td>{{ parseFloat((user.salary.salary + 1780) / 21.75).toFixed(2) }}</td>
        <!-- <td>{{ user.inOutPrice }}</td> -->
        <td>{{ user.days }}</td>
        <td>{{ user.staffCost }}</td>
        <td></td>
      </tr>
      <tr v-if="carLen != 1">
        <td :rowspan="carLen">车辆</td>
        <td>车牌号</td>
        <td>油耗</td>
        <td>总里程</td>
        <td>折旧成本（天）</td>
        <td>预算天数</td>
        <td>金额</td>
        <!-- <td></td> -->
      </tr>
      <tr v-for="car in budgetForm.chooseCar" :key="'car' + car.carId">
        <td>{{ car.licensePlate }}</td>
        <td>{{ car.mileage }}</td>
        <td>{{ car.distance }}</td>
        <td>{{ car.dayCost }}</td>
        <td>{{ car.days }}</td>
        <td>{{ car.expense }}</td>
        <td></td>
      </tr>
      <tr v-if="deviceLen != 1">
        <td :rowspan="deviceLen">设备</td>
        <td>设备名称</td>
        <td>规格型号</td>
        <td>品牌</td>
        <td>折旧成本（天）</td>
        <td>预算天数</td>
        <td>金额</td>
        <!-- <td>备注</td> -->
      </tr>
      <tr v-for="device in budgetForm.chooseDevice" :key="'device' + device.deviceId">
        <td>{{ device.name }}</td>
        <td>{{ device.series }}</td>
        <td>{{ device.brand }}</td>
        <td>{{ device.dayCost }}</td>
        <td>{{ device.days }}</td>
        <td>{{ device.depreciation }}</td>
        <td></td>
      </tr>
      <tr>
        <td :colspan="6" class="head">间接成本合计</td>
        <td :colspan="1" class="head">{{ budgetForm.fixCost }}</td>
        <td></td>
      </tr>
      <tr class="head">
        <td :colspan="3">外协费用</td>
        <td :colspan="5">{{ budgetForm.outExpense }}</td>
        <td>{{ budgetForm.outRemark }}</td>
      </tr>
      <tr class="head">
        <td colspan="3">车船租赁</td>
        <td :colspan="5">{{ budgetForm.rentExpense }}</td>
        <td>{{ budgetForm.rentRemark }}</td>
      </tr>
      <tr class="head">
        <td colspan="3">其他费用</td>
        <td :colspan="5">{{ budgetForm.otherExpense }}</td>
        <td>{{ budgetForm.otherRemark }}</td>
      </tr>
      <tr class="head">
        <td colspan="3">税费成本</td>
        <td :colspan="5">{{ budgetForm.taxExpense }}</td>
        <td>{{ budgetForm.taxRemark }}</td>
      </tr>
      <tr class="head">
        <td colspan="3">经营管理费用</td>
        <td :colspan="5">{{ budgetForm.businessExpense }}</td>
        <td>{{ budgetForm.businessRemark }}</td>
      </tr>
      <tr>
        <td colspan="3" class="head">成本合计</td>
        <td colspan="5" class="head">{{ costSum }}</td>
      </tr>
      <tr v-if="budgetForm.contract">
        <td colspan="3" class="head">利润</td>
        <td colspan="2" class="head">{{ profit }}</td>
        <td colspan="3" class="head">合同总价约</td>
        <td colspan="1" class="head">{{ budgetForm.contract ? budgetForm.contract.amount : '' }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  props: {
    budgetForm: {
      type: Object,
      require: true
    },
    projectForm: {
      type: Object,
      require: true
    }
  },
  data() {
    return {
      userLen: 1,
      carLen: 1,
      deviceLen: 1,
      workLen: 1,
      costSum: 0,
      inOutPrice: '',
      profit:''
    }
  },
  created() {
    this.userLen = this.budgetForm.chooseUser.length + 1;
    this.carLen = this.budgetForm.chooseCar.length + 1;
    this.deviceLen = this.budgetForm.chooseDevice.length + 1;
    this.workLen = this.budgetForm.contentList.length;
    this.costSum = (Number(this.budgetForm.directExpense) + Number(this.budgetForm.fixCost) ).toFixed(2);
    if(this.budgetForm.contract){
      this.profit = (Number(this.budgetForm.contract.amount) - Number(this.costSum) ).toFixed(2)
    }
    this.$emit('getTotal', this.costSum);
  },
}
</script>

<style lang="scss" scoped>
.table {
  /*居中*/
  // margin: 0 auto;
  /*边框*/
  /* border: 1px solid black; */
  text-align: center;
  border-collapse: collapse;
  margin: 0 auto;

  /*设置背景颜色*/
  /* background-color: #bfa; */
  td {
    padding: 5px;
    height: 40px;
  }
}

.head {
  // background-color: var(--current-color);
  // opacity: 0.5;
  // color: #fff;
  font-weight: bold;
}
</style>