<!--
 * @Author: ysh
 * @Date: 2024-04-03 16:28:09
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-04-17 15:21:14
-->
<template>
  <div class="main">
    <h2 style="text-align: center">项目直接生产成本预算表</h2>
    <table border="1" class="table">
      <tr>
        <td class="head">项目名称</td>
        <td colspan="3">{{ budgetForm.project ? budgetForm.project.projectName : '' }}</td>
        <td class="head">项目编号</td>
        <td colspan="2">{{ budgetForm.project ? budgetForm.project.projectNumber : '' }}</td>
      </tr>
      <tr>
        <td :rowspan="userLen" class="head vertical-text">人员</td>
        <td class="head" style="width:250px">姓名</td>
        <td class="head">部门</td>
        <td class="head">岗位工资</td>
        <td class="head">人员成本（天）</td>
        <!-- <td class="head">进出场单价</td> -->
        <td class="head">预算天数</td>
        <td class="head">金额</td>
      </tr>
      <tr v-for="user, index in chooseUser" :key="'user' + index">
        <td>{{ user.user ? user.user.nickName : '' }}</td>
        <td>{{ user.dept? user.dept.deptName : '' }}</td>
        <td>{{ user.salary.salary }}</td>
        <td>{{ parseFloat(user.salary.salary / 31).toFixed(2) }}</td>
        <td>{{ user.days }}</td>
        <td>{{ user.staffCost }}</td>
      </tr>
      <tr>
        <td :rowspan="carLen" class="head vertical-text">车辆</td>
        <td class="head">车牌号</td>
        <td class="head">油耗</td>
        <td class="head">总里程</td>
        <td class="head">折旧成天（天）</td>
        <td class="head">预算天数</td>
        <td class="head">金额</td>
      </tr>
      <tr v-for="car, index in chooseCar" :key="'car' + index">
        <td>{{ car.car ? car.car.licensePlate : '' }}</td>
        <td>{{ car.mileage }}</td>
        <td>{{ car.distance }}</td>
        <td>{{ car.car ? car.car.dayCost : '' }}</td>
        <td>{{ car.days }}</td>
        <td>{{ car.expense }}</td>
      </tr>
      <tr>
        <td :rowspan="deviceLen" class="head vertical-text">设备</td>
        <td class="head">设备名称</td>
        <td class="head">规格型号</td>
        <td class="head">品牌</td>
        <td class="head">折旧成本（天）</td>
        <td class="head">预算天数</td>
        <td class="head">金额</td>
      </tr>
      <tr v-for="device, index in chooseDevice" :key="'device' + index">
        <td>{{ device.device ? device.device.name : '' }}</td>
        <td>{{ device.device ? device.device.series : '' }}</td>
        <td>{{ device.device ? device.device.brand : '' }}</td>
        <td>{{ device.device ? device.device.dayCost : '' }}</td>
        <td>{{ device.days }}</td>
        <td>{{ device.depreciation }}</td>
      </tr>
      <tr>
        <td colspan="6" class="head">固定成本小计</td>
        <td>{{ budgetForm.fixCost }}</td>
      </tr>
      <tr>
        <td :rowspan="workLen" class="head vertical-text">预计结算金额</td>
        <td class="head">工作内容</td>
        <td class="head">比例尺</td>
        <td class="head">总工作量</td>
        <td class="head">单价</td>
        <td class="head">系数</td>
        <td class="head">金额</td>
      </tr>
      <tr v-for="(work, index) in workList" :key="'work' + index">
        <td>{{ workContentList.length != 0 ? workContentList[index].content : "" }}</td>
        <td>{{ work.scaleGrade }}</td>
        <td>{{ work.workload }}</td>
        <td>{{ work.price }}</td>
        <td>{{ work.coefficient }}</td>
        <td>{{ work.settle }}</td>
      </tr>
      <tr>
        <td colspan="5" class="head">进出场津贴</td>
        <td>{{ budgetForm.inOutPriceSum }}</td>
      </tr>
      <tr>
        <td colspan="5" class="head">外协费用</td>
        <td>{{ budgetForm.outExpense }}</td>
      </tr>
      <tr>
        <td colspan="5" class="head">商务费用</td>
        <td>{{ budgetForm.businessExpense }}</td>
      </tr>
      <tr>
        <td colspan="5" class="head">车船租赁</td>
        <td>{{ budgetForm.rentExpense }}</td>
      </tr>
      <tr>
        <td colspan="5" class="head">其他费用</td>
        <td>{{ budgetForm.otherExpense }}</td>
      </tr>
      <tr>
        <td colspan="6" class="head">直接成本小计</td>
        <td>{{ budgetForm.directExpense }}</td>
      </tr>
      <tr>
        <td colspan="6" class="head">总成本=（固定成本+直接成本）*120%</td>
        <td>{{ budgetForm.totalBudget }}</td>
      </tr>
      <tr>
        <td class="head">编制人</td>
        <td colspan="2">{{ budgetForm.compilerUser ? budgetForm.compilerUser.nickName :'' }}</td>
        <td class="head">审核人</td>
        <td colspan="3">{{ name }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
import { listBudget } from "@/api/oa/budget/budget";
import { listBudgetCar, getBudgetCar } from "@/api/oa/budget/budgetCar";
import { listBudgetDevice, getBudgetDevice } from "@/api/oa/budget/budgetDevice";
import { listBudgetSettle, getBudgetSettle } from "@/api/oa/budget/budgetSettle";
import { listBudgetStaff, getBudgetStaff } from "@/api/oa/budget/budgetStaff";
import { getProjectWork } from "@/api/oa/project/projectWork";
import { mapGetters } from 'vuex';
export default {
  computed: {
    ...mapGetters(["name", "userId"]),
  },
  props: {
    taskForm: {
      type: Object,
      require: true
    }
  },
  data() {
    return {
      projectId: '',
      budgetForm: {
      },
      projectForm: {},
      userLen: 1,
      carLen: 1,
      deviceLen: 1,
      workLen: 1,
      totalBudget: 0,
      chooseCar: [],
      chooseDevice: [],
      chooseUser: [],
      workList: [],
      workContentList: []
    };
  },
  created() {
    this.initBudgetForm();
    this.totalBudget = (
      (Number(this.budgetForm.directExpense) + Number(this.budgetForm.fixCost)) *
      1.2
    ).toFixed(2);
  },
  methods: {
    initBudgetForm() {
      listBudget({ pageNum: 1, pageSize: 20, projectId: this.taskForm.formId }).then(res => {
        console.log(res);
        this.budgetForm = res.rows[0];
        getBudgetDevice(this.budgetForm.budgetId).then(res => {
          this.chooseDevice = res.data;
          this.deviceLen = res.data.length + 1;
        })
        getBudgetStaff(this.budgetForm.budgetId).then(res => {
          this.chooseUser = res.data;
          this.userLen = res.data.length + 1;
          let days = 0;
          for(let d of this.chooseUser){
            days = days + d.days
          }
          this.budgetForm.inOutPriceSum = Number(days) * Number(this.chooseUser[0].inOutPrice)
        })
        getBudgetCar(this.budgetForm.budgetId).then(res => {
          this.chooseCar = res.data;
          this.carLen = res.data.length + 1;
        })
        getBudgetSettle(this.budgetForm.budgetId).then(res => {
          this.workList = res.data;
          this.workLen = res.data.length + 6;
          for(let work of this.workList){
            if(work.groundType == '0'){
              work.price = work.cmcPrice.commonPrice
              work.scaleGrade = work.cmcPrice.scaleGrade
            }else{
              work.price = work.cmcPrice.complexPrice
            }
          }
          this.getProjectWorkList();
        })
      });
    },
    getProjectWorkList() {
      getProjectWork(this.$route.query.formId).then(res => {
        this.workContentList = res.data;
      })
    },
  },
};
</script>

<style lang="scss" scoped>
.main {
  width: 1200px;
  margin: 0 auto;
  text-align: center;
}

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

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

.head {
  line-height: 35px;
  font-weight: bold;
}
</style>
