|
@@ -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;
|
|
|
}
|