<!--
  @description: 供应商管理-供应商申报入库工作流处理查看页
  @Modifier:lxl
  @routerPath:supplierWork/supplierWork-detail
  @date: 2020/12/22
-->
<template>
  <div class="p0-16">
    <p class="page-title">
      1.基本信息
    </p>
    <table class="tableData">
      <tr>
        <td>资审来源</td>
        <td colspan="3">
          申报入库
        </td>
      </tr>
      <tr>
        <td>单位注册基地</td>
        <td>
          <span v-for="item in incorporationGroup" :key="item.typecode">
            {{ decFormData.incorporation === item.typecode?item.typename:'' }}
          </span>,
          <span v-for="item in incorporationGroups" :key="item.typecode">
            {{ decFormData.area === item.typecode?item.typename:'' }}
          </span>
        </td>
        <td>机构类型</td>
        <td>
          <span v-for="(item) in documentMethodList" :key="item.typecode">
            {{ decFormData.unittype === item.typecode ? item.typename : '' }}
          </span>
        </td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>供应商名称</td>
        <td>
          {{ decFormData.departName }}
        </td>
        <td>{{ businesslicenceTitle }}</td>
        <td>{{ decFormData.businesslicence }}</td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>供应商分类</td>
        <td> {{ filterDictText(supplierTypeCodeGroup,decFormData.supplierType) }}</td>
        <td>企业性质</td>
        <td>
          <span v-for="item in supplierEntPrptGroup" :key="item.typecode">
            {{ decFormData.entPrpt === item.typecode?item.typename:'' }}
          </span>
        </td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>单位成立日期</td>
        <td>{{ decFormData.foundingTime }}</td>
        <td>法人/负责人</td>
        <td>{{ decFormData.corporation }}</td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>法人/负责人身份证号或护照号</td>
        <td>{{ decFormData.corporateid }}</td>
        <td>法人/负责人身份证或护照扫描件</td>
        <td>
          <downloadFile v-if="principalData.bizId" :data="principalData" />
        </td>
      </tr>
      <tr>
        <td>单位地址</td>
        <td colspan="3">
          {{ decFormData.areaValue }}{{ decFormData.address }}
        </td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>供货范围</td>
        <td>
          {{ decFormData.supplyScope }}
        </td>
        <td>公司简介</td>
        <td colspan="3">
          {{ decFormData.descr }}
        </td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>营业执照有效期</td>
        <td>
          {{ decFormData.effectiveEndDate }}
        </td>
        <td>营业执照扫描件</td>
        <td><downloadFile v-if="businessLicenseData.bizId" :data="businessLicenseData" /></td>
      </tr>
      <tr>
        <td>是否新供应商</td>
        <td>{{ formData.isNewSupplier }}</td>
        <td>调查方式</td>
        <td>{{ filterDictText(nvestigationMethodList,formData.nvestigationMethod) }}</td>
      </tr>
      <tr>
        <td>调查报告</td>
        <td><downloadFile v-if="siteAssessmenteportData.bizId" :data="siteAssessmenteportData" /></td>
        <td>推荐理由</td>
        <td>{{ formData.reason }}</td>
      </tr>
    </table>
    <p class="page-title">
      2.基本户信息
    </p>
    <table class="tableData">
      <tr>
        <td>开户银行</td>
        <td>{{ decFormData.bankname }}</td>
        <td>账号</td>
        <td>{{ decFormData.bankaccount }}</td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>开户行行号</td>
        <td>{{ decFormData.accountNum }}</td>
        <td>联行号</td>
        <td>{{ decFormData.correspondentNum }}</td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>开户行地址</td>
        <td>{{ decFormData.accountCity }}</td>
        <td>电话</td>
        <td>{{ decFormData.accountPhone }}</td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>注册资本(万元)</td>
        <td>
          {{
            decFormData.regcapital
              ? moneyFormat(Number(decFormData.regcapital))
              : decFormData.regcapital
          }}
        </td>
        <td>币种</td>
        <td>
          <span v-for="(item,indexs) in currencies" :key="indexs">
            {{ decFormData.currencies === item.typecode?item.typename:'' }}
          </span>
        </td>
      </tr>
      <!-- <tr /> -->
      <tr>
        <td>实缴资本(万元)</td>
        <td>
          {{ decFormData.actualCapital }}
        </td>
        <td>开户许可证</td>
        <td>
          <downloadFile
            v-if="accountLicenceData.bizId"
            ref="downloadFile"
            :data="accountLicenceData"
          />
        </td>
      </tr>
    </table>
    <p class="page-title">
      3.业务经办人信息
    </p>
    <table v-for="(item,index) in listArray" :key="index" class="tableData">
      <tr>
        <td :style="{'border-top':index>0?'0px':''}" colspan="4" style="text-align: left;font-weight: bold;">
          业务经办人{{ index+1 }}
        </td>
      </tr>
      <tr>
        <td>姓名</td>
        <td>{{ item.linkname }}</td>
        <td>身份证号或护照号</td>
        <td>{{ item.linkerID }}</td>
      </tr>
      <tr>
        <td>手机</td>
        <td>{{ item.linktel }}</td>
        <td>邮箱</td>
        <td>{{ item.email }}</td>
      </tr>
      <tr>
        <td>身份证或护照扫描件</td>
        <td><downloadFile v-if="item.identityCardData.bizId" :data="item.identityCardData" /></td>
        <td>授权书扫描件</td>
        <td><downloadFile v-if="item.letterAttorneyData.bizId" :data="item.letterAttorneyData" /></td>
      </tr>
    </table>
    <p class="page-title">
      4.企业资质信息
    </p>
    <template>
      <el-table
        ref="smallTable"
        :data="etpTableData"
      >
        <!-- 序号 -->
        <el-table-column
          :label="language.Serialnumber"
          type="index"
          width="60px"
          align="center"
        />
        <!-- 证书名称 -->
        <el-table-column
          :label="language.Certificatename"
          prop="certificateName"
          header-align="center"
          min-width="160"
        />
        <!-- 证书编号 -->
        <el-table-column
          :label="language.Certificatenumber"
          header-align="center"
          prop="certificateNo"
          min-width="120"
        />
        <!-- 发证单位 -->
        <el-table-column
          :label="language.Certificationunit"
          header-align="center"
          prop="issuingUnit"
          min-width="200"
        />
        <!-- 发证日期 -->
        <el-table-column
          :label="language.Dateofissue"
          align="center"
          prop="issuingTime"
          min-width="110"
        />
        <!-- 有效期至 -->
        <el-table-column
          :label="language.Validuntil"
          prop="validityEndTime"
          align="center"
          min-width="110"
        />
        <!-- 证书扫描 -->
        <el-table-column
          :label="language.Certificatescanningcopy"
          header-align="center"
          min-width="160"
        >
          <template slot-scope="scope">
            <downloadFile :data="scope.row.certificateScanData" />
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="审核状态"
          prop="auditStatus"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span v-for="(item,index) in auditStatusList" :key="index">
              {{ scope.row.auditStatus === item.typecode?item.typename:'' }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="etpPagData" @change="etpLoadData" />
    </template>
    <p class="page-title">
      4.供货记录信息
    </p>
    <template>
      <el-table
        ref="smallTable"
        :data="recTableData"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          prop="purchasingUnit"
          header-align="center"
          label="采购单位"
          min-width="200"
        />
        <el-table-column
          align="center"
          prop="partners"
          label="合同合作方"
          width="110"
        >
          <template slot-scope="scope">
            <span v-for="(item,index) in supplierPartnersList" :key="index">
              {{ scope.row.partners === item.typecode?item.typename:'' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="contractDate"
          label="签定日期"
          width="110"
        />
        <el-table-column
          header-align="center"
          label="合同金额(万元)"
          prop="contractAmount"
          align="right"
          min-width="110"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.contractAmount?moneyFormat(Number(scope.row.contractAmount)):scope.row.contractAmount }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="买方业务代表"
          prop="buyerRepresentative"
          header-align="center"
          width="110"
        />
        <el-table-column
          label="买方业务代表联系电话"
          prop="buyerLinker"
          align="center"
          width="150"
        />
        <el-table-column
          label="合同扫描"
          prop="contractAttr"
          header-align="center"
          min-width="160"
        >
          <template slot-scope="scope">
            <downloadFile :data="scope.row.supplyRecordFile" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="recPagData" @change="recLoadData" />
    </template>
    <p class="page-title">
      5.财务状况信息
    </p>
    <template>
      <el-table
        ref="smallTable"
        :data="finTableData"
        width="100%"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          prop="year"
          align="center"
          label="年度"
          width="80"
        />
        <el-table-column
          header-align="center"
          align="right"
          prop="totalAssets"
          label="资产总计(万元)"
          min-width="110"
        >
          <template slot-scope="scope">
            <span>{{ moneyFormat(Number(scope.row.totalAssets)) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="right"
          prop="totalLiabilities"
          label="负债总计(万元)"
          min-width="110"
        >
          <template slot-scope="scope">
            <span>{{ moneyFormat(Number(scope.row.totalLiabilities)) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="right"
          label="利润总额(万元)"
          prop="totalProfit"
          min-width="110"
        >
          <template slot-scope="scope">
            <span>{{ moneyFormat(Number(scope.row.totalProfit)) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="净利润(万元)"
          prop="netProfit"
          header-align="center"
          align="right"
          min-width="100"
        >
          <template slot-scope="scope">
            <span>{{ moneyFormat(Number(scope.row.netProfit)) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="资产负债率(%)"
          prop="assetLiabilityRatio"
          header-align="center"
          align="right"
          min-width="110"
        />
        <el-table-column
          label="流动比率(%)"
          prop="flowRate"
          header-align="center"
          align="right"
          min-width="100"
        />
        <el-table-column
          header-align="center"
          label="财务审计报告扫描件"
          prop="auditReportAttr"
          align="left"
          min-width="160"
        >
          <template slot-scope="scope">
            <downloadFile :data="scope.row.financialAuditingReportData" />
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="审核状态"
          prop="auditStatus"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span v-for="(item,index) in auditStatusList" :key="index">
              {{ scope.row.auditStatus === item.typecode?item.typename:'' }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="finPagData" @change="finLoadData" />
    </template>
  </div>
</template>
<script>
/* api*/
import { queryDeclarationInfoByDeclarationId } from '@/api/supplier/supplierBaseInfo.js'// 列表
import { getUpdateDepartInfo } from '@/api/supplier/supplierBaseInfo'// 获取编辑申报材料查询
import { getUpdateLinker } from '@/api/supplier/supplierBaseInfo'// 业务经办人
import { listCertificatePages } from '@/api/supplier/supplierCertificate'// 企业资质
import { listSupplyRecordPages } from '@/api/supplier/supplierSupplyRecord' // 供货记录
import { listFinancialSituationPages } from '@/api/supplier/supplierFinancialSituation'// 财务状况

/* 公用方法 */
import { moneyFormat, filterDictText } from '@assets/js/utils'
/* 混合开发*/
import { declareHegSupperGroupMixin } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperGroupMixin'// 供应商-字典
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin'
/* 公用组件*/
import downloadFile from '@comp/common/updownload/downloadFile'// 附件
import pagination from '@comp/common/pagination/pagination'// 分页
// vuex
import { mapGetters } from 'vuex'

export default {
  name: 'SupplierWorkDetail',
  components: {
    downloadFile, // 附件
    pagination // 分页
  },
  mixins: [declareHegSupperGroupMixin, declareHegSupperMixins, supplierGroupMixin],
  data() {
    return {
      decFormData: {}, // 供应商申报基本信息
      listArray: [], // 业务经办人信息
      formData: {}, // 基本信息
      // 企业资质分页
      etpPagData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      etpTableData: [], // 企业资质数据
      // 供货记录分页
      recPagData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      recTableData: [], // 供货记录信息数据
      // 财务状况分页
      finPagData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      finTableData: [] // 财务状况数据
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  created() {
    this.initKey() // 获取供应商字典
    this.getData()// 获取基本信息
  },
  methods: {
    moneyFormat, // 金额
    filterDictText, // 字典
    async  getData() {
      new Promise((resolve) => {
        const params = {
          declarationId: this.$route.query.bizId
        }
        queryDeclarationInfoByDeclarationId(params).then((res) => {
          this.formData = res.data
          resolve(res.data)
        })
      }).then((res) => {
        // 基本信息参数
        const params = {
          departId: res.supplierId,
          declarationId: res.id, // 申报id
          isViewPage: '01'// 判断是否为变更数据
        }
        // 企业资质参数
        const paramsData = {
          departId: res.supplierId,
          tabType: '02',
          pageNo: this.etpPagData.pageNo,
          pageSize: this.etpPagData.pageSize
        }
        // 供货记录参数
        const recParams = {
          departId: res.supplierId,
          tabType: '03',
          pageNo: this.recPagData.pageNo,
          pageSize: this.recPagData.pageSize
        }
        // 财务状况参数
        const finParams = {
          departId: res.supplierId,
          tabType: '04',
          pageNo: this.finPagData.pageNo,
          pageSize: this.finPagData.pageSize
        }
        // 申报材料查询
        getUpdateDepartInfo(params).then((response) => {
          const { info, finance, showStatus, declarationAuditStatus } = response.data
          this.decFormData = {
            ...info,
            ...finance,
            ...showStatus,
            ...declarationAuditStatus
          }
          console.log(response.data)
          if (this.decFormData.foundingTime) this.decFormData.foundingTime = this.$Moment(this.decFormData.foundingTime).format(this.momentDate)// 单位成立日期
          if (this.decFormData.longTerm === '01') { // 有效期至为长期
            this.decFormData.effectiveEndDate = '长期'
          } else { // 有效期至非长期
            if (this.decFormData.effectiveEndDate) this.decFormData.effectiveEndDate = this.$Moment(this.decFormData.effectiveEndDate).format(this.momentDate)// 有效期至
          }
          // 附件主键Id
          this.businessLicenseData.bizId = this.decFormData.id // 营业执照扫描件
          this.principalData.bizId = this.decFormData.id // 法人/负责人身份证号或护照号
          this.accountLicenceData.bizId = this.decFormData.id // 开户许可证
          this.siteAssessmenteportData.bizId = res.id
        })
        // 业务经办人
        getUpdateLinker(params).then((response) => {
          this.listArray = response.data.linkerlist
        })
        // 企业资质
        this.etpLoadData(paramsData)
        // 供货记录
        this.recLoadData(recParams)
        // 财务状况
        this.finLoadData(finParams)
      })
    },
    // 企业资质
    etpLoadData(params) {
      listCertificatePages(params).then((response) => {
        this.assemblyData(response)// 组装数据
      })
    },
    // 组装数据
    assemblyData(response) {
      this.etpPagData.total = response.data.total
      const tableData = response.data.records
      tableData.forEach((item) => {
        item.issuingTime = this.$Moment(item.issuingTime).format(this.momentDate)// 发证日期
        if (item.longTerm === '01') { // 有效期至为长期
          item.validityEndTime = '长期'
        } else { // 有效期至非长期
          if (item.validityEndTime) item.validityEndTime = this.$Moment(item.validityEndTime).format(this.momentDate)// 有效期至
        }
        // 证书扫描
        item.certificateScanData = {
          ...this.certificateScanData,
          bizId: item.id
        }
      })
      this.etpTableData = tableData
    },
    // 供应商记录
    recLoadData(params) {
      listSupplyRecordPages(params).then((response) => {
        this.recTableData = response.data.records
        this.recPagData.total = response.data.total
        this.recTableData.forEach(item => {
          item.contractDate = this.$Moment(item.contractDate).format(this.momentDate)// 签订日期
          // 合同扫描件
          item.supplyRecordFile = {
            ...this.supplyRecordFile,
            bizId: item.id
          }
        })
      })
    },
    // 财务状况
    finLoadData(params) {
      listFinancialSituationPages(params).then((response) => {
        this.finTableData = response.data.records
        this.finPagData.total = response.data.total
        this.finTableData.forEach((item, index) => {
        // 证书扫描
          item.financialAuditingReportData = {
            ...this.financialAuditingReportData,
            bizId: item.id
          }
        })
      })
    }
  }
}
</script>
