|
|
@@ -1,120 +0,0 @@
|
|
|
-import {getSemiManufacturesDrawInfo, semiManufacturesOut} from '@apis';
|
|
|
-import {yupResolver} from '@hookform/resolvers/yup';
|
|
|
-import {useQueryDataInfo} from '@hooks';
|
|
|
-import {SemiDrawListData} from '@models';
|
|
|
-import {userStore} from '@stores';
|
|
|
-import {useMutation, useQueryClient} from '@tanstack/react-query';
|
|
|
-import {message} from 'antd';
|
|
|
-import {useEffect} from 'react';
|
|
|
-import {useForm, useFormContext} from 'react-hook-form';
|
|
|
-import {number, object} from 'yup';
|
|
|
-import {useStore} from 'zustand';
|
|
|
-
|
|
|
-type FormState = {
|
|
|
- semiDrawNum: number;
|
|
|
-};
|
|
|
-
|
|
|
-const validate = object({
|
|
|
- semiDrawNum: number()
|
|
|
- .required('请输入出库数量')
|
|
|
- .typeError('请输入数字')
|
|
|
- .min(1, '不能小于1个'),
|
|
|
-});
|
|
|
-
|
|
|
-function useInfoData(id: string) {
|
|
|
- const client = useQueryClient();
|
|
|
-
|
|
|
- return function () {
|
|
|
- return client.getQueryData<SemiDrawListData>([
|
|
|
- getSemiManufacturesDrawInfo.name,
|
|
|
- id,
|
|
|
- ]);
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-function useMutationEvent(onClose: () => void, onFetch: () => void) {
|
|
|
- return useMutation({
|
|
|
- mutationFn: semiManufacturesOut,
|
|
|
- onSuccess({msg}) {
|
|
|
- if (msg === '200') {
|
|
|
- onClose();
|
|
|
- onFetch();
|
|
|
- message.success('出库成功');
|
|
|
- }
|
|
|
- },
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-export function useFormState({
|
|
|
- visible,
|
|
|
- id,
|
|
|
- onClose,
|
|
|
- onFetch,
|
|
|
-}: {
|
|
|
- visible: boolean;
|
|
|
- id: string;
|
|
|
- onClose: () => void;
|
|
|
- onFetch: () => void;
|
|
|
-}) {
|
|
|
- const formInstance = useForm<FormState>({
|
|
|
- defaultValues: {
|
|
|
- semiDrawNum: 0,
|
|
|
- },
|
|
|
- resolver: yupResolver(validate),
|
|
|
- });
|
|
|
-
|
|
|
- const {clearErrors, handleSubmit} = formInstance;
|
|
|
-
|
|
|
- useEffect(
|
|
|
- function () {
|
|
|
- visible && clearErrors();
|
|
|
- },
|
|
|
- [visible, clearErrors],
|
|
|
- );
|
|
|
-
|
|
|
- const getInfo = useInfoData(id);
|
|
|
- const {isLoading, mutate} = useMutationEvent(onClose, onFetch);
|
|
|
- const userId = useStore(userStore, state => String(state.id));
|
|
|
-
|
|
|
- const onSubmit = handleSubmit(function ({semiDrawNum}) {
|
|
|
- const info = getInfo();
|
|
|
-
|
|
|
- if (!info) message.error('未获取到信息');
|
|
|
- else {
|
|
|
- const {materialId, askGoodsId, materialCode, companyNumber, wbs} = info;
|
|
|
- // mutate({
|
|
|
- // materialId,
|
|
|
- // askGoodsId,
|
|
|
- // userId,
|
|
|
- // warehousingNum: String(semiDrawNum),
|
|
|
- // wllbCode: materialCode,
|
|
|
- // companyNumber,
|
|
|
- // wbs,
|
|
|
- // });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return [{formInstance, isLoading}, {onSubmit}] as const;
|
|
|
-}
|
|
|
-
|
|
|
-export function useControl() {
|
|
|
- const {control} = useFormContext<FormState>();
|
|
|
-
|
|
|
- return control;
|
|
|
-}
|
|
|
-
|
|
|
-export function useWatchId(id: string) {
|
|
|
- const data = useQueryDataInfo({
|
|
|
- queryFn: getSemiManufacturesDrawInfo,
|
|
|
- params: [id],
|
|
|
- enabled: Boolean(id),
|
|
|
- });
|
|
|
- const {setValue} = useFormContext<FormState>();
|
|
|
-
|
|
|
- useEffect(
|
|
|
- function () {
|
|
|
- setValue('semiDrawNum', Number(data?.num ?? '0'));
|
|
|
- },
|
|
|
- [data, setValue],
|
|
|
- );
|
|
|
-}
|