|
|
@@ -15,6 +15,7 @@ import { API_getGoodsInfo } from '@/store/action/Cledger/C1ledger'
|
|
|
import { MessageFu } from '@/utils/message'
|
|
|
import { API_getFileListByIds } from '@/store/action/Cledger/C4file'
|
|
|
import { FileUpInfoType } from '../data'
|
|
|
+import { useInfo } from '../InfoContext'
|
|
|
|
|
|
// 级联的数据转换成字符串
|
|
|
export const cascaderChArr = [
|
|
|
@@ -49,6 +50,8 @@ type Props = {
|
|
|
}
|
|
|
|
|
|
function AddGoods({ closeFu, succFu, isEdit, moduleId, info, APIsave, fileUpInfo }: Props) {
|
|
|
+ const { delSnapIdsRef } = useInfo()
|
|
|
+
|
|
|
// 获取标签 树结构
|
|
|
const E1tree = useSelector((state: RootState) => state.E1tag.treeData)
|
|
|
|
|
|
@@ -64,41 +67,51 @@ function AddGoods({ closeFu, succFu, isEdit, moduleId, info, APIsave, fileUpInfo
|
|
|
// 藏品编辑模块用来对比
|
|
|
const objOld = useRef({} as GoodsType)
|
|
|
|
|
|
- // 编辑进来获取详情
|
|
|
- const getInfo = useCallback(async (id: number) => {
|
|
|
- const res = await API_getGoodsInfo(id)
|
|
|
- if (res.code === 0) {
|
|
|
- // 藏品编辑信息保存
|
|
|
- objOld.current = { ...res.data }
|
|
|
+ const resInfoFu = useCallback(async (infoRes: GoodsType) => {
|
|
|
+ // 藏品编辑信息保存
|
|
|
+ objOld.current = { ...infoRes }
|
|
|
|
|
|
- const obj = { ...res.data }
|
|
|
- // makeDate inGoodYear 2个日期需要格式处理一下
|
|
|
- if (obj.makeDate) obj.makeDate = dayjs(obj.makeDate)
|
|
|
- if (obj.inGoodYear) obj.inGoodYear = dayjs(obj.inGoodYear)
|
|
|
+ const obj: any = { ...infoRes }
|
|
|
+ // makeDate inGoodYear 2个日期需要格式处理一下
|
|
|
+ if (obj.makeDate) obj.makeDate = dayjs(obj.makeDate)
|
|
|
+ if (obj.inGoodYear) obj.inGoodYear = dayjs(obj.inGoodYear)
|
|
|
|
|
|
- cascaderChArr.forEach(v => {
|
|
|
- if (obj[v] === '0') obj[v] = null
|
|
|
- else if (obj[v]) {
|
|
|
- obj[v] = obj[v].split(',')
|
|
|
- }
|
|
|
- })
|
|
|
+ cascaderChArr.forEach(v => {
|
|
|
+ if (obj[v] === '0') obj[v] = null
|
|
|
+ else if (obj[v]) {
|
|
|
+ obj[v] = obj[v].split(',')
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
- addZiSelectChArr.forEach(v => {
|
|
|
- if (!obj[v]) obj[v] = null
|
|
|
- })
|
|
|
+ addZiSelectChArr.forEach(v => {
|
|
|
+ if (!obj[v]) obj[v] = null
|
|
|
+ })
|
|
|
|
|
|
- FormBoxRef.current?.setFieldsValue(obj)
|
|
|
+ FormBoxRef.current?.setFieldsValue(obj)
|
|
|
|
|
|
- // 设置附件
|
|
|
- if (obj.fileIds) {
|
|
|
- const fileRes = await API_getFileListByIds(obj.fileIds.split(','))
|
|
|
- if (fileRes.code === 0) {
|
|
|
- fileRef.current?.sonSetListFu(fileRes.data || [])
|
|
|
- }
|
|
|
+ // 设置附件
|
|
|
+ if (obj.fileIds) {
|
|
|
+ const fileRes = await API_getFileListByIds(obj.fileIds.split(','))
|
|
|
+ if (fileRes.code === 0) {
|
|
|
+ fileRef.current?.sonSetListFu(fileRes.data || [])
|
|
|
}
|
|
|
}
|
|
|
}, [])
|
|
|
|
|
|
+ // 编辑进来获取详情
|
|
|
+ const getInfo = useCallback(
|
|
|
+ async (id: number) => {
|
|
|
+ if (info.pageType === 'clue') {
|
|
|
+ // 从征集进来 不用拿详情
|
|
|
+ resInfoFu(info)
|
|
|
+ } else {
|
|
|
+ const res = await API_getGoodsInfo(id)
|
|
|
+ if (res.code === 0) resInfoFu(res.data)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [info, resInfoFu]
|
|
|
+ )
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (info.id > 0) getInfo(info.id)
|
|
|
}, [getInfo, info.id])
|
|
|
@@ -121,7 +134,7 @@ function AddGoods({ closeFu, succFu, isEdit, moduleId, info, APIsave, fileUpInfo
|
|
|
|
|
|
const obj = {
|
|
|
...values,
|
|
|
- id: info.id > 0 ? info.id : null,
|
|
|
+ id: info.pageType === 'clue' ? null : info.id > 0 ? info.id : null,
|
|
|
makeDate,
|
|
|
inGoodYear,
|
|
|
fileIds: flieList.map((v: any) => v.id).join(','),
|
|
|
@@ -145,11 +158,22 @@ function AddGoods({ closeFu, succFu, isEdit, moduleId, info, APIsave, fileUpInfo
|
|
|
const res = await APIsave(obj)
|
|
|
if (res.code === 0) {
|
|
|
MessageFu.success(info.id > 0 ? '编辑成功' : '新增成功')
|
|
|
- succFu(info.id > 0 ? '编辑' : '新增', res.data)
|
|
|
+ // if (1 + 1 === 2) {
|
|
|
+ // console.log('----------------', info)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+
|
|
|
+ const resObj = { ...res.data }
|
|
|
+ if (info.pageType === 'clue') {
|
|
|
+ resObj.clueId = info.id
|
|
|
+ if (info.id2) delSnapIdsRef.current.push(info.id2)
|
|
|
+ }
|
|
|
+
|
|
|
+ succFu(info.id > 0 ? '编辑' : '新增', resObj)
|
|
|
closeFu()
|
|
|
}
|
|
|
},
|
|
|
- [APIsave, closeFu, info.id, succFu]
|
|
|
+ [APIsave, closeFu, delSnapIdsRef, info, succFu]
|
|
|
)
|
|
|
|
|
|
return (
|