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