<template>
  <div>
    <a-card>
      <!-- 高级搜索组件 -->
      <audit-advanced-query
        :expand="expand"
        :search-data="formData"
        :ref-name="searchform"
        :search-style="{ height: '150px', left: '20px', top: '80px' }"
        :search-fun="handleSearch"
        @searchedClick="searchedClick"
      >
        <template>
          <a-col :span="12">
            <a-form-model-item :label="'目录名称'" prop="contentsTitle">
              <a-input v-model="formData.contentsTitle" allow-clear />
            </a-form-model-item>
          </a-col>
        </template>
      </audit-advanced-query>

      <sd-data-table-ex
        ref="deployDataTable"
        :filter-expressions="expressions"
        :columns="columns"
        :actions="actions"
        form-id="iamDirectoryDeploy"
        page-id="audit/deploy/iamDirectoryDeploy"
        :search-fields="['contentsTitle']"
        show-selection
        :show-advance-query="true"
        @searchbtnClick="searchbtnClick"
      >
        <div slot="islink" slot-scope="text, record">
          <a @click="rowClick(record)">{{ text }}</a>
        </div>
      </sd-data-table-ex>
    </a-card>
  </div>
</template>

<script>
import TableActionTypes from '@/common/services/table-action-types'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditAdvancedQueryMixins from '../../components/audit-advanced-query-mixins'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import auditAdvancedQuery from '../../components/audit-advanced-query.vue'
import components from './_import-components/audit-deploy-list-import'

export default {
  name: 'AuditDeployList',
  metaInfo: {
    title: '目录配置',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins, auditAdvancedGroupMixins],
  data() {
    return {
      searchform: 'searchform',
      expressions: [],
      formId: 'iamDirectoryDeploy',
      formData: {
        contentsTitle: '',
      },
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNumber',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '目录名称',
          dataIndex: 'contentsTitle',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '显示顺序',
          dataIndex: 'contentsOrder',
          defaultSortOrder: 'asc', // 没有点击任何排序列时，默认的排序列
          width: '10%',
        },
        {
          title: '归辑内容',
          dataIndex: 'collectionContent',
          width: '35%',
        },
        {
          title: '简要描述',
          dataIndex: 'remarks',
        },
      ],
      actions: [
        {
          label: '新建',
          id: 'new',
          permission: 'create',
          type: TableActionTypes.primary,
          callback: () => {
            const url = '/audit-deploy-form' // 新页面要打开的路由地址
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                // 这里写或者调刷新的方法
                this.refresh()
              }
            })
          },
        },
        {
          label: '删除',
          id: 'delete',
          type: TableActionTypes.oa.delete, // 删除按钮，不需要回调，会自动处理
        },
      ],
    }
  },
  methods: {
    // 查询
    handleSearch() {
      this.expressions = []
      // 项目名称
      if (this.formData.contentsTitle) {
        this.expressions.push({
          dataType: 'str',
          name: 'contentsTitle',
          op: 'like',
          stringValue: `%${this.formData.contentsTitle}%`,
        })
      }
    },

    refresh() {
      return this.$refs.deployDataTable.refresh(true)
    },
    rowClick(record) {
      const url = '/audit-deploy-form?record=' + record.id // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },
  },
}
</script>

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