<template>
  <div>
    <a-card>
      <sd-data-table-ex
        ref="dataTable"
        :filter-expressions="expressions"
        :columns="columns"
        :actions="actions"
        form-id="kpiJobInfo"
        page-id="kpi/job/kpiJobInfo"
        show-selection
        :modal-props="{ class: 'noBottom' }"
        @searchbtnClick="searchbtnClick"
      >
        <div slot="islink" slot-scope="text, record">
          <a :title="text" @click="rowClick(record)">{{ text }}</a>
        </div>
      </sd-data-table-ex>
    </a-card>
  </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 auditAdvancedQueryMixins from '@product/iam/components/audit-advanced-query-mixins'
import components from './_import-components/kpi-job-list-import'

export default {
  name: 'KpiJobList',
  metaInfo: {
    title: '指标定时任务列表',
  },
  components: {
    ...components,
  },
  mixins: [auditAdvancedQueryMixins],
  data() {
    return {
      checked: true,
      checking: false, // 按钮是否执行中
      dataType: [],
      searchform: 'searchform',
      expressions: [],
      formData: {
        name: '',
        databaseStatus: '',
      },
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '时间维度',
          dataIndex: 'jobFrequency',
          scopedSlots: { customRender: 'islink' },
          width: '300px',
        },
        {
          title: '执行规则',
          dataIndex: 'jobCron',
        },

        {
          title: '启用',
          dataIndex: 'jobStatus',
          sdRender: TableColumnTypes.ex.switch,
        },
      ],
      actions: [
        {
          label: '删除',
          permission: null,
          type: TableActionTypes.ex.delete,
        },
        {
          label: '新建',
          type: TableActionTypes.primary, // 新建按钮，不需要回调，自动处理
          permission: 'create', // 权限控制
          callback: () => {
            const url = '/kpi-job-form' // 新页面要打开的路由地址
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                // 这里写或者调刷新的方法
                this.refresh()
              }
            })
          },
        },
      ],
    }
  },
  mounted() {},
  methods: {
    // 开关点击事件
    switchClick(record) {},
    clearSelection() {
      this.$refs.sjzlTable.clearSelection()
    },
    // 刷新列表
    refresh() {
      this.$refs.dataTable.refresh()
    },
    // 新建、详情打开新页面
    rowClick(record) {
      const url = '/kpi-job-form?record=' + record.id // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },
    // 重置查询
    resetForm() {
      this.expressions = []
      this.formData = {}
    },
  },
}
</script>

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