hooks.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {useTableModalEvent, useTableDeleteEvent} from '@hooks';
  2. import {delMaterialBind} from '@apis';
  3. import {ColumnsType} from 'antd/es/table';
  4. import {MaterialBindListData} from '@models';
  5. import {Button} from 'antd';
  6. import {
  7. DOUBLE_BTN_WIDTH,
  8. HUGE_TABLE_WIDTH,
  9. MIDDLE_TABLE_WIDTH,
  10. NORMAL_TABLE_WIDTH,
  11. } from '@utils';
  12. const tableColumns: ColumnsType<MaterialBindListData> = [
  13. {
  14. title: '物料编号',
  15. dataIndex: 'wllbCode',
  16. key: 'wllbCode',
  17. width: MIDDLE_TABLE_WIDTH,
  18. },
  19. {
  20. title: '物料名称',
  21. dataIndex: 'materialName',
  22. key: 'materialName',
  23. width: HUGE_TABLE_WIDTH,
  24. },
  25. {
  26. title: '工号',
  27. dataIndex: 'userName',
  28. key: 'userName',
  29. width: MIDDLE_TABLE_WIDTH,
  30. },
  31. {
  32. title: '姓名',
  33. dataIndex: 'realName',
  34. key: 'realName',
  35. width: MIDDLE_TABLE_WIDTH,
  36. },
  37. {
  38. title: '修改人',
  39. dataIndex: 'modifyUser',
  40. key: 'modifyUser',
  41. width: NORMAL_TABLE_WIDTH,
  42. },
  43. {
  44. title: '修改时间',
  45. dataIndex: 'modifyTime',
  46. key: 'modifyTime',
  47. width: MIDDLE_TABLE_WIDTH,
  48. },
  49. ];
  50. export function useHandle(refetch: () => void) {
  51. const [{visible, editId}, {onAdd, onClose, onEdit}] = useTableModalEvent();
  52. const [pendingId, onDelete] = useTableDeleteEvent(delMaterialBind, refetch, {
  53. label: '物料绑定',
  54. });
  55. const columns: ColumnsType<MaterialBindListData> = [
  56. ...tableColumns,
  57. {
  58. title: '操作',
  59. dataIndex: 'id',
  60. key: 'id',
  61. width: DOUBLE_BTN_WIDTH,
  62. fixed: 'right',
  63. render(_, {id, wllbCode}) {
  64. return (
  65. <>
  66. <Button
  67. type='text'
  68. className='ant-text-btn-color-primary'
  69. disabled={pendingId === id}
  70. onClick={onEdit(id)}
  71. >
  72. 修改
  73. </Button>
  74. <Button
  75. type='text'
  76. danger
  77. onClick={onDelete(id, wllbCode)}
  78. loading={pendingId === id}
  79. >
  80. 删除
  81. </Button>
  82. </>
  83. );
  84. },
  85. },
  86. ];
  87. return [
  88. {visible, columns, editId},
  89. {onAdd, onClose},
  90. ] as const;
  91. }