chenlei 1 день назад
Родитель
Сommit
7416165f81

+ 1 - 1
src/components/MyTable/form.tsx

@@ -230,7 +230,7 @@ const MyTable = forwardRef<MyTableMethods, MyTableProps>(
           },
           custom: (item: any) => {
             return (
-              <Form.Item noStyle name={`${item.id}-${v[2]}`}>
+              <Form.Item noStyle name={`${item.id}-${v[2]}`} initialValue={item[v[2]]}>
                 {v[3].render(readOnly)}
               </Form.Item>
             )

+ 125 - 94
src/pages/Fstorehouse/F1inStorage/F1edit/index.tsx

@@ -1,8 +1,9 @@
-import React, { useEffect, useMemo, useRef, useState } from 'react'
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
+import { useParams } from 'react-router-dom'
 import styles from './index.module.scss'
 import EditTop from '@/pages/Zother/EditTop'
 import EditBtn from '@/pages/Zother/EditBtn'
-import { InfoProvider } from '@/pages/Zother/InfoContext'
+import { InfoProvider, useInfo } from '@/pages/Zother/InfoContext'
 import { rowArrTemp } from '@/pages/Zother/data'
 import SonGoodsList from '@/pages/Zother/SonGoodsList'
 import {
@@ -17,7 +18,10 @@ import { selectObj } from '@/utils/dataChange'
 
 const rowArr = rowArrTemp('入库')
 
-function F1edit() {
+function F1editContent() {
+  const { info } = useInfo() as { info: any }
+  const { key } = useParams<any>()
+  const canEdit = useMemo(() => ['1', '2'].includes(key), [key])
   const sonGoodsListRef = useRef<any>(null)
   const [selectStorage, setSelectStorage] = useState<any>(null)
   const [allWarehouseList, setAllWarehouseList] = useState<any[]>([])
@@ -30,7 +34,7 @@ function F1edit() {
   }, [allWarehouseList])
   const [shelfList, setShelfList] = useState<any[]>([])
 
-  const handleStorageChange = async (value: string, option: any) => {
+  const handleStorageChange = useCallback(async (value: string, option: any) => {
     setSelectStorage(option)
     const res = await F1_APIgetShelfList({ storageId: value })
     setShelfList(
@@ -39,7 +43,7 @@ function F1edit() {
         value: i.id
       }))
     )
-  }
+  }, [])
 
   const handleAutoAssignShelf = async () => {
     const snaps = sonGoodsListRef.current?.snaps ?? []
@@ -53,19 +57,35 @@ function F1edit() {
     if (!form) return
     const values: Record<string, number | undefined> = {}
     snaps.forEach((snap: any, i: number) => {
-      values[`${snap.id}-storageInId`] = idList[i]?.id
+      values[`${snap.id}-siteId`] = idList[i]?.id
     })
     form.setFieldsValue(values)
   }
 
-  const getStorageList = async () => {
+  const getStorageList = useCallback(async () => {
     const res = await F1_APIgetStorageList()
     setAllWarehouseList(res.data.records)
-  }
+  }, [])
 
   useEffect(() => {
     getStorageList()
-  }, [])
+  }, [getStorageList])
+
+  useEffect(() => {
+    if (!info?.storageId || !allWarehouseList.length) return
+    const opt = warehouseOptions.find((o: any) => o.value === info.storageId)
+    if (opt && selectStorage?.value !== info.storageId) {
+      setSelectStorage(opt)
+      F1_APIgetShelfList({ storageId: info.storageId }).then(res => {
+        setShelfList(
+          res.data.map((i: any) => ({
+            label: [i.layer1, i.layer2, i.layer3, i.layer4].filter(i => Boolean(i)).join('-'),
+            value: i.id
+          }))
+        )
+      })
+    }
+  }, [info?.storageId, allWarehouseList.length, warehouseOptions, selectStorage?.value])
 
   const verifyBackFu = (info: any) => {
     if (!selectStorage) return { flag: true, txt: '请选择入库库房' }
@@ -73,7 +93,7 @@ function F1edit() {
     if (!form) return { flag: true, txt: '请添加藏品' }
     const values = form.getFieldsValue()
     const snaps = sonGoodsListRef.current?.snaps ?? []
-    const hasEmptyStorage = snaps.some((snap: any) => !values[`${snap.id}-storageInId`])
+    const hasEmptyStorage = snaps.some((snap: any) => !values[`${snap.id}-siteId`])
     if (hasEmptyStorage) return { flag: true, txt: '请为藏品选择库房位置' }
     return { flag: false, txt: '' }
   }
@@ -83,8 +103,8 @@ function F1edit() {
     const values = form?.getFieldsValue() ?? {}
     const snapsArr = snaps.map((v: any) => {
       const flag = v.pageType === 'clue' && !v.clueId
-      const storageInId = values[`${v.id}-storageInId`] ?? null
-      const siteLoc = shelfList.find((s: any) => s.value === storageInId)?.label ?? null
+      const siteId = values[`${v.id}-siteId`] ?? null
+      const siteLoc = shelfList.find((s: any) => s.value === siteId)?.label ?? null
       return {
         goodId: v.isNew || flag ? null : v.id,
         orderId: info.id,
@@ -93,7 +113,7 @@ function F1edit() {
           ...v,
           id: v.isNew || flag ? null : v.id,
           siteLoc,
-          siteId: storageInId
+          siteId
         })
       }
     })
@@ -104,92 +124,103 @@ function F1edit() {
   }
 
   return (
-    <InfoProvider>
-      <div className={styles.F1edit} id='editBox'>
-        <div className='editMain'>
-          {/* 顶部 */}
-          {/* TODO: 借展归还待完善 */}
-          <EditTop
-            pageTxt='藏品入库'
-            rowArr={rowArr}
-            APIobj={F1API_obj}
-            fileUpInfo={{ myUrl: 'cms/orderSite/in/upload', dirCode: 'inStorage' }}
-          />
+    <div className={styles.F1edit} id='editBox'>
+      <div className='editMain'>
+        <div className='F1editStorage'>
+          <p className='F1editStorageTitle'>审批信息</p>
+        </div>
 
-          <div className='F1editStorage'>
-            <p className='F1editStorageTitle'>*入库库房</p>
-            <Select
-              style={{ width: 200 }}
-              options={warehouseOptions}
-              placeholder='请选择'
-              value={selectStorage?.value}
-              onChange={handleStorageChange}
-            />
-            {selectStorage?.managerUser && (
-              <p className='F1editStorageManager'>库房负责人:{selectStorage.managerUser}</p>
-            )}
-          </div>
-
-          {/* 藏品清单 */}
-          <SonGoodsList
-            ref={sonGoodsListRef}
-            needEdit={true}
-            btnTxt='选择藏品'
-            addShow={false}
-            customRightBtn={
-              <Button
-                disabled={!selectStorage?.value}
-                type='primary'
-                ghost
-                onClick={handleAutoAssignShelf}
-              >
-                自动分配空置位置
-              </Button>
-            }
-            goodsSonTable={[
-              ['txt', '藏品登记号', 'num'],
-              ['img', '封面', 'thumb'],
-              ['txtCTag', '藏品标签', 'tagDictId'],
-              ['txt', '藏品名称', 'name'],
-              ['select', '级别', 'level', selectObj['藏品级别']],
-              ['txtC', '类别', 'typeDictId'],
-              ['txtC', '年代', 'ageDictId'],
-              ['txtC', '质地', 'textureDictId'],
-              ['select', '完残程度', 'tornLevel', selectObj['完残程度']],
-              ['ping', '数量', 'pcs', 'pcsUnitDictId'],
-              [
-                'custom',
-                '库房位置',
-                'storageInId',
-                {
-                  render(readOnly?: boolean) {
-                    return (
-                      <Select
-                        allowClear
-                        options={shelfList}
-                        disabled={readOnly}
-                        placeholder='请选择'
-                      />
-                    )
-                  }
-                }
-              ]
-            ]}
-            fileUpInfo={{ myUrl: 'cms/orderSite/in/upload', dirCode: 'inStorageGoods' }}
-            selectApi={F1_APIgetClueList}
-            isClueSelect={false}
-          />
+        {/* 顶部 */}
+        {/* TODO: 借展归还待完善 */}
+        <EditTop
+          pageTxt='藏品入库'
+          rowArr={rowArr}
+          APIobj={F1API_obj}
+          fileUpInfo={{ myUrl: 'cms/orderSite/in/upload', dirCode: 'inStorage' }}
+        />
 
-          {/* 底部按钮 */}
-          <EditBtn
-            path='/inStorage'
-            APIobj={F1API_obj}
-            checkListTxt='请添加藏品'
-            verifyBackFu={verifyBackFu}
-            getExtraData={getExtraData}
+        <div className='F1editStorage'>
+          <p className='F1editStorageTitle'>*入库库房</p>
+          <Select
+            style={{ width: 200 }}
+            options={warehouseOptions}
+            placeholder='请选择'
+            value={selectStorage?.value}
+            onChange={handleStorageChange}
+            disabled={!canEdit}
           />
+          {selectStorage?.managerUser && (
+            <p className='F1editStorageManager'>库房负责人:{selectStorage.managerUser}</p>
+          )}
         </div>
+
+        {/* 藏品清单 */}
+        <SonGoodsList
+          ref={sonGoodsListRef}
+          needEdit={true}
+          btnTxt='选择藏品'
+          addShow={false}
+          customRightBtn={
+            <Button
+              disabled={!selectStorage?.value || !canEdit}
+              type='primary'
+              ghost
+              onClick={handleAutoAssignShelf}
+            >
+              自动分配空置位置
+            </Button>
+          }
+          goodsSonTable={[
+            ['txt', '藏品登记号', 'num'],
+            ['img', '封面', 'thumb'],
+            ['txtCTag', '藏品标签', 'tagDictId'],
+            ['txt', '藏品名称', 'name'],
+            ['select', '级别', 'level', selectObj['藏品级别']],
+            ['txtC', '类别', 'typeDictId'],
+            ['txtC', '年代', 'ageDictId'],
+            ['txtC', '质地', 'textureDictId'],
+            ['select', '完残程度', 'tornLevel', selectObj['完残程度']],
+            ['ping', '数量', 'pcs', 'pcsUnitDictId'],
+            [
+              'custom',
+              '库房位置',
+              'siteId',
+              {
+                render(_readOnly?: boolean) {
+                  return (
+                    <Select
+                      allowClear
+                      options={shelfList}
+                      disabled={!canEdit}
+                      placeholder='请选择'
+                    />
+                  )
+                }
+              }
+            ]
+          ]}
+          fileUpInfo={{ myUrl: 'cms/orderSite/in/upload', dirCode: 'inStorageGoods' }}
+          selectApi={F1_APIgetClueList}
+          isClueSelect={false}
+        />
+
+        {/* 底部按钮 */}
+        <EditBtn
+          path='/inStorage'
+          APIobj={F1API_obj}
+          checkListTxt='请添加藏品'
+          verifyBackFu={verifyBackFu}
+          getExtraData={getExtraData}
+        />
       </div>
+    </div>
+  )
+}
+
+function F1edit() {
+  return (
+    <InfoProvider>
+      <F1editContent />
     </InfoProvider>
   )
 }

