<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]">审计发现列表</span>
    </div>
    <sd-data-table
      ref="dataTable"
      :projectlist="true"
      :columns="columns"
      :data-url="dataUrl"
      row-key="FIND_TITLE"
      :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/iam-audit-dsc-find-list-import'
const columns = [
  {
    title: '序号',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '审计机构',
    dataIndex: 'UNIT_NAME',
    width: '200px',
  },
  {
    title: '项目名称',
    dataIndex: 'PROJECT_TITLE',
    width: '350px',
  },
  {
    title: '项目编号',
    dataIndex: 'PROJECT_CODE',
    width: '200px',
  },
  {
    title: '项目组长',
    dataIndex: 'GROUP_LEADER_NAME',
    width: '200px',
  },
  {
    title: '被审计单位',
    dataIndex: 'AUDITED_UNIT_NAME',
    width: '150px',
  },
  {
    title: '审计发现提出人',
    dataIndex: 'CREATOR_NAME',
    width: '180px',
  },
  {
    title: '审计发现标题',
    dataIndex: 'FIND_TITLE',
    width: '150px',
  },
  {
    title: '审计发现类别',
    dataIndex: 'FIND_TYPE',
    width: '150px',
  },
  {
    title: '审计发现描述',
    dataIndex: 'SUGGESTION',
    width: '150px',
  },
  {
    title: '审计建议类型',
    dataIndex: 'SUGGESTION_TYPE',
    width: '150px',
  },
  {
    title: '问题类型',
    dataIndex: 'PROBLEM_TYPE',
    width: '100px',
  },
  {
    title: '问题涉及金额（万元）',
    dataIndex: 'AUDIT_ASSETS',
    width: '200px',
  },
  {
    title: '风险评级',
    dataIndex: 'RISK_LEVEL',
    width: '100px',
  },
  {
    title: '问题所属业务域',
    dataIndex: 'BUSINESS_PROCESS',
    width: '150px',
  },
  {
    title: '是否问责',
    dataIndex: 'WHETHER_ORDER_DUTY',
    width: '100px',
  },
]
export default {
  name: 'IamAuditDscFindList',
  metaInfo: {
    title: '审计发现统计透视图',
  },
  components,
  data() {
    return {
      params: null,
      columns,
      data: [],
      actions: [
        {
          label: '导出',
          id: 'export',
          permission: null,
          type: TableActionTypes.primary,
          callback: () => {
            if (this.$route.query.type === 'projectlist') {
              this.params.maxResults = '-1'
              // 审计发现统计_钻取审计发现列表导出
              auditService
                .exportFindList(this.params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '审计发现列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            }
          },
        },
      ],
    }
  },
  computed: {
    dataUrl() {
      return 'api/xcoa-mobile/v1/iam-statistics/getAuditFindList'
    },
  },
  methods: {
    isJson(str) {
      if (typeof str === 'string') {
        try {
          const obj = JSON.parse(str)
          if (typeof obj === 'object' && obj) {
            return true
          } else {
            return false
          }
        } catch (e) {
          return false
        }
      }
    },
    processRes(res) {
      if (res.data.length > 0) {
        res.data.forEach((item) => {
          if (this.isJson(item.FIND_TYPE)) {
            item.FIND_TYPE = JSON.parse(item.FIND_TYPE).text
          }
        })
      }
      return res
    },
    processReq(req) {
      const params = JSON.parse(this.$route.query.params)
      const newparams = {
        dimension: params.dimension,
      }
      // 没有参数就不传
      if (params.unitNames !== "'null'") {
        newparams.unitNames = params.unitNames
      }
      if (params.dateStart !== 'null') {
        newparams.dateStart = params.dateStart
      }
      if (params.unitIds !== 'null') {
        newparams.unitIds = params.unitIds
      }
      req.data = {
        ...req.data,
        ...newparams,
      }
      if (req.data.pageIndex === undefined) {
        req.data.pageIndex = req.data.startPosition
      }

      if (req.data.pageSize === undefined) {
        req.data.pageSize = 10
      }
      this.params = req.data
      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: 200px;
  font-size: 22px;
  font-weight: bold;
  color: #404040;
}
</style>
