<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <MesXslRackTrainCountSettingModal @register="registerModal" @success="handleSuccess" />
  </div>
</template>

<script lang="ts" name="MesXslRackTrainCountSettingList" setup>
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import MesXslRackTrainCountSettingModal from './components/MesXslRackTrainCountSettingModal.vue';
  import { columns, searchFormSchema } from './MesXslRackTrainCountSetting.data';
  import { list } from './MesXslRackTrainCountSetting.api';

  const [registerModal, { openModal }] = useModal();

  const { tableContext } = useListPage({
    tableProps: {
      title: '架子车数设定',
      api: list,
      columns,
      canResize: true,
      showIndexColumn: true,
      tableSetting: { cacheKey: 'mesXslRackTrainCountSetting_v20260528' },
      formConfig: {
        labelWidth: 90,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
      },
      actionColumn: {
        title: '操作',
        dataIndex: 'action',
        width: 140,
        fixed: 'right',
        slots: { customRender: 'action' },
      },
      defSort: {
        column: 'updateTime',
        order: 'desc',
      },
    },
  });

  const [registerTable, { reload }] = tableContext;

  function handleEdit(record: Recordable) {
    openModal(true, { record, isUpdate: true, showFooter: true });
  }

  function handleDetail(record: Recordable) {
    openModal(true, { record, isUpdate: true, showFooter: false });
  }

  function handleSuccess() {
    reload();
  }

  function getTableAction(record: Recordable) {
    return [
      {
        label: '设定',
        onClick: handleEdit.bind(null, record),
        auth: 'xslmes:mes_xsl_rack_train_count_setting:edit',
      },
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
        auth: 'xslmes:mes_xsl_rack_train_count_setting:list',
      },
    ];
  }
</script>
