<template>
  <a-alert type="warning" class="mt-16">
    <template #message>
      不可与scroll共用。TableAction组件可配置stopButtonPropagation来阻止操作按钮的点击事件冒泡，以便配合Table组件的expandRowByClick
    </template>
  </a-alert>

  <BzTable @register="registerTable" class="mt-16">
    <template #expandedRowRender="{ record }">
      <span>No: {{ record.no }} </span>
    </template>
    <template #action="{ record }">
      <TableAction
        stopButtonPropagation
        :actions="[
          {
            label: '删除',
            onClick: handleDelete.bind(null, record),
          },
        ]"
        :dropDownActions="[
          {
            label: '启用',
            popConfirm: {
              title: '是否启用？',
              confirm: handleOpen.bind(null, record),
            },
          },
        ]"
      />
    </template>
  </BzTable>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BzTable, useTable, TableAction } from '/@/index';
  import { getBasicColumns } from './tableData';
  import { Alert } from 'ant-design-vue';
  import { demoListApi } from './tableData';

  export default defineComponent({
    components: { BzTable, TableAction, AAlert: Alert },
    setup() {
      const [registerTable] = useTable({
        api: demoListApi,
        title: '可展开表格演示',
        titleHelpMessage: ['已启用expandRowByClick', '已启用stopButtonPropagation'],
        columns: getBasicColumns(),
        rowKey: 'id',
        canResize: false,
        expandRowByClick: true,
        actionColumn: {
          width: 160,
          title: '操作',
          slots: { customRender: 'action' },
        },
      });
      function handleDelete(record: Recordable) {
        console.log('点击了删除', record);
      }
      function handleOpen(record: Recordable) {
        console.log('点击了启用', record);
      }

      return {
        registerTable,
        handleDelete,
        handleOpen,
      };
    },
  });
</script>
