<template>
  <div style="padding: 20px;padding-top: 0px;" 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"
      :columns="columns"
      :data-url="dataUrl"
      row-key="PROJECT_CODE"
      :actions="actions"
      :process-req="processReq"
      :defultpagination-pagesize="50"
    />
  </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-project-list-import'
const columns = [
  {
    title: '序号',

    customRender: (text, record, index) => {
      return { children: index + 1 }
    },
    width: '80px',
  },
  {
    title: '审计机构',
    dataIndex: 'UNIT_NAME',
  },
  {
    title: '项目名称',
    dataIndex: 'PROJECT_TITLE',
  },
  {
    title: '项目编号',
    dataIndex: 'PROJECT_CODE',
  },
  {
    title: '审计类型',
    dataIndex: 'AUDIT_TYPE',
  },
  {
    title: '被审计单位',
    dataIndex: 'AUDITED_UNIT_NAMES',
  },
  {
    title: '项目负责人',
    dataIndex: 'PROJECT_PRINCIPAL_NAME',
  },
  {
    title: '项目组长',
    dataIndex: 'GROUP_LEADER_NAME',
  },
  {
    title: '项目成员',
    dataIndex: 'USER_NAME',
  },
  {
    title: '项目来源',
    dataIndex: 'isPlanIn',
  },
  // {
  //   title: '审计方式',
  //   dataIndex: 'AUDIT_MODE',
  // },
  {
    title: '项目状态',
    dataIndex: 'ITEM_STATUS',
  },
]
export default {
  name: 'IamAuditProjectList',
  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 === 'projecttrends' ||
              this.$route.query.type === 'projectimplement'
            ) {
              // 项目趋势分析_项目信息列表穿透导出
              auditService
                .exportXmqsQSData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '项目信息列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else if (this.$route.query.type === 'projectlist') {
              // 审计项目统计_项目信息列表穿透导出
              auditService
                .exportSjxmTjCtData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '项目信息列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else if (this.$route.query.type === 'personnelstatistics') {
              // 审计项目统计_项目信息列表穿透导出
              auditService
                .exportOrgqsQSData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '项目信息列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else if (this.$route.query.type === 'personnelworkstatistics') {
              // 人员工作情况统计
              auditService
                .exportUserProjectPassList(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '项目信息列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            } else {
              // 年度计划完成情况_项目信息列表穿透导出
              auditService
                .exportNdXmctData(params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '项目信息列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            }
          },
        },
      ],
    }
  },
  computed: {
    dataUrl() {
      if (this.$route.query.type === 'projecttrends') {
        return 'api/xcoa-mobile/v1/iam-statistics/getProjectTrendPassList'
      } else if (this.$route.query.type === 'projectlist') {
        return 'api/xcoa-mobile/v1/iam-statistics/getAuditProjectPassList'
      } else if (this.$route.query.type === 'projectimplement') {
        return 'api/xcoa-mobile/v1/iam-statistics/getProjectTrendPassList'
      } else if (this.$route.query.type === 'personnelstatistics') {
        return 'api/xcoa-mobile/v1/iam-statistics/getOrgProjectPassList'
      } else if (this.$route.query.type === 'personnelworkstatistics') {
        return 'api/xcoa-mobile/v1/iam-statistics/getUserProjectPassList'
      } else {
        return 'api/xcoa-mobile/v1/iam-statistics/getProjectPassList'
      }
    },
  },
  methods: {
    processReq(req) {
      const parasm = JSON.parse(this.$route.query.params)
      req.data = {
        ...req.data,
        ...parasm,
      }
      return req
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.titlepoint {
  background: #1890ff;
  height: 27px;
  width: 8px;
  position: fixed;
  top: 12px;
  left: 20px;
  border-radius: 8px;
}
.toptitle {
  color: #404040;
  font-weight: bold;
  font-size: 22px;
  position: fixed;
  left: 40px;
  top: 9px;
}
:global(.reporttablecardxm) {
  :global(.ant-table-body) {
    height: calc(100vh - 140px);
    overflow: auto;
  }
}
</style>
