hooks.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {useContextSection, useQueryTableList} from '@hooks';
  2. import {context, pageContext, searchContext} from '../context';
  3. import {getDictionaryList} from '@apis';
  4. import {DictionaryData, DictionaryParamsType} from '@models';
  5. import {Button} from 'antd';
  6. import {ColumnsType} from 'antd/es/table';
  7. import {useState} from 'react';
  8. import {useBoolean} from 'ahooks';
  9. export function useList() {
  10. const params = useContextSection(
  11. context,
  12. function([{name, code}]) {
  13. return {name, code, type: ('物料字典' as DictionaryParamsType)};
  14. },
  15. );
  16. return useQueryTableList({
  17. queryFn: getDictionaryList,
  18. params,
  19. pageContext,
  20. searchContext,
  21. });
  22. }
  23. export function useEdit() {
  24. const [editId, setEditId] = useState('');
  25. const [visible, {setTrue, setFalse}] = useBoolean();
  26. function onEdit(id: string) {
  27. return function() {
  28. setEditId(id);
  29. setTrue();
  30. };
  31. }
  32. return [{visible, editId}, {onClose: setFalse, onEdit}] as const;
  33. }
  34. export function useHandle() {
  35. const [{visible, editId}, {onClose, onEdit}] = useEdit();
  36. const columns: ColumnsType<DictionaryData> = [
  37. {title: '物料名称', dataIndex: 'name', key: 'name'},
  38. {title: '物料编号', dataIndex: 'code', key: 'code'},
  39. {title: '物料类型', dataIndex: 'materialType', key: 'materialType'},
  40. {title: '存储容量', dataIndex: 'size', key: 'size'},
  41. {
  42. title: '是否混合存储',
  43. dataIndex: 'isNotDisable',
  44. key: 'isNotDisable',
  45. render(_, {isNotDisable}) {
  46. return isNotDisable === '1' ? '是' : '否';
  47. },
  48. },
  49. {
  50. title: '操作',
  51. dataIndex: 'tldId',
  52. key: 'tldId',
  53. width: 330,
  54. render(_, {tldId}) {
  55. return (
  56. <>
  57. <Button
  58. type='link'
  59. onClick={onEdit(tldId)}
  60. >
  61. 修改
  62. </Button>
  63. </>
  64. );
  65. },
  66. },
  67. ];
  68. return [{columns, visible, editId}, {onClose}] as const;
  69. }