<template>
  <div style="padding: 20px; padding-top: 0" class="reporttablecardxm">
    <div
      style="position: absolute; padding-top: 10px; line-height: 32px"
      class="header_sd-header_common"
    >
      <div :class="$style.titlepoint"></div>
      <span :class="['toptitle', $style.toptitle]">{{ this.unitName }}</span>
    </div>
    <sd-data-table
      ref="dataTable"
      :columns="columns"
      :projectlist="true"
      :data-url="dataUrl"
      :actions="actions"
      :process-req="processReq"
      :process-res="processRes"
      :defultpagination-pagesize="50"
    />
  </div>
</template>

<script>
import { Message } from 'ant-design-vue'
import TableActionTypes from '@/common/services/table-action-types'
import download from '@/common/services/download'
import auditService from './iam-audit-dsc-service'
import components from './_import-components/spic-audit-dsc-three-coverage-list-import'

export default {
  name: 'SpicAuditDscThreeCoverageList',
  metaInfo: {
    title: '审计覆盖情况',
  },
  components,
  data() {
    return {
      params: null,
      columns: [],
      year: '',
      data: [],
      unitName: '',
      actions: [
        {
          label: '导出',
          id: 'export',
          permission: null,
          type: TableActionTypes.primary,
          callback: () => {
            const params = JSON.parse(this.$route.query.params)
            if (this.$route.query.type === 'fourYearCoverage') {
              auditService
                .exportUnitList(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '审计覆盖情况列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            }
          },
        },
      ],
    }
  },
  computed: {
    dataUrl() {
      return 'api/xcoa-mobile/v1/spicDecisionSupportCenter/getAuditedUnitList'
    },
  },
  mounted() {
    const params = this.$route.query.params
    setTimeout(() => {
      const str = JSON.parse(params).unitNames
      this.unitName = '审计覆盖情况：' + str.substring(1, str.length - 1)
    }, 1000)
    const year = this.$route.query.year
    this.columns.push({
      title: '序号',
      width: '80px',
    })
    this.columns.push({ title: '单位名称', dataIndex: '' })
    this.columns.push({ title: year - 2, dataIndex: '' })
    this.columns.push({ title: year - 1, dataIndex: '' })
    this.columns.push({ title: year, dataIndex: '' })
  },
  methods: {
    processRes(res) {
      return res
    },
    processReq(req) {
      const params = JSON.parse(this.$route.query.params)
      req.data = {
        ...req.data,
        ...params,
      }
      if (req.data.pageIndex === undefined) {
        req.data.pageIndex = req.data.startPosition
      }

      if (req.data.pageSize === undefined) {
        req.data.pageSize = 10
      }
      return req
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.titlepoint {
  position: absolute;
  top: 12px;
  left: 20px;
  width: 8px;
  height: 27px;
  background: #1890ff;
  border-radius: 8px;
}
.toptitle {
  position: absolute;
  top: 9px;
  left: 40px;
  width: 800px;
  font-size: 22px;
  font-weight: bold;
  color: #404040;
}
</style>
