<template>
  <div>
    <sd-oa-table
      ref="dossierDataTable"
      form-id="iamDossierData"
      page-id="audit/archives/iamDossierData"
      :columns="columns"
      :actions="actions"
      show-selection
      :search-fields="[]"
    >
      <div slot="islink" slot-scope="text, record">
        <a :title="text" @click="rowClick(record)">{{ text }}</a>
      </div>
    </sd-oa-table>
  </div>
</template>

<script>
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import TableColumnTypes from '@/common/services/table-column-types'
import TableActionTypes from '@/common/services/table-action-types'
import components from './_import-components/audit-dossier-list-import'

export default {
  name: 'AuditDossierList',
  metaInfo: {
    title: '案卷资料',
  },
  components,
  data() {
    return {
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNumber',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: '文件名称',
          dataIndex: 'docTitle',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '编制人员',
          dataIndex: 'creatorName',
        },
        {
          title: '编制日期',
          dataIndex: 'creationTime',
          defaultSortOrder: 'descend', // 没有点击任何排序列时，默认的排序列
          sdRender: TableColumnTypes.dateTime,
        },
      ],
      actions: [
        {
          label: '新建',
          id: 'new',
          permission: 'create',
          type: TableActionTypes.primary,
          callback: () => {
            const url = '/audit-dossier-form' // 新页面要打开的路由地址
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                // 这里写或者调刷新的方法
                this.refresh()
              }
            })
          },
        },
        {
          label: '删除',
          id: 'delete',
          type: TableActionTypes.oa.delete, // 删除按钮，不需要回调，会自动处理
        },
      ],
    }
  },
  methods: {
    refresh() {
      return this.$refs.dossierDataTable.refresh(true)
    },
    rowClick(record) {
      debugger
      const url = '/audit-dossier-form?record=' + record.id // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
