<!--
 * @Author: ysh
 * @Date: 2024-12-16 10:42:55
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-12-19 16:49:37
-->
<template>
  <div>
    <div class="text-center header">分包合同列表</div>
    <el-table :data="subContractList" v-loading="loading" :height="220">
      <el-table-column label="序号" type="index"></el-table-column>
      <el-table-column label="分包合同名称" prop="subContractName"></el-table-column>
      <el-table-column label="承接单位" align="center" prop="partner.partnerName" />
      <el-table-column label="分包合同金额" align="center" prop="subAmount" />
    </el-table>
    <div class="mt10 mr20 text-right footer">
      <span class="mr20">共{{ total }}个分包合同</span>
      <span>分包合同额合计：{{ subAmount }}</span>
    </div>
  </div>
</template>

<script>
import { listSubContract, getSubContract, delSubContract, addSubContract, updateSubContract } from "@/api/oa/contract/subContract";
import { listContractSubcontract, delContractSubcontract, addContractSubcontract } from "@/api/oa/contract/contractSubcontract"
export default {
  props: {
    contract: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      subContractList: [],
      loading: true,
      total: 0,
      subAmount:0
    }
  },
  watch: {
    contract: {
      handler() {
        this.getList()
      },
      deep: true
    },
    subAmount(val){
      this.$emit('getSumAmount',val)
    }
  },
  mounted() {
  },
  methods: {
    getList() {
      this.subContractList = []
      this.loading = true;
      listContractSubcontract({ pageNum: 1, pageSize: 999, contractId: this.contract.contractId }).then(async res => {
        let subContractIds = res.rows.map(item => item.subContractId)
        for (let id of subContractIds) {
          let resData = await getSubContract(id);
          this.subContractList.push(resData.data);
        }
        this.subAmount = this.subContractList.reduce((sum,item)=>sum + item.subAmount,0)
        this.total = this.subContractList.length;
        this.loading = false;
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.header {
  font-family: 'puhuiti';
  font-size: 18px;
  line-height: 30px;
}
.footer{
  font-size: 14px;
  font-family: 'puhuiti';
}
</style>