<template>
  <a-card>
    <sd-data-table-sys
      ref="leaderTable"
      form-id="oaLeaderSecretary"
      page-id="base/leadersecretary/oaLeaderSecretary"
      :columns="columns"
      show-selection
      :actions="actions"
      :search-fields="['leaderName', 'secretaryName']"
      @hierarchyChange="hierarchyChange"
    >
      <!-- 详情表单 -->
      <template v-slot:form>
        <sd-form-item name="sortNumber" />
        <sd-form-item name="leaderUserMember" :input-props="{ rootNode }" />
        <sd-form-item name="secretaryUserMember" :input-props="{ rootNode }" />
      </template>
    </sd-data-table-sys>
  </a-card>
</template>

<script>
import TableActionTypes from '@/common/services/table-action-types'
import components from './_import-components/sd-leader-mapping-import'
const columns = [
  {
    title: '排序号',
    dataIndex: 'sortNumber',
    sdClickable: true,
    defaultSortOrder: 'asc', // 没有点击任何排序列时，默认的排序列
  },
  {
    title: '领导',
    dataIndex: 'leaderName',
    sdClickable: true,
  },
  {
    title: '秘书',
    dataIndex: 'secretaryName',
    sdClickable: true,
  },
]

export default {
  name: 'SdLeaderMapping',
  metaInfo: {
    title: '领导秘书映射配置',
  },
  components,
  data() {
    return {
      columns,
      actions: [
        {
          label: '新建',
          id: 'new',
          type: TableActionTypes.ex.create, // 新建按钮，不需要回调，自动处理
        },
        {
          label: '删除',
          id: 'delete',
          type: TableActionTypes.ex.delete, // 删除按钮，不需要回调，会自动处理（对sd-data-table无效）
        },
      ],
      rootNode: undefined,
    }
  },
  methods: {
    hierarchyChange(belongedOrg) {
      if (belongedOrg) {
        this.rootNode = [{ ...belongedOrg, code: belongedOrg.id }]
      }
    },
  },
}
</script>

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