<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"
    >
    </sd-data-table>
  </div>
</template>

<script>
import download from '@/common/services/download'
import { Message } from 'ant-design-vue'
import TableActionTypes from '@/common/services/table-action-types'
import auditService from './iam-audit-report-service'
import components from './_import-components/iam-audit-find-list-import'
const columns = [
  {
    title: '序号',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '审计机构',
    dataIndex: 'UNIT_NAME',
    width: '150px',
  },
  {
    title: '项目名称',
    dataIndex: 'PROJECT_TITLE',
    width: '150px',
  },
  {
    title: '项目编号',
    dataIndex: 'PROJECT_CODE',
    width: '150px',
  },
  {
    title: '项目组长',
    dataIndex: 'GROUP_LEADER_NAME',
    width: '150px',
  },
  {
    title: '被审计单位',
    dataIndex: 'AUDITED_UNIT_NAME',
    width: '150px',
  },
  {
    title: '审计发现提出人',
    dataIndex: 'CREATOR_NAME',
    width: '180px',
  },
  {
    title: '问题名称（定性描述）',
    dataIndex: 'FIND_TITLE',
    width: '150px',
  },
  {
    title: '审计问题描述',
    dataIndex: 'FIND_DESC',
    width: '150px',
  },
  {
    title: '是否属于审计意见书问题',
    dataIndex: 'GIVE_OPINION',
    width: '180px',
  },
  {
    title: '问题分类',
    dataIndex: 'PROBLEM_CATEGORY_FUNCTION',
    width: '150px',
  },
  {
    title: '是否属于零容忍事项',
    dataIndex: 'ZERO_TOLERATE',
    width: '165px',
  },
  {
    title: '是否移送纪检监察线索（单移送）',
    dataIndex: 'TRANSFER_CLUE_SINGLE',
    width: '180px',
  },
  {
    title: '是否移送纪检监察线索（双移送）',
    dataIndex: 'TRANSFER_CLUE_DOUBLE',
    width: '180px',
  },
  {
    title: '审计处理意见',
    dataIndex: 'HANDLE_SUGGESTION',
    width: '200px',
  },
  {
    title: '非金额类问题类别',
    dataIndex: 'NOT_AMOUNT_TYPE',
    width: '165px',
  },
  {
    title: '问题涉及金额（万元）',
    dataIndex: 'AUDIT_ASSETS',
    width: '200px',
  },
]
export default {
  name: 'IamAuditFindList',
  metaInfo: {
    title: '审计发现统计透视图',
  },
  components,
  data() {
    return {
      columns,
      data: [],
      actions: [
        {
          label: '导出',
          id: 'export',
          permission: null,
          type: TableActionTypes.primary,
          callback: () => {
            const params = JSON.parse(this.$route.query.params)
            if (this.$route.query.type === 'problemtrends') {
              // 问题趋势分析_钻取审计发现列表导出
              auditService
                .exportWTQSCTData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '审计发现列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else if (this.$route.query.type === 'projectlist') {
              // 审计发现统计_钻取审计发现列表导出
              auditService
                .exporSJFXTJCTData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '审计发现列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else if (this.$route.query.type === 'personnelstatistics') {
              // 审计发现统计_钻取审计发现列表导出
              auditService
                .exporORGCTData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '审计发现列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else if (this.$route.query.type === 'personnelworkstatistics') {
              // 人员情况统计_钻取审计发现列表导出
              auditService
                .exporRYQKTJData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '审计问题列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else {
              // 问题涉及金额_钻取审计发现列表导出
              auditService
                .exporWTSJCTData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '审计发现列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            }
          },
        },
      ],
    }
  },
  computed: {
    dataUrl() {
      if (this.$route.query.type === 'problemtrends') {
        return 'api/xcoa-mobile/v1/iam-statistics/getFindTrendPassList'
      } else if (this.$route.query.type === 'projectlist') {
        return 'api/xcoa-mobile/v1/iam-statistics/getAuditFindList'
      } else if (this.$route.query.type === 'personnelstatistics') {
        return 'api/xcoa-mobile/v1/iam-statistics/getOrgFindPassList'
      } else if (this.$route.query.type === 'personnelworkstatistics') {
        return 'api/xcoa-mobile/v1/iam-statistics/getUserFindPassList'
      } else {
        return 'api/xcoa-mobile/v1/iam-statistics/getAuditFindForMoneyList'
      }
    },
  },
  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 parasm = JSON.parse(this.$route.query.params)
      req.data = {
        ...req.data,
        ...parasm,
      }
      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: fixed;
  top: 12px;
  left: 20px;
  width: 8px;
  height: 27px;
  background: #1890ff;
  border-radius: 8px;
}
.toptitle {
  position: fixed;
  top: 9px;
  left: 40px;
  font-size: 22px;
  font-weight: bold;
  color: #404040;
}
:global(.reporttablecardxm) {
  :global(.ant-table-body) {
    height: calc(100vh - 140px);
    overflow: auto;
  }
}
</style>
