<template>
  <a-card :bordered="false" :class="$style.newcard">
    <div>
      <audit-advanced-query
        :expand="expand"
        :search-data="formData"
        :ref-name="searchform"
        :search-style="{ height: '135px', left: '0px', top: '40px' }"
        :search-fun="handleSearch"
        @searchedClick="searchedClick"
      >
        <template>
          <a-col :span="12">
            <a-form-model-item label="报表编码" prop="reportCode">
              <a-input v-model="formData.reportCode" allow-clear />
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="报表名称" prop="reportName">
              <a-input v-model="formData.reportName" allow-clear />
            </a-form-model-item>
          </a-col>
        </template>
      </audit-advanced-query>
      <a-card>
        <sd-data-table-ex
          ref="dataTable"
          :filter-expressions="expressions"
          :columns="columns"
          :actions="actions"
          form-id="iamFineReport"
          page-id="core/finereport/iamFineReport"
          :search-fields="['configName']"
          :show-advance-query="true"
          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>
  </a-card>
</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 auditAdvancedQuery from '@product/iam/components/audit-advanced-query.vue'
import auditAdvancedQueryMixins from '@product/iam/components/audit-advanced-query-mixins'
import components from './_import-components/iam-dm-finereport-list-import'

export default {
  name: 'IamDmFinereportList',
  metaInfo: {
    title: '帆软报表配置列表',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins],
  data() {
    return {
      expressions: [],
      searchform: 'searchform',
      formData: {
        reportCode: '',
        reportName: '',
      },
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '报表编码',
          dataIndex: 'reportCode',
          scopedSlots: { customRender: 'islink' },
          width: '200px',
        },
        {
          title: '报表名称',
          dataIndex: 'reportName',
        },
        {
          title: '报表文件路径',
          dataIndex: 'reportFileName',
        },
        {
          title: '附件',
          dataIndex: 'attachment',
        },
        {
          title: '维护人员',
          dataIndex: 'creatorName',
        },
        {
          title: '维护日期',
          dataIndex: 'creationTime',
          sdRender: TableColumnTypes.date,
        },
      ],
      actions: [
        {
          label: '删除',
          permission: null,
          type: TableActionTypes.ex.delete,
        },
        {
          label: '新建',
          type: TableActionTypes.primary, // 新建按钮，不需要回调，自动处理
          permission: null, // 权限控制
          callback: () => {
            const url = '/iam-finereport-form' // 新页面要打开的路由地址
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                // 这里写或者调刷新的方法
                this.refresh()
              }
            })
          },
        },
      ],
    }
  },
  methods: {
    clearSelection() {
      this.$refs.dataTable.clearSelection()
    },
    // 刷新列表
    refresh() {
      this.$emit('refreshTable')
      this.$refs.dataTable.refresh()
    },
    // 查询
    handleSearch() {
      this.expressions = []

      // 报表编码
      if (this.formData.reportCode) {
        this.expressions.push({
          dataType: 'str',
          name: 'reportCode',
          op: 'like',
          stringValue: `%${this.formData.reportCode}%`,
        })
      }

      // 报表名称
      if (this.formData.reportName) {
        this.expressions.push({
          dataType: 'str',
          name: 'reportName',
          op: 'like',
          stringValue: `%${this.formData.reportName}%`,
        })
      }
    },
    // 查看
    rowClick(record) {
      const url = '/iam-finereport-form?record=' + record.id // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.newcard {
  padding: 16px;
  :global(.ant-card-body) {
    padding: 0;
  }
}
</style>
