<!--
 * @Description: 
 * @Author: Format-qi 283810417@qq.com
 * @Date: 2022-05-12 15:27:52
 * @LastEditors: Format-qi 283810417@qq.com
 * @LastEditTime: 2022-08-02 17:20:35
-->
<template>
  <div class="p-4">
    <BzTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'icon-shouye|font',
              iconSize: 10,
              label: '编辑',
            },
            {
              icon: 'icon-shouye|font',
              label: '删除',
              onClick: handleDelete.bind(null, record),
            },
          ]"
          :dropDownActions="[
            {
              label: '启用',
              iconColor: 'red',
              iconSize: 10,
              textColor: 'red',
              icon: 'icon-shouye|font',
              popConfirm: {
                title: '是否启用？',
                confirm: handleOpen.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BzTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BzTable, useTable, BasicColumn, TableAction } from '/@/index';

  import { demoListApi } from './tableData';
  const columns: BasicColumn[] = [
    {
      title: 'ID',
      dataIndex: 'id',
      fixed: 'left',
      width: 280,
    },
    {
      title: '姓名',
      dataIndex: 'name',
      width: 260,
    },
    {
      title: '地址',
      dataIndex: 'address',
    },
    {
      title: '编号',
      dataIndex: 'no',
      width: 300,
    },
    {
      title: '开始时间',
      width: 200,
      dataIndex: 'beginTime',
    },
    {
      title: '结束时间',
      dataIndex: 'endTime',
      width: 200,
    },
  ];
  export default defineComponent({
    components: { BzTable, TableAction },
    setup() {
      const [registerTable] = useTable({
        title: 'TableAction组件及固定列示例',
        api: demoListApi,
        columns: columns,
        rowSelection: { type: 'radio' },
        bordered: false,
        actionColumn: {
          width: 160,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });
      function handleDelete(record: Recordable) {
        console.log('点击了删除', record);
      }
      function handleOpen(record: Recordable) {
        console.log('点击了启用', record);
      }
      return {
        registerTable,
        handleDelete,
        handleOpen,
      };
    },
  });
</script>
