<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"
      :columns="columns"
      :data-url="dataUrl"
      row-key="PROJECT_CODE"
      :actions="actions"
      :process-req="processReq"
      :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-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: 'GROUP_LEADER_NAME',
  },
  {
    title: '项目组成员',
    dataIndex: 'USER_NAME',
  },
  {
    title: '审计方式',
    dataIndex: 'AUDIT_MODE',
  },
  {
    title: '项目状态',
    dataIndex: 'ITEM_STATUS',
  },
]
export default {
  name: 'IamAuditDscProjectList',
  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
                .exportProjectList(this.params)
                .then((data) => {
                  const url = URL.createObjectURL(data)
                  download(url, '项目信息列表导出.xls')
                })
                .catch(() => {
                  Message.error('导出失败')
                })
            }
          },
        },
      ],
    }
  },
  computed: {
    dataUrl() {
      return 'api/xcoa-mobile/v1/iam-statistics/getProjectTrendPassList'
    },
  },
  methods: {
    processReq(req) {
      const params = JSON.parse(this.$route.query.params)
      const newparams = {}
      // 没有参数就不传
      if (params.unitNames !== "'null'") {
        newparams.unitNames = params.unitNames
      }
      if (params.planYear !== 'null') {
        newparams.planYear = params.planYear
      }
      if (params.status === 'start') {
        newparams.itemStatus = '02,03,04,05,07'
      }
      if (params.unitIds !== 'null') {
        newparams.unitIds = params.unitIds
      }
      req.data = {
        ...req.data,
        ...newparams,
      }
      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>
