<template>
  <a-card>
    <!-- 高级搜索组件 -->
    <audit-advanced-query
      :expand="expand"
      :search-data="formData"
      :ref-name="searchform"
      :search-style="{ height: '150px', left: '20px', top: '57px' }"
      :search-fun="handleSearch"
      @searchedClick="searchedClick"
    >
      <template>
        <a-col :span="12">
          <a-form-model-item label="模板名称" prop="templateName">
            <a-input v-model="formData.templateName" allow-clear />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="编制人员" prop="creatorName">
            <a-input v-model="formData.creatorName" allow-clear />
          </a-form-model-item>
        </a-col>
      </template>
    </audit-advanced-query>
    <sd-data-table-ex
      ref="auditMattersTemplateTable"
      form-id="iamAuditMattersTemplate"
      data-url="api/xcoa-mobile/v1/iam-auditmatters-template/businessList"
      :columns="columns"
      :actions="actions"
      show-selection
      :show-advance-query="true"
      :filter-expressions="expressions"
      :search-fields="['templateName']"

      @searchbtnClick="searchbtnClick"
    >
      <div slot="islink" slot-scope="text, record">
        <a :title="text" @click="rowClick(record)">{{ text }}</a>
      </div>
    </sd-data-table-ex>
  </a-card>
</template>

<script>
import TableColumnTypes from '@/common/services/table-column-types'
import TableActionTypes from '@/common/services/table-action-types'
import crossWindowWatcher from '@/common/services/cross-window-watcher'

import auditAdvancedQuery from '../../../components/audit-advanced-query.vue'
import auditAdvancedQueryMixins from '../../../components/audit-advanced-query-mixins'
import components from './_import-components/audit-matters-template-list-import'

export default {
  name: 'AuditMattersTemplateList',
  metaInfo: {
    title: '审计事项模板',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins],
  data() {
    return {
      searchform: 'searchform',
      formData: {
        templateName: '',
        creatorName: '',
      },
      expressions: [],
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '模板名称',
          dataIndex: 'templateName',
          scopedSlots: { customRender: 'islink' },
          width: '50%',
        },
        {
          title: '编制人员',
          dataIndex: 'creatorName',
          width: '30%',
        },

        {
          title: '编制日期',
          dataIndex: 'creationTime',
          sdRender: TableColumnTypes.date,
          width: '20%',
          sorter: true,
        },
      ],
      actions: [
        {
          label: '新建',
          id: 'new',
          type: TableActionTypes.primary, // 新建按钮，不需要回调，自动处理
          permission: 'iamAuditMatters-create',
          callback: () => {
            const url = '/audit-matters-template-form' // 新页面要打开的路由地址
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                // 这里写或者调刷新的方法
                this.refresh()
              }
            })
          },
        },
        {
          label: '删除',
          id: 'delete',
          permission: 'iamAuditMatters-delete',
          type: TableActionTypes.ex.delete,
        },
      ],
    }
  },
  created() {},
  methods: {
    handleSearch() {
      this.expressions = []
      // 模板名称
      if (this.formData.templateName) {
        this.expressions.push({
          dataType: 'str',
          name: 'templateName',
          op: 'like',
          stringValue: '%' + this.formData.templateName + '%',
        })
      }
      // 编制人员
      if (this.formData.creatorName) {
        this.expressions.push({
          dataType: 'str',
          name: 'creatorName',
          op: 'like',
          stringValue: '%' + this.formData.creatorName + '%',
        })
      }
    },
    // 新建、详情打开新页面
    rowClick(record) {
      const url = '/audit-matters-template-form?record=' + record.id // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },

    refresh() {
      this.$refs.auditMattersTemplateTable.refresh()
    },
  },
}
</script>

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