+ 18 - 3
src/pages/Fstorehouse/F1inStorage/index.tsx

@@ -1,4 +1,4 @@
-import React, { useEffect, useMemo, useRef, useState } from 'react'
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
 import styles from './index.module.scss'
 import TableList from '@/pages/Zother/TableList'
 import { baseFormData } from '@/pages/Zother/data'
@@ -9,6 +9,7 @@ import { Button } from 'antd'
 import { inStorageTableC } from '@/utils/tableData'
 import { selectObj } from '@/utils/dataChange'
 import { useHistory } from 'react-router-dom'
+import { tableListAuditBtnFu } from '@/utils/authority'
 
 const F1baseFormData = baseFormData()
 
@@ -34,6 +35,13 @@ function F1inStorage() {
     setAllWarehouseList(res.data.records)
   }
 
+  const tableBtnFu = useCallback(
+    (id: number | null, key: string) => {
+      history.push(`/inStorage_edit/${key}/${id}`)
+    },
+    [history]
+  )
+
   useEffect(() => {
     getStorageList()
   }, [])
@@ -82,7 +90,7 @@ function F1inStorage() {
         ]}
         storyTableListToprr={({ clickSearch, resetSelectFu }) => (
           <>
-            <Button type='primary' ghost onClick={() => history.push('/inStorage_edit/1/null')}>
+            <Button type='primary' ghost onClick={() => tableBtnFu(null, '1')}>
               发起申请
             </Button>
             <Button type='primary' onClick={dataExport}>
@@ -99,7 +107,14 @@ function F1inStorage() {
             title: '操作',
             render: (item: any) => (
               <>
-                <Button type='text'>查看</Button>
+                <Button type='text' onClick={() => tableBtnFu(item.id, '4')}>
+                  查看
+                </Button>
+                {tableListAuditBtnFu(item) ? (
+                  <Button size='small' type='text' onClick={() => tableBtnFu(item.id, '3')}>
+                    审批
+                  </Button>
+                ) : null}
               </>
             )
           }

+ 1 - 1
src/pages/Zother/EditBtn/index.tsx

@@ -22,7 +22,7 @@ type Props = {
   verifyArr?: { key: string; txt: string }[]
   // 其他需要校验的回调函数,返回 flag为true 表示校验不通过,txt为提示语
   verifyBackFu?: (info: Typetable) => { flag: boolean; txt: string; info?: any }
-  // 页面特有数据,如 storageId、带 storageInId 的 snaps 等,会合并到提交的 obj 中
+  // 页面特有数据,如 storageId,会合并到提交的 obj 中
   getExtraData?: (info: Typetable, snaps: GoodsType[]) => { storageId?: number; snaps?: any[] }
   // 第二个模块
   isTow?: boolean

+ 4 - 0
src/pages/Zother/EditTop/index.tsx

@@ -91,6 +91,10 @@ function EditTop({ rowArr, pageTxt, APIobj, fileUpInfo, moreDom }: Props) {
 
           obj.idTemp = obj.id
 
+          if (v.siteId != null) {
+            obj.siteId = v.siteId ?? obj.siteId
+          }
+
           arrTemp.push(obj)
 
           // 第二个模块的信息回显

+ 1 - 1
src/utils/tableData.ts

@@ -158,7 +158,7 @@ export const goodsFileTableC = [
 // 藏品入库
 export const inStorageTableC = [
   ['txt', '入库日期', 'createTime'],
-  ['txt', '入库库房', 'tagName'],
+  ['txt', '入库库房', 'storageName'],
   ['txt', '申请编号', 'num'],
   ['txt', '发起部门', 'deptName'],
   ['txt', '发起人', 'creatorName'],