<!--
  @description: 申报材料-供货记录-查看
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020-5-23
-->
<template>
  <div>
    <el-button v-if="ChangeDetailBtn" type="primary" style="margin-bottom: 10px" @click="handleChangeDetail">
      查看变更内容
    </el-button>
    <div>
      <el-table
        ref="smallTable"
        :data="tableData"
      >
        <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" v-if="scope.row.partners === item.typecode" :key="index">
              {{ 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-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 { listSupplyRecordPages, listSupplyRecordAuditPages } from '@/api/supplier/supplierSupplyRecord'
/* 公用方法*/
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/supplYrecord/supplYrecordDifference-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, // 千分位
      tableData: [], // 列表
      ChangeDetailBtn: false, // 查看变更内容
      bizType: this.$route.params.bizType,
      listFinancialSituationPagesDto: {
        departId: '',
        tabType: '03' // 切换内容——企业资质
      },
      consignContractSelectDialog: {
        dialog: false // 变更查看
      }
    }
  },
  created() {
    this.listFinancialSituationPagesDto.departId = this.$route.params.supplierId || this.judgePageData.departId// 供应商id
    // this.departData.detailType = this.$route.meta.type === 'audit' ? '' : 'dialog' // 判断是否为审核
    this.ChangeDetailBtn = this.bizType === '02' ? [] : false // 判断是否是变更审核
    this.loadData() // 获取数据
    this.getSupplyRecordDictionaries() // 获取字典信息
  },
  methods: {
    // 获取数据
    loadData() {
    // 判断是否为初审审核页面
      if (this.$route.meta.type === 'declarationFirst' || this.$route.meta.type === 'declarationChange' || this.judgePageData.detailType === 'dialog') { // declarationFirst 编辑申报材料查看 declarationChange 申报材料变更时 audit 初审审核时
        this.listSupplyRecordPages()// 非审核时-查询企业信息
      } else if (this.$route.meta.type === 'audit') { // 审核时
        this.listSupplyRecordAuditPages()// 审核时-查询企业信息
      }
    },
    // 非审核时-查询企供货记录
    listSupplyRecordPages() {
      const params = this.getQueryParams()// 查询条件
      listSupplyRecordPages(params).then(response => {
        this.assemblyData(response)// 组装数据
      }).catch(() => {
      })
    },
    // 审核时-查询供货记录
    listSupplyRecordAuditPages() {
      this.loading = true
      const params = this.getQueryParams()// 查询条件
      listSupplyRecordAuditPages(params).then(response => {
        this.assemblyData(response)// 组装数据
      }).catch(() => {
      })
    },
    // 组装数据
    assemblyData(response) {
      this.tableData = response.data.records
      this.paginationData.total = response.data.total
      this.tableData.forEach(item => {
        item.contractDate = this.$Moment(item.contractDate).format(this.momentDate)// 签订日期
        // 合同扫描件
        item.supplyRecordFile = {
          ...this.supplyRecordFile,
          bizId: item.id
        }
      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.listFinancialSituationPagesDto)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 查看变更记录弹框
    handleChangeDetail() {
      this.consignContractSelectDialog.dialog = true
    }
  }
}
</script>

<style lang="less" scoped>

</style>
