Browse Source

chore: 半成品其他出库

xyh 2 years ago
parent
commit
ce8f90894d

+ 1 - 1
packages/app/src/apis/warehousing.ts

@@ -33,6 +33,6 @@ export function otherOut(data: OtherStockOutParams): BaseResult {
   return request({
     method: 'GET',
     data,
-    url: `${BASE_URL}/otherAskGoods`,
+    url: `/askGoods/otherAskGoods`,
   });
 }

+ 0 - 7
packages/app/src/pages/stock-in/index.module.css

@@ -1,10 +1,3 @@
-.card-wrapper {
-  & :global(.ant-card-head-title) {
-    font-size: 20px !important;
-    font-weight: normal !important;
-  }
-}
-
 .form {
   max-width: 600px;
   margin: 0 auto;

+ 1 - 2
packages/app/src/pages/stock-in/index.tsx

@@ -1,7 +1,6 @@
 import {Button, Card, Space} from 'antd';
 import {FC, useMemo} from 'react';
 import css from './index.module.css';
-import classNames from 'classnames';
 import {useFormState} from './hooks';
 import {FormField, FormSelect} from '@components';
 import {useDictionaryWidthCode, useMaterialOptions, useStorageOptions} from '@hooks';
@@ -33,7 +32,7 @@ const StockIn: FC = function () {
   );
 
   return (
-    <section className={classNames('content-main', css.cardWrapper)}>
+    <section className='content-main ant-card-title-reset'>
       <Card title='半成品其他入库'>
         <form className={css.form} onSubmit={onSubmit} onReset={onReset}>
           <Space direction='vertical' className='width-full'>

+ 84 - 0
packages/app/src/pages/stock-out/hooks.ts

@@ -0,0 +1,84 @@
+import {otherOut} from '@apis';
+import {yupResolver} from '@hookform/resolvers/yup';
+import {userStore} from '@stores';
+import {useMutation} from '@tanstack/react-query';
+import {message} from 'antd';
+import {FormEvent} from 'react';
+import {useForm} from 'react-hook-form';
+import {number, object, string} from 'yup';
+import {useStore} from 'zustand';
+
+type FormState = {
+  wllbCode: string;
+  storageLocationCode: string;
+  num: number;
+  wbs: string;
+  accountSleeve: string;
+  warehouse: string;
+};
+
+const validate = object({
+  wllbCode: string().required('请输入物料编号'),
+  warehouse: string().required('请选择出库仓库'),
+  storageLocationCode: string().required('请选择出库库位'),
+  wbs: string().required('请输入wbs编号'),
+  accountSleeve: string().required('请选择所属公司'),
+  num: number().typeError('请输入出库数量').min(1, '出库数量不能小于1个'),
+});
+
+export function useFormState() {
+  const {control, reset, handleSubmit, clearErrors, watch} = useForm<FormState>({
+    resolver: yupResolver(validate),
+    defaultValues: {
+      wllbCode: '',
+      storageLocationCode: '',
+      num: 1,
+      warehouse: '',
+      wbs: '',
+      accountSleeve: '',
+    },
+  });
+
+  function onReset(e: FormEvent) {
+    e.preventDefault();
+    reset();
+  }
+
+  const {mutate, isLoading} = useMutation({
+    mutationFn: otherOut,
+    onSuccess({msg}) {
+      if (msg === '200') {
+        reset();
+        clearErrors();
+        message.success('出库成功');
+      }
+    },
+  });
+
+  const {userId, department} = useStore(userStore, state => ({
+    userId: String(state.id),
+    department: state.department,
+  }));
+  const onSubmit = handleSubmit(function ({
+    wllbCode,
+    storageLocationCode,
+    num,
+    wbs,
+    accountSleeve,
+  }) {
+    mutate({
+      userId,
+      department,
+      wllbCode,
+      storageLocationCode,
+      num: String(num),
+      wbs,
+      accountSleeve,
+    });
+  });
+
+  return [
+    {isLoading, control},
+    {onSubmit, onReset, watch},
+  ] as const;
+}

+ 4 - 0
packages/app/src/pages/stock-out/index.module.css

@@ -0,0 +1,4 @@
+.form {
+  max-width: 600px;
+  margin: 0 auto;
+}

+ 88 - 0
packages/app/src/pages/stock-out/index.tsx

@@ -0,0 +1,88 @@
+import {Button, Card, Space} from 'antd';
+import {FC, useMemo} from 'react';
+import css from './index.module.css';
+import {FormField, FormSelect} from '@components';
+import {useFormState} from './hooks';
+import {useDictionaryWidthCode, useMaterialOptions, useStorageOptions} from '@hooks';
+
+const OtherStockOut: FC = function () {
+  const [{control, isLoading}, {onSubmit, onReset, watch}] = useFormState();
+  const {data: materialOptions, isFetching} = useMaterialOptions();
+  const [{data: warehouseOptions, isFetching: isWarehouseFetching}] = useDictionaryWidthCode(
+    '仓库',
+    {enabled: true},
+  );
+  const halfWarehouseOptions = useMemo(
+    function () {
+      return warehouseOptions.filter(val => val.type === '1');
+    },
+    [warehouseOptions],
+  );
+  const warehouseId = watch('warehouse');
+  const {data: locationOptions, isFetching: isLocationFetching} = useStorageOptions(
+    false,
+    state => state.storageLocationCode,
+    {
+      id: warehouseId,
+    },
+  );
+  const [{data: corporationOptions, isFetching: isCorporationFetching}] = useDictionaryWidthCode(
+    '公司',
+    {enabled: true, findValue: state => state.code},
+  );
+
+  return (
+    <section className='content-main ant-card-title-reset'>
+      <Card title='半成品其他出库'>
+        <form className={css.form} onSubmit={onSubmit} onReset={onReset}>
+          <Space direction='vertical' className='width-full'>
+            <FormSelect
+              loading={isFetching}
+              options={materialOptions}
+              control={control}
+              label='出库物料'
+              name='wllbCode'
+              showSearch
+              placeholder='请输入物料编号'
+            />
+            <FormSelect
+              loading={isWarehouseFetching}
+              options={halfWarehouseOptions}
+              control={control}
+              label='所属仓库'
+              name='warehouse'
+              showSearch
+            />
+            <FormSelect
+              loading={isLocationFetching}
+              options={locationOptions}
+              control={control}
+              label='所属库位'
+              name='storageLocationCode'
+              showSearch
+            />{' '}
+            <FormSelect
+              loading={isCorporationFetching}
+              options={corporationOptions}
+              control={control}
+              label='所属公司'
+              name='accountSleeve'
+            />
+            <FormField control={control} name='wbs' label='WBS编号' />
+            <FormField control={control} name='num' label='出库数量' type='number' />
+            <Space className='width-full' style={{justifyContent: 'flex-end'}}>
+              <Button htmlType='reset' disabled={isLoading}>
+                重置
+              </Button>
+              <Button htmlType='submit' type='primary' loading={isLoading}>
+                确认出库
+              </Button>
+            </Space>
+          </Space>
+        </form>
+      </Card>
+    </section>
+  );
+};
+
+export default OtherStockOut;

+ 3 - 0
packages/app/src/routes/index.tsx

@@ -38,6 +38,7 @@ import {
   INVENTORY_PATH,
   GS_ERROR_LOG_PATH,
   PUT_IN_STORAGE,
+  PUT_OUT_STORAGE,
 } from './name';
 import {
   Container,
@@ -76,6 +77,7 @@ import {
   Login,
   GSErrorLog,
   PutInStorageWithOther,
+  PutOutStorageWithOther,
 } from './routes';
 import Main from '@pages/main';
 import Home from '@pages/home';
@@ -120,6 +122,7 @@ export const routes: RouteObject[] = [
       {path: INVENTORY_PATH, element: <Inventory />},
       {path: GS_ERROR_LOG_PATH, element: <GSErrorLog />},
       {path: PUT_IN_STORAGE, element: <PutInStorageWithOther />},
+      {path: PUT_OUT_STORAGE, element: <PutOutStorageWithOther />},
     ],
   },
   {path: NO_PERMISSION_PATH, element: <NoPermision />},

+ 3 - 0
packages/app/src/routes/routes.tsx

@@ -190,3 +190,6 @@ export const GSErrorLog = lazy(
 export const PutInStorageWithOther = lazy(
   () => import(/* webpackChunkName: "putInStorageWithOther" */ '@pages/stock-in'),
 );
+export const PutOutStorageWithOther = lazy(
+  () => import(/** webpackChunkName: "putOutStorageWithOther" */ '@pages/stock-out'),
+);

+ 7 - 0
packages/app/src/styles/index.css

@@ -133,6 +133,13 @@ img {
 }
 
 /* antd ui调整 */
+.ant-card-title-reset {
+  & .ant-card-head-title {
+    font-size: 20px !important;
+    font-weight: normal !important;
+  }
+}
+
 .ant-table-thead th {
   text-align: center !important;
 }