<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="financialSystemName">
              <a-input v-model="formData.financialSystemName" allow-clear />
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="财务系统版本" prop="financialSystemVersion">
              <a-input v-model="formData.financialSystemVersion" 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="iamFinFinancialSystem"
          page-id="dm/finsystem/iamFinFinancialSystem"
          :search-fields="['financialSystemName']"
          :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 axios from '@/common/services/axios-instance'
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-finsystem-list-import'

export default {
  name: 'IamDmFinsystemList',
  metaInfo: {
    title: '财务系统版本列表',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins],
  data() {
    return {
      dataType: [],
      searchform: 'searchform',
      expressions: [],
      formData: {
        financialSystemName: '',
        financialSystemVersion: '',
      },
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '财务系统名称',
          dataIndex: 'financialSystemName',
          scopedSlots: { customRender: 'islink' },
          width: '200px',
        },
        {
          title: '财务系统版本',
          dataIndex: 'financialSystemVersion',
        },
        {
          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-dm-finsystem-form' // 新页面要打开的路由地址
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                // 这里写或者调刷新的方法
                this.refresh()
              }
            })
          },
        },
      ],
    }
  },
  methods: {
    clearSelection() {
      this.$refs.sjzlTable.clearSelection()
    },
    // 刷新列表
    refresh() {
      // this.$refs.sjzlTable.refresh()
      this.$emit('refreshTable')
    },
    // 新建、详情打开新页面
    rowClick(record) {
      const url = '/iam-dm-finsystem-form?record=' + record.id // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },
    // 查询
    handleSearch() {
      this.expressions = []

      // 财务系统名称
      if (this.formData.financialSystemName) {
        this.expressions.push({
          dataType: 'str',
          name: 'financialSystemName',
          op: 'like',
          stringValue: `%${this.formData.financialSystemName}%`,
        })
      }

      // 财务系统版本
      if (this.formData.financialSystemVersion) {
        this.expressions.push({
          dataType: 'str',
          name: 'financialSystemVersion',
          op: 'like',
          stringValue: `%${this.formData.financialSystemVersion}%`,
        })
      }
    },
  },
}
</script>

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