Ver código fonte

chore: 领料单和出库单数量固定

xyh 2 anos atrás
pai
commit
c82b64528e

+ 48 - 17
packages/app/src/pages/semi-draw/table/hooks.tsx

@@ -1,12 +1,14 @@
 import {useContextSection, useQueryTableList} from '@hooks';
 import {context, pageContext, searchContext} from '../context';
-import {getSemiManufacturesDrawList} from '@apis';
+import {getSemiManufacturesDrawList, semiManufacturesOut} from '@apis';
 import {ColumnsType} from 'antd/es/table';
 import {SemiDrawListData} from '@models';
-import {useBoolean} from 'ahooks';
 import {useState} from 'react';
-import {Button} from 'antd';
+import {Button, Modal, message} from 'antd';
 import {MIDDLE_TABLE_WIDTH, NORMAL_TABLE_WIDTH, SMALL_TABLE_WIDTH} from '@utils';
+import {useMutation} from '@tanstack/react-query';
+import {useStore} from 'zustand';
+import {userStore} from '@stores';
 
 export function useList() {
   const params = useContextSection(context, function([{code, type}]) {
@@ -26,22 +28,50 @@ export function useList() {
   });
 }
 
-function useClick() {
-  const [visible, {setTrue, setFalse}] = useBoolean();
-  const [id, setId] = useState('');
+function usePutInQuery(refetch: () => void) {
+  const [pendingId, setPendingId] = useState('');
+  const userId = useStore(userStore, state => String(state.id));
 
-  function onClick(id: string) {
+  const {mutate} = useMutation({
+    mutationFn: semiManufacturesOut,
+    onSuccess({msg}) {
+      if (msg === '200') {
+        refetch();
+        setPendingId('');
+        message.success('出库成功');
+      }
+    },
+  });
+
+  function putInQuery(data: SemiDrawListData) {
+    const {companyNumber, wbs, materialId, askGoodsId, num, id, materialCode} = data;
+    setPendingId(id);
+    mutate({
+      companyNumber,
+      wbs,
+      materialId,
+      warehousingNum: num,
+      userId,
+      askGoodsId,
+      wllbCode: materialCode,
+    });
+  }
+
+  function onClick(data: SemiDrawListData) {
     return function() {
-      setId(id);
-      setTrue();
+      Modal.confirm({
+        title: '出库',
+        content: `你确定要对${data.askGoodsId}出库吗?`,
+        onOk: () => putInQuery(data),
+      });
     };
   }
 
-  return [{visible, id}, {onClick, onClose: setFalse}] as const;
+  return [pendingId, onClick] as const;
 }
 
-export function useHandle() {
-  const [{visible, id}, {onClick, onClose}] = useClick();
+export function useHandle(refetch: () => void) {
+  const [pendingId, onClick] = usePutInQuery(refetch);
 
   const columns: ColumnsType<SemiDrawListData> = [
     {title: '要货单编号', dataIndex: 'askGoodsId', key: 'askGoodsId', width: NORMAL_TABLE_WIDTH},
@@ -65,15 +95,16 @@ export function useHandle() {
       key: 'id',
       fixed: 'right',
       width: SMALL_TABLE_WIDTH,
-      render(_, {id, type}) {
+      render(_, data) {
         return (
           <>
             <Button
               type='link'
-              disabled={type !== '0'}
-              onClick={onClick(id)}
+              disabled={data.type !== '0'}
+              onClick={onClick(data)}
+              loading={pendingId === data.id}
             >
-              {type === '0' ? '出库' : '已出库'}
+              {data.type === '0' ? '出库' : '已出库'}
             </Button>
 
           </>
@@ -82,5 +113,5 @@ export function useHandle() {
     },
   ];
 
-  return [{columns, visible, id}, {onClose}] as const;
+  return [{columns}] as const;
 }

+ 1 - 3
packages/app/src/pages/semi-draw/table/index.tsx

@@ -3,11 +3,10 @@ import {useHandle, useList} from './hooks';
 import {Card} from 'antd';
 import {Table} from '@components';
 import {pageContext, searchContext} from '../context';
-import PutModal from './modal';
 
 const TableList: FC = function() {
   const [{data, count}, {refetch}] = useList();
-  const [{columns, visible, id}, {onClose}] = useHandle();
+  const [{columns}] = useHandle(refetch);
 
   return (
     <>
@@ -22,7 +21,6 @@ const TableList: FC = function() {
         />
       </Card>
 
-      <PutModal id={id} onClose={onClose} onFetch={refetch} visible={visible} />
     </>
   );
 };

+ 50 - 27
packages/app/src/pages/semi-report/table/hooks.tsx

@@ -1,10 +1,9 @@
 import {useContextSection, useQueryTableList} from '@hooks';
 import {context, contextStateSelector, pageContext, searchContext} from '../context';
-import {getNoticeList} from '@apis';
-import {Button} from 'antd';
+import {getNoticeList, semiManufacturesAdd} from '@apis';
+import {Button, Modal, message} from 'antd';
 import {ColumnsType} from 'antd/es/table';
 import {NoticeListData} from '@models';
-import {useBoolean} from 'ahooks';
 import {useState} from 'react';
 import {
   HUGE_TABLE_WIDTH,
@@ -12,6 +11,9 @@ import {
   NORMAL_TABLE_WIDTH,
   SMALL_TABLE_WIDTH,
 } from '@utils';
+import {useMutation} from '@tanstack/react-query';
+import {useStore} from 'zustand';
+import {userStore} from '@stores';
 
 export function useList() {
   const params = useContextSection(
@@ -27,37 +29,57 @@ export function useList() {
   });
 }
 
-function usePutIn() {
-  const [visible, {setTrue, setFalse}] = useBoolean(false);
-  const [state, setState] = useState('');
+function usePutInStorage(refetch: () => void) {
+  const [pendingId, setPendingId] = useState('');
+  const userId = useStore(userStore, state => String(state.id));
 
-  function onClick(id: string) {
+  const {mutate} = useMutation({
+    mutationFn: semiManufacturesAdd,
+    onSuccess({msg}) {
+      if (msg === '200') {
+        refetch();
+        setPendingId('');
+        message.success('入库成功');
+      }
+    },
+  });
+
+  function putInQuery(data: NoticeListData) {
+    const {wllbClass, companyNumber, wbs, materialId, noticeId, wllbCode, num, id} = data;
+    setPendingId(id);
+    mutate({
+      wllbClass,
+      companyNumber,
+      wbs,
+      materialId,
+      noticeId,
+      wllbCode,
+      warehousingNum: num,
+      userId,
+    });
+  }
+
+  function onClick(data: NoticeListData) {
     return function() {
-      setTrue();
-      setState(id);
+      Modal.confirm({
+        title: '入库',
+        content: `你确定要对${data.noticeId}入库吗?`,
+        onOk: () => putInQuery(data),
+      });
     };
   }
 
-  return [{visible, state}, {onClick, onClose: setFalse}] as const;
+  return [pendingId, onClick] as const;
 }
 
-export function useHandle() {
-  const [{visible, state}, {onClick, onClose}] = usePutIn();
+export function useHandle(refetch: () => void) {
+  const [pendingId, onClick] = usePutInStorage(refetch);
 
   const columns: ColumnsType<NoticeListData> = [
     {title: '报工单号', dataIndex: 'noticeId', key: 'noticeId', width: MIDDLE_TABLE_WIDTH},
     {title: '物料名称', dataIndex: 'materialName', key: 'materialName', width: HUGE_TABLE_WIDTH},
     {title: '物料编号', dataIndex: 'wllbCode', key: 'wllbCode', width: MIDDLE_TABLE_WIDTH},
-    {title: '申请入库数量', dataIndex: 'num', key: 'num', width: SMALL_TABLE_WIDTH},
-    {
-      title: '已入库数量',
-      dataIndex: 'warehousingNum',
-      key: 'warehousingNum',
-      render(_, {warehousingNum}) {
-        return warehousingNum ?? '0';
-      },
-      width: SMALL_TABLE_WIDTH,
-    },
+    {title: '数量', dataIndex: 'num', key: 'num', width: SMALL_TABLE_WIDTH},
     {title: '生产批次', dataIndex: 'productionCode', key: 'productionCode', width: MIDDLE_TABLE_WIDTH},
     {title: '分录号', dataIndex: 'entryNumber', key: 'entryNumber', width: NORMAL_TABLE_WIDTH},
     {
@@ -75,15 +97,16 @@ export function useHandle() {
       key: 'id',
       width: SMALL_TABLE_WIDTH,
       fixed: 'right',
-      render(_, {id, type}) {
+      render(_, data) {
         return (
           <>
             <Button
               type='link'
-              disabled={type !== '0'}
-              onClick={onClick(id)}
+              disabled={data.type !== '0'}
+              onClick={onClick(data)}
+              loading={pendingId === data.id}
             >
-              {type === '0' ? '入库' : '已入库'}
+              {data.type === '0' ? '入库' : '已入库'}
             </Button>
 
           </>
@@ -92,5 +115,5 @@ export function useHandle() {
     },
   ];
 
-  return [{columns, visible, state}, {onClose}] as const;
+  return [{columns}] as const;
 }

+ 1 - 4
packages/app/src/pages/semi-report/table/index.tsx

@@ -3,11 +3,10 @@ import {useHandle, useList} from './hooks';
 import {Card} from 'antd';
 import {Table} from '@components';
 import {pageContext, searchContext} from '../context';
-import PutModal from './modal';
 
 const TableList: FC = function() {
   const [{data, count}, {refetch}] = useList();
-  const [{columns, visible, state}, {onClose}] = useHandle();
+  const [{columns}] = useHandle(refetch);
 
   return (
     <>
@@ -21,8 +20,6 @@ const TableList: FC = function() {
           count={count}
         />
       </Card>
-
-      <PutModal visible={visible} onClose={onClose} onFetch={refetch} id={state} />
     </>
   );
 };