Browse Source

feat: 其他入增加删除功能

xyh 2 years ago
parent
commit
8bc6bf4243

+ 1 - 0
packages/app/src/pages/other-in/context.ts

@@ -15,5 +15,6 @@ export const contextState: OriginalListParams<GetOtherInParams> = {
   companyNumber: '',
   wbs: '',
   noticeCode: '',
+  type: '',
 };
 export const context = createTableSearchContext(contextState);

+ 12 - 0
packages/app/src/pages/other-in/filter/state.ts

@@ -19,4 +19,16 @@ export const sourceMap: FilterGroupMap<typeof contextState> = new Map([
     },
   ],
   ['3', {type: 'field', label: 'WBS编号', value: 'wbs'}],
+  [
+    '4',
+    {
+      type: 'select',
+      label: '入库状态',
+      value: 'type',
+      options: [
+        {label: '已完成', value: '1'},
+        {label: '未完成', value: '0'},
+      ],
+    },
+  ],
 ]);

+ 33 - 3
packages/app/src/pages/other-in/table/hooks.tsx

@@ -1,3 +1,5 @@
+import {deleteOtherIn} from '@apis';
+import {useSupertube, useTableDeleteEvent} from '@hooks';
 import {OtherInListData} from '@models';
 import {
   HUGE_TABLE_WIDTH,
@@ -5,6 +7,7 @@ import {
   NORMAL_TABLE_WIDTH,
   SMALL_TABLE_WIDTH,
 } from '@utils';
+import {Button} from 'antd';
 import {ColumnsType} from 'antd/es/table';
 
 const columns: ColumnsType<OtherInListData> = [
@@ -29,8 +32,35 @@ const columns: ColumnsType<OtherInListData> = [
   {title: 'WBS编号', dataIndex: 'wbs', width: NORMAL_TABLE_WIDTH},
 ];
 
-export function useColumns() {
-  const tableColumns = [...columns];
+export function useColumns(refetch: () => void) {
+  const isSuper = useSupertube();
+  const [pendingId, onDelete] = useTableDeleteEvent(deleteOtherIn, refetch, {
+    label: '其他入库',
+  });
 
-  return tableColumns;
+  const tableColumns: ColumnsType<OtherInListData> = [
+    ...columns,
+    {
+      title: '操作',
+      dataIndex: 'id',
+      width: SMALL_TABLE_WIDTH,
+      fixed: 'right',
+      render(_, {id, noticeCode}) {
+        return (
+          <>
+            <Button
+              type='text'
+              danger
+              loading={pendingId === id}
+              onClick={onDelete(id, noticeCode)}
+            >
+              删除
+            </Button>
+          </>
+        );
+      },
+    },
+  ];
+
+  return isSuper ? tableColumns : columns;
 }

+ 1 - 1
packages/app/src/pages/other-in/table/index.tsx

@@ -14,7 +14,7 @@ const TableList: FC = function () {
     params,
     searchContext,
   });
-  const columns = useColumns();
+  const columns = useColumns(refetch);
 
   return (
     <Card className='table-wrapper'>