<!--
  @description: 入库审核-查看-财务状况
  @Modifier: qk
  @routerPath:supplierDeclaration/supplier/financialSituation
  @date: 2020-2-20 16:32:31
-->
<template>
  <div>
    <el-button v-if="ChangeDetailBtn" type="primary" style="margin-bottom: 10px" @click="handleChangeDetail">
      查看变更内容
    </el-button>
    <div>
      <el-table
        ref="smallTable"
        :data="tableData"
        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" v-if="scope.row.auditStatus === item.typecode" :key="index">
              {{ item.typename }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
    <!--审核信息-->
    <inforaMtionAuditDetail v-if="!judgePageData.detailType" />
    <!--查看变更内容弹框-->
    <consignContractSelectDialog :dialog-data="consignContractSelectDialog" />
  </div>
</template>

<script>
/* 接口*/
import { listFinancialSituationPages, listFinancialSituationAuditPages } from '@/api/supplier/supplierFinancialSituation'// 暂存 ，获取,删除
/* 公用方法*/
import { moneyFormat, filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
import { declareHegSupperGroupMixin } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperGroupMixin'// 供应商-字典
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin'
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile'// 附件
import pagination from '@comp/common/pagination/pagination'// 分页
import consignContractSelectDialog from '@/views/supplier/editorDeclaration/financialSituation/financialSituationDifference-dialog' // 查看变更内容-弹窗
import inforaMtionAuditDetail from '@/views/supplier/editorDeclaration/inforaMtionAudit/inforaMtionAudit-detail'// 审报材料-审核信息
export default {
  name: 'PreviewProjectInfoDetail',
  components: {
    downloadFile, // 附件
    pagination, // 分页
    consignContractSelectDialog, // 查看变更内容-弹框
    inforaMtionAuditDetail // 审核信息
  },
  mixins: [ListMixin, declareHegSupperMixins, declareHegSupperGroupMixin, supplierGroupMixin],
  props: {
    // 查看状态
    judgePageData: {
      type: Object,
      default: function() {
        return {
          detailType: 'dialog', // 查看形式 dialog 弹框
          departId: ''// 供应商主键id
        }
      }
    }
  },
  data() {
    return {
      moneyFormat: moneyFormat, // 转千分位
      // searchForm: {
      //   departId: ''// 机构Id
      // },
      loading: true, // 列表loding
      tableData: [], // 列表信息
      bizType: this.$route.params.bizType,
      listSupplyRecordPagesDto: {
        departId: '', // 机构Id
        tabType: '04' // 切换内容——财务状况
      },
      consignContractSelectDialog: {
        dialog: false // 变更查看
      }
    }
  },
  created() {
    this.ChangeDetailBtn = this.bizType === '02' ? [] : false // 判断是否是变更审核
    // this.departData.detailType = this.$route.meta.type === 'audit' ? '' : 'dialog' // 判断是否为审核
    this.listSupplyRecordPagesDto.departId = this.$route.params.supplierId || this.judgePageData.departId// 供应商id
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
    // 判断是否为初审审核页面
      if (this.$route.meta.type === 'declarationFirst' || this.$route.meta.type === 'declarationChange' || this.judgePageData.detailType === 'dialog') {
        // declarationFirst 编辑申报材料查看 declarationChange 申报材料变更时 audit 初审审核时
        this.listFinancialSituationPages()// 非审核时-查询财务状况
      } else if (this.$route.meta.type === 'audit') { // 审核时
        this.listFinancialSituationAuditPages()// 审核时-查询财务状况
      }
    },
    // 非审核时-查询财务状况
    listFinancialSituationPages() {
      const params = this.getQueryParams()// 查询条件
      listFinancialSituationPages(params).then(response => {
        this.assemblyData(response)// 组装数据
      }).catch(() => {
      })
    },
    // 审核时-查询财务状况
    listFinancialSituationAuditPages() {
      const params = this.getQueryParams()// 查询条件
      listFinancialSituationAuditPages(params).then(response => {
        this.assemblyData(response)// 组装数据
      }).catch(() => {
      })
    },
    // 组装数据
    assemblyData(response) {
      this.tableData = response.data.records
      this.paginationData.total = response.data.total
      this.tableData.forEach((item, index) => {
        // 证书扫描
        item.financialAuditingReportData = {
          ...this.financialAuditingReportData,
          bizId: item.id
        }
      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.listSupplyRecordPagesDto)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 查看变更记录弹框
    handleChangeDetail() {
      this.consignContractSelectDialog.dialog = true
    }
  }
}
</script>

<style lang="less" scoped>

</style>
