<template>
  <div>
    <a-card>
      <!-- 高级搜索组件 -->
      <audit-advanced-query
        :expand="expand"
        :search-data="formData"
        :ref-name="searchform"
        :search-style="{ height: '130px', left: '20px', top: '57px' }"
        :search-fun="handleSearch"
        @searchedClick="searchedClick"
      >
        <template>
          <a-col :span="12">
            <a-form-model-item :label="'节点名称'" prop="nodeName">
              <a-input v-model="formData.nodeName" allow-clear />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item :label="'所属阶段'" prop="nodePeriod">
              <a-select v-model="formData.nodePeriod" :allow-clear="true">
                <a-select-option :value="'file-done'">
                  准备阶段
                </a-select-option>
                <a-select-option :value="'profile'">
                  实施阶段
                </a-select-option>
                <a-select-option :value="'file-text'">
                  报告阶段
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </template>
      </audit-advanced-query>

      <sd-data-table-ex
        ref="WorkNodeDataTable"
        :filter-expressions="expressions"
        :columns="columns"
        :actions="actions"
        form-id="iamWorkNode"
        page-id="audit/node/workNode/iamWorkNode"
        :search-fields="['nodeCode', 'nodeName', 'nodePeriod', 'creatorName']"
        show-selection
        :show-advance-query="true"
        @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 { getUserInfo } from '@/common/store-mixin'
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 '../../../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-worknode-list-import'

export default {
  name: 'AuditWorknodeList',
  metaInfo: {
    title: '作业节点',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins, auditAdvancedGroupMixins],
  data() {
    return {
      searchform: 'searchform',
      expressions: [],
      formData: {
        nodeName: '',
        nodePeriod: null,
      },
      formId: 'iamWorkNode',
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNumber',
          width: '80px',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: '节点名称',
          dataIndex: 'nodeName',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '代码',
          dataIndex: 'nodeCode',
        },
        {
          title: '所属阶段',
          dataIndex: 'nodePeriod',
        },
        {
          title: '排序号',
          dataIndex: 'sortNo',
          sorter: true,
          defaultSortOrder: 'ascend',
        },
        {
          title: '维护人员',
          dataIndex: 'creatorName',
        },
        {
          title: '维护日期',
          dataIndex: 'creationTime',
          sdRender: TableColumnTypes.date,
        },
      ],
      actions: [
        {
          label: '新建',
          id: 'new',
          permission: 'create',
          type: TableActionTypes.primary,
          callback: () => {
            const url = '/audit-worknode-form' // 新页面要打开的路由地址
            crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
              if (refreshFlag) {
                // 这里写或者调刷新的方法
                this.refresh()
              }
            })
          },
        },
        {
          label: '删除',
          id: 'delete',
          type: TableActionTypes.ex.delete, // 删除按钮，不需要回调，会自动处理（对sd-data-table无效）
        },
      ],
    }
  },
  computed: {},
  created() {},
  methods: {
    refresh() {
      return this.$refs.WorkNodeDataTable.refresh(true)
    },
    rowClick(record) {
      const url = '/audit-worknode-form?record=' + record.id // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },
    // 查询
    handleSearch() {
      this.expressions = []

      // 节点名称
      if (this.formData.nodeName) {
        this.expressions.push({
          dataType: 'str',
          name: 'nodeName',
          op: 'like',
          stringValue: `%${this.formData.nodeName}%`,
        })
      }
      // 所属阶段
      if (this.formData.nodePeriod) {
        this.expressions.push({
          dataType: 'str',
          name: 'nodePeriod',
          op: 'like',
          stringValue: `%${this.formData.nodePeriod}%`,
        })
      }
    },
  },
}
</script>

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