<template>
  <a-card>
    <sd-data-table-ex
      ref="refTable"
      form-id="spicDesensitize"
      page-id="audit/spicdesensitize/spicDesensitize"
      show-selection
      :columns="columns"
      :actions="actions"
    >
      <template slot="islink" slot-scope="text, record">
        <a :title="text" @click="rowClick(record)">{{ text }}</a>
      </template>
    </sd-data-table-ex>
  </a-card>
</template>

<script>
import TableActionTypes from '@/common/services/table-action-types'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import components from './_import-components/xm-spic-desensitize-config-import'

export default {
  name: 'XmSpicDesensitizeConfig',
  metaInfo: {
    title: '脱敏配置',
  },
  components,
  data() {
    return {
      columns: [
        { title: '序号', customRender: (text, record, index) => `${index + 1}`, width: '180px' },
        { title: '标题', dataIndex: 'title', scopedSlots: { customRender: 'islink' } },
      ],
      actions: [
        {
          label: '新建',
          id: 'new',
          permission: 'create',
          type: TableActionTypes.primary,
          callback: () => {
            const url = '/xm-spic-desensitize-config-form'
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                this.refresh()
              }
            })
          },
        },
        {
          label: '删除',
          id: 'delete',
          type: TableActionTypes.oa.delete,
        },
      ],
    }
  },
  methods: {
    rowClick(record) {
      const url = '/xm-spic-desensitize-config-form?record=' + record.id
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.$refs.refTable.refresh()
        }
      })
    },
    refresh() {
      this.$refs.refTable.refresh()
    },
  },
}
</script>

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