<!--
 * @Author: ysh
 * @Date: 2024-10-10 10:03:14
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-10-25 11:35:32
-->
<template>
  <div>
    <el-form-item label="主合同信息" label-width="120px">
      <div v-if="hasContract" v-loading="contractLoading">
        <el-descriptions border style="margin-top: 10px" :column="2" v-for="item,index in contractObjList" :key="index">
          <el-descriptions-item label="合同名称">
            {{ item.contractName }}
          </el-descriptions-item>
          <el-descriptions-item label="合同编码">
            {{ item.contractCode }}
          </el-descriptions-item>
          <el-descriptions-item label="合同编号">
            {{ item.contractNumber }}
          </el-descriptions-item>
          <el-descriptions-item label="合同价款">
            {{ item.amount }}
          </el-descriptions-item>
          <el-descriptions-item label="甲方单位">
            {{ item.partyA ? item.partyA.partyAName : '' }}
          </el-descriptions-item>
          <el-descriptions-item label="合同文件">
            <div v-if="item.contractDocument" class="upload-list">
              <el-link type="primary" @click="reviewWord(`${baseUrl}${'/profile/upload' + item.contractDocument}`)">
                {{ getFileName(item.contractDocument) }}
              </el-link>
              <el-link class="ml20" type="warning" :href="`${baseUrl}${'/profile/upload' + item.contractDocument}`"
                :underline="false" target="_blank">
                <span class="el-icon-download">下载文件</span>
              </el-link>
            </div>
            <div v-else>
              <el-tag type="info">暂无</el-tag>
            </div>
          </el-descriptions-item>
          <el-descriptions-item label="合同备注">
            {{ item.remark }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div v-else>
        <el-tag type="danger">暂无关联主合同信息</el-tag>
      </div>
    </el-form-item>
    <el-form-item label="分包合同信息" label-width="120px">
      <div v-if="hasSubContract" v-loading="subContractLoading">
        <el-descriptions border style="margin-top: 10px" :column="2" v-for="item,index in subContractObjList" :key="index">
          <el-descriptions-item label="分包合同名称">
            {{ item.subContractName }}
          </el-descriptions-item>
          <el-descriptions-item label="分包合同价款">
            {{ item.subAmount }}
          </el-descriptions-item>
          <el-descriptions-item label="合作单位">
            {{ item.partner ? item.partner.partnerName : '' }}
          </el-descriptions-item>
          <el-descriptions-item label="分包合同文件">
            <div v-if="item.contractDocument" class="upload-list">
              <el-link type="primary" @click="reviewWord(`${baseUrl}${'/profile/upload' + item.contractDocument}`)">
                {{ getFileName(item.contractDocument) }}
              </el-link>
              <el-link class="ml20" type="warning" :href="`${baseUrl}${'/profile/upload' + item.contractDocument}`"
                :underline="false" target="_blank">
                <span class="el-icon-download">下载文件</span>
              </el-link>
            </div>
            <div v-else>
              <el-tag type="info">暂无</el-tag>
            </div>
          </el-descriptions-item>
          <el-descriptions-item label="分包合同备注">
            {{ item.remark }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div v-else>
        <el-tag type="danger">暂无关联分包合同信息</el-tag>
      </div>
    </el-form-item>

  </div>
</template>

<script>
import { listProjectContract, addProjectContract } from "@/api/oa/contract/projectContract";
import { listProjectSubcontract, addProjectSubcontract, delProjectSubcontract } from '@/api/oa/contract/projectSubcontract'
import { getContract } from "@/api/oa/contract/contract";
import { getSubContract } from "@/api/oa/contract/subContract";
export default {
  props: {
    projectId: {
      type: String,
      default: ''
    }
  },
  watch: {
    projectId(newval) {
      this.init();
    }
  },
  mounted() {
  },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      contractObjList: [],
      subContractObjList: [],
      hasContract: true,
      hasSubContract: true,
      contractLoading: false,
      subContractLoading: false,
    }
  },
  methods: {
    init() {
      const projectId = this.projectId;
      this.contractLoading = true;
      this.subContractLoading = true;
      Promise.all([listProjectContract({ projectId }), listProjectSubcontract({ projectId })]).then(async response => {
        let [contractData = null, subContractData = null] = response
        // 主合同
        if (contractData.total >= 1) {
          let list = contractData.rows;
          this.contractObjList = []
          for (let l of list) {
            let res = await getContract(l.contractId)
            if (res.data) {
              this.contractObjList.push(res.data)
            }
          }
          this.hasContract = true;
        } else if (contractData.total == 0) {
          this.hasContract = false;
        }

        //分包合同
        if (subContractData.total >= 1) {
          let list = subContractData.rows;
          this.subContractObjList = []
          for (let l of list) {
            let res = await getSubContract(l.subContractId)
            if (res.data) {
              this.subContractObjList.push(res.data)
            }
          }
          this.hasSubContract = true;
        } else if (subContractData.total == 0) {
          this.hasSubContract = false;
        }
        this.contractLoading = false;
        this.subContractLoading = false;
      })
    }
  },
}
</script>

<style lang="scss" scoped>
::v-deep .el-descriptions-item__label.is-bordered-label {
  color: #5a5757;
  background: rgba($color: #a9adb3, $alpha: 0.1);
  width: 150px;
  min-width: 150px;
}

::v-deep .el-descriptions .is-bordered .el-descriptions-item__cell {
  border: 1px solid #cdd0d3;
}
</style>