<template>
  <a-card>
    <sd-data-table-sys
      ref="dataTable"
      form-id="oaUserWhiteList"
      page-id="base/exclusive/oaUserWhiteList"
      :columns="columns"
      show-selection
      :actions="actions"
      :search-fields="['userName']"
      @hierarchyChange="hierarchyChange"
    >
      <template v-slot:form="{ model }">
        <sd-form-item name="id" hidden />
        <sd-form-item name="userMember">
          <sd-user-picker
            v-model="model.userMember"
            :single="false"
            :read-only="!!model.id"
            :root-node="rootNode"
            hierarchical
          />
        </sd-form-item>
        <sd-form-item name="sortNum" />
        <sd-form-item name="remark">
          <a-textarea v-model="model.remark" autosize />
        </sd-form-item>
      </template>
    </sd-data-table-sys>
  </a-card>
</template>

<script>
import TableActionTypes from '@/common/services/table-action-types'
import TableColumnTypes from '../common/services/table-column-types'
import components from './_import-components/sd-exclude-login-manage-import'
const columns = [
  {
    title: '排序号',
    dataIndex: 'sortNum',
    defaultSortOrder: 'ascend',
  },
  {
    title: '白名单人员',
    dataIndex: 'userName',
    sdClickable: true,
  },
  {
    title: '所属部门',
    dataIndex: 'deptName',
  },

  {
    title: '创建时间',
    dataIndex: 'creationTime',
    sdRender: TableColumnTypes.dateTime,
    defaultSortOrder: 'desc',
  },
  {
    title: '备注',
    dataIndex: 'remark',
  },
]
export default {
  name: 'SdExcludeLoginManage',
  metaInfo: {
    title: '排他登录管理',
  },
  components,
  data() {
    return {
      columns,
      actions: [
        {
          label: '新建',
          id: 'new',
          type: TableActionTypes.ex.create,
        },
        {
          label: '删除',
          id: 'delete',
          type: TableActionTypes.ex.delete,
        },
      ],
      rootNode: undefined,
    }
  },
  methods: {
    hierarchyChange(belongedOrg) {
      if (belongedOrg) {
        this.rootNode = [{ ...belongedOrg, code: belongedOrg.id }]
      }
    },
  },
}
</script>

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