|
|
@@ -0,0 +1,253 @@
|
|
|
+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, useInfo } from '@/pages/Zother/InfoContext'
|
|
|
+import { rowArrTemp } from '@/pages/Zother/data'
|
|
|
+import SonGoodsList from '@/pages/Zother/SonGoodsList'
|
|
|
+import { Button, Select } from 'antd'
|
|
|
+import { selectObj } from '@/utils/dataChange'
|
|
|
+import FileArchive from '@/pages/Zother/FileArchive'
|
|
|
+import { F1_APIgetShelfList, F1_APIgetStorageList } from '@/store/action/Fstorehouse/F1inStorage'
|
|
|
+import {
|
|
|
+ F2_APIgetClueList,
|
|
|
+ F2_APIgetShelfEmptyList,
|
|
|
+ F2API_obj
|
|
|
+} from '@/store/action/Fstorehouse/F2moveStorage'
|
|
|
+
|
|
|
+const rowArr = rowArrTemp('移库')
|
|
|
+
|
|
|
+function F2editContent() {
|
|
|
+ const { info } = useInfo() as { info: any }
|
|
|
+ const { key } = useParams<any>()
|
|
|
+ const canEdit = useMemo(() => ['1', '2'].includes(key), [key])
|
|
|
+ const sonGoodsListRef = useRef<any>(null)
|
|
|
+ const [outStorage, setoutStorage] = useState<any>(null)
|
|
|
+ const [inStorage, setinStorage] = useState<any>(null)
|
|
|
+ const [allWarehouseList, setAllWarehouseList] = useState<any[]>([])
|
|
|
+ const warehouseOptions = useMemo(() => {
|
|
|
+ return allWarehouseList.map((i: any) => ({
|
|
|
+ label: i.name,
|
|
|
+ value: i.id,
|
|
|
+ managerUser: i.managerUser
|
|
|
+ }))
|
|
|
+ }, [allWarehouseList])
|
|
|
+ const [shelfList, setShelfList] = useState<any[]>([])
|
|
|
+
|
|
|
+ const handleOutStorageChange = useCallback(async (value: string, option: any) => {
|
|
|
+ setoutStorage(option)
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ const handleInStorageChange = useCallback(async (value: string, option: any) => {
|
|
|
+ setinStorage(option)
|
|
|
+ const res = await F1_APIgetShelfList({ storageId: value })
|
|
|
+ setShelfList(
|
|
|
+ res.data.map((i: any) => ({
|
|
|
+ label: [i.layer1, i.layer2, i.layer3, i.layer4].filter(i => Boolean(i)).join('-'),
|
|
|
+ value: i.id
|
|
|
+ }))
|
|
|
+ )
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ const handleAutoAssignShelf = async () => {
|
|
|
+ const snaps = sonGoodsListRef.current?.snaps ?? []
|
|
|
+ if (!snaps.length) return
|
|
|
+ const res = await F2_APIgetShelfEmptyList({
|
|
|
+ storageId: outStorage?.value,
|
|
|
+ limit: snaps.length
|
|
|
+ })
|
|
|
+ const idList: { id: number }[] = Array.isArray(res) ? res : (res?.data ?? [])
|
|
|
+ const form = sonGoodsListRef.current?.tableRef?.current?.form
|
|
|
+ if (!form) return
|
|
|
+ const values: Record<string, number | undefined> = {}
|
|
|
+ snaps.forEach((snap: any, i: number) => {
|
|
|
+ values[`${snap.id}-storageInId`] = idList[i]?.id
|
|
|
+ })
|
|
|
+ form.setFieldsValue(values)
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ const outOpt = warehouseOptions.find((o: any) => o.value === info.snaps[0]?.storageOutId)
|
|
|
+ if (opt && outOpt) {
|
|
|
+ setoutStorage(outOpt)
|
|
|
+ setinStorage(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, info?.snaps])
|
|
|
+
|
|
|
+ const verifyBackFu = (info: any) => {
|
|
|
+ if (!outStorage) return { flag: true, txt: '请选择入库库房' }
|
|
|
+ const form = sonGoodsListRef.current?.tableRef?.current?.form
|
|
|
+ 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`])
|
|
|
+ if (hasEmptyStorage) return { flag: true, txt: '请为藏品选择库房位置' }
|
|
|
+ return { flag: false, txt: '' }
|
|
|
+ }
|
|
|
+
|
|
|
+ const getExtraData = (info: any, snaps: any[]) => {
|
|
|
+ const form = sonGoodsListRef.current?.tableRef?.current?.form
|
|
|
+ const values = form?.getFieldsValue() ?? {}
|
|
|
+ const snapsArr = snaps.map((v: any) => {
|
|
|
+ const flag = v.pageType === 'clue' && !v.clueId
|
|
|
+ const siteId = values[`${v.id}-storageInId`] ?? null
|
|
|
+ const siteLoc = shelfList.find((s: any) => s.value === siteId)?.label ?? null
|
|
|
+ return {
|
|
|
+ goodId: v.isNew || flag ? null : v.id,
|
|
|
+ orderId: info.id,
|
|
|
+ storageOutId: outStorage?.value ?? null,
|
|
|
+ storageInId: inStorage?.value ?? null,
|
|
|
+ snap: JSON.stringify({
|
|
|
+ ...v,
|
|
|
+ id: v.isNew || flag ? null : v.id,
|
|
|
+ siteLoc,
|
|
|
+ siteId,
|
|
|
+ storageInId: siteId
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return {
|
|
|
+ storageId: inStorage?.value ?? undefined,
|
|
|
+ extraInfo:
|
|
|
+ inStorage?.value === outStorage?.value
|
|
|
+ ? inStorage.label
|
|
|
+ : `${outStorage.label} -> ${inStorage.label}`,
|
|
|
+ snaps: snapsArr
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.F2edit} id='editBox'>
|
|
|
+ <div className='editMain'>
|
|
|
+ {/* 顶部 */}
|
|
|
+ {/* TODO: 借展归还待完善 */}
|
|
|
+ <EditTop
|
|
|
+ pageTxt='申请信息'
|
|
|
+ rowArr={rowArr}
|
|
|
+ APIobj={F2API_obj}
|
|
|
+ fileUpInfo={{ myUrl: 'cms/orderSite/move/upload', dirCode: 'moveStorage' }}
|
|
|
+ />
|
|
|
+
|
|
|
+ <div className='F2editStorage'>
|
|
|
+ <p className='F2editStorageTitle'>*移出库房</p>
|
|
|
+ <Select
|
|
|
+ style={{ width: 200 }}
|
|
|
+ options={warehouseOptions}
|
|
|
+ placeholder='请选择'
|
|
|
+ value={outStorage?.value}
|
|
|
+ onChange={handleOutStorageChange}
|
|
|
+ disabled={!canEdit}
|
|
|
+ />
|
|
|
+
|
|
|
+ <p className='F2editStorageTitle'>*移入库房</p>
|
|
|
+ <Select
|
|
|
+ style={{ width: 200 }}
|
|
|
+ options={warehouseOptions}
|
|
|
+ placeholder='请选择'
|
|
|
+ value={inStorage?.value}
|
|
|
+ onChange={handleInStorageChange}
|
|
|
+ disabled={!canEdit}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 藏品清单 */}
|
|
|
+ <SonGoodsList
|
|
|
+ ref={sonGoodsListRef}
|
|
|
+ needEdit={true}
|
|
|
+ btnTxt='选择藏品'
|
|
|
+ addShow={false}
|
|
|
+ customRightBtn={
|
|
|
+ <Button
|
|
|
+ disabled={!inStorage?.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',
|
|
|
+ '移入位置',
|
|
|
+ 'storageInId',
|
|
|
+ {
|
|
|
+ render(_readOnly?: boolean) {
|
|
|
+ return (
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ options={shelfList}
|
|
|
+ disabled={!canEdit}
|
|
|
+ placeholder='请选择'
|
|
|
+ />
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ ]}
|
|
|
+ fileUpInfo={{ myUrl: 'cms/orderSite/in/upload', dirCode: 'inStorageGoods' }}
|
|
|
+ selectApi={F2_APIgetClueList}
|
|
|
+ isClueSelect={false}
|
|
|
+ clueShowBtnDisabled={!outStorage?.value}
|
|
|
+ selectGoodsParams={{
|
|
|
+ storageId: outStorage?.value
|
|
|
+ }}
|
|
|
+ />
|
|
|
+
|
|
|
+ {/* 附件归档 */}
|
|
|
+ <FileArchive />
|
|
|
+
|
|
|
+ {/* 底部按钮 */}
|
|
|
+ <EditBtn
|
|
|
+ path='/moveStorage'
|
|
|
+ APIobj={F2API_obj}
|
|
|
+ checkListTxt='请添加藏品'
|
|
|
+ verifyBackFu={verifyBackFu}
|
|
|
+ getExtraData={getExtraData}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+function F2edit() {
|
|
|
+ return (
|
|
|
+ <InfoProvider>
|
|
|
+ <F2editContent />
|
|
|
+ </InfoProvider>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const MemoF2edit = React.memo(F2edit)
|
|
|
+
|
|
|
+export default MemoF2edit
|