|
@@ -11,9 +11,23 @@ import MyTable from '@/components/MyTable'
|
|
|
import { B1TableC2up } from '@/utils/tableData'
|
|
|
import { B1X_APIadds } from '@/store/action/B1collect'
|
|
|
import { forwardRef, useImperativeHandle } from 'react'
|
|
|
-
|
|
|
-// 删掉前面2个
|
|
|
-const arrTemp = ['dictAge', 'dictAgeFirst', 'dictType', 'source']
|
|
|
+import { A3m_APIaddGoods_2, A3m_APIaddZip } from '@/store/action/A3machineReg'
|
|
|
+
|
|
|
+// 删掉前面2个 0,10000,12008,12563 == 12008,12563
|
|
|
+const arrTemp = [
|
|
|
+ 'dictAge',
|
|
|
+ 'dictAgeFirst',
|
|
|
+ 'dictType',
|
|
|
+ 'source',
|
|
|
+ 'dictTexture1',
|
|
|
+ 'dictTexture2',
|
|
|
+ 'dictTexture3',
|
|
|
+ 'inDictDateScope',
|
|
|
+ 'qualityDictScope',
|
|
|
+ 'qualityUnit',
|
|
|
+ 'dictTorn',
|
|
|
+ 'preserveState'
|
|
|
+]
|
|
|
|
|
|
type Props = {
|
|
|
closeFu: () => void
|
|
@@ -22,9 +36,14 @@ type Props = {
|
|
|
clickSuccFu: (arr: B1Xtype[]) => void
|
|
|
isZongZhang?: boolean
|
|
|
ref: any //当前自己的ref,给父组件调用
|
|
|
+ url: string
|
|
|
+ pageType: '藏品总账' | '藏品征集'
|
|
|
}
|
|
|
|
|
|
-function B1upXLSX({ closeFu, infoXLSX, clickSuccFu, upSuccFu, isZongZhang }: Props, ref: any) {
|
|
|
+function B1upXLSX(
|
|
|
+ { closeFu, infoXLSX, clickSuccFu, upSuccFu, isZongZhang, url, pageType }: Props,
|
|
|
+ ref: any
|
|
|
+) {
|
|
|
// 藏品总账导入的类型 一普 和省平台
|
|
|
const zongZhnagType = useRef('')
|
|
|
|
|
@@ -55,11 +74,16 @@ function B1upXLSX({ closeFu, infoXLSX, clickSuccFu, upSuccFu, isZongZhang }: Pro
|
|
|
e.target.value = ''
|
|
|
|
|
|
try {
|
|
|
- const res = await API_upFile(fd, 'cms/orderCollect/uploadZj')
|
|
|
+ const res = await API_upFile(fd, url)
|
|
|
|
|
|
if (res.code === 0) {
|
|
|
MessageFu.success('上传成功!')
|
|
|
- const arrAll: any[] = res.data || []
|
|
|
+ const arrAll: any[] = (pageType === '藏品总账' ? res.data.excel : res.data) || []
|
|
|
+
|
|
|
+ if (pageType === '藏品总账') {
|
|
|
+ fileInfo.current = { fileName: res.data.fileName, filePath: res.data.filePath }
|
|
|
+ }
|
|
|
+
|
|
|
const succArr: B1Xtype[] = []
|
|
|
const errArr: B1Xtype[] = []
|
|
|
|
|
@@ -84,34 +108,71 @@ function B1upXLSX({ closeFu, infoXLSX, clickSuccFu, upSuccFu, isZongZhang }: Pro
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- [upSuccFu]
|
|
|
+ [pageType, upSuccFu, url]
|
|
|
)
|
|
|
|
|
|
const [btnAc, setBtnAc] = useState('成功')
|
|
|
|
|
|
+ // 藏品总账才有的 附件名和附件路径
|
|
|
+ const fileInfo = useRef({ fileName: '', filePath: '' })
|
|
|
+
|
|
|
// 点击导入当前数据
|
|
|
const btnOk = useCallback(async () => {
|
|
|
- const res = await B1X_APIadds(
|
|
|
- infoXLSX.succ.map(v => ({
|
|
|
- ...v,
|
|
|
- id: null
|
|
|
- }))
|
|
|
- )
|
|
|
- if (res.code === 0) {
|
|
|
- MessageFu.success('导入成功')
|
|
|
- clickSuccFu(res.data)
|
|
|
- closeFu()
|
|
|
+ if (pageType === '藏品征集') {
|
|
|
+ const res = await B1X_APIadds(
|
|
|
+ infoXLSX.succ.map(v => ({
|
|
|
+ ...v,
|
|
|
+ id: null
|
|
|
+ }))
|
|
|
+ )
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success('导入成功')
|
|
|
+ clickSuccFu(res.data)
|
|
|
+ closeFu()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const obj = {
|
|
|
+ fileName: fileInfo.current.fileName,
|
|
|
+ filePath: fileInfo.current.filePath,
|
|
|
+ pcsError: infoXLSX.err.length,
|
|
|
+ pcsSuccess: infoXLSX.succ.length,
|
|
|
+ pcsTotal: infoXLSX.err.length + infoXLSX.succ.length,
|
|
|
+ type: zongZhnagType.current
|
|
|
+ }
|
|
|
+
|
|
|
+ const res1 = await A3m_APIaddZip(obj)
|
|
|
+
|
|
|
+ if (res1.code === 0) {
|
|
|
+ const obj2 = [...infoXLSX.succ, ...infoXLSX.err].map(v => ({
|
|
|
+ ...v,
|
|
|
+ id: null,
|
|
|
+ importId: res1.data.id,
|
|
|
+ importDesc: JSON.stringify(v.error || '[]'),
|
|
|
+ importError: v.isTrue === 1 ? '0' : '1'
|
|
|
+ // importRow: v.row
|
|
|
+ }))
|
|
|
+
|
|
|
+ const res2 = await A3m_APIaddGoods_2(obj2)
|
|
|
+
|
|
|
+ if (res2.code === 0) {
|
|
|
+ MessageFu.success('导入成功')
|
|
|
+ clickSuccFu(res2.data)
|
|
|
+ closeFu()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }, [clickSuccFu, closeFu, infoXLSX.succ])
|
|
|
+ }, [clickSuccFu, closeFu, infoXLSX, pageType])
|
|
|
|
|
|
// 让父组件调用
|
|
|
const openUpFu = useCallback((val: string) => {
|
|
|
- console.log(123, val)
|
|
|
+ // console.log(123, val)
|
|
|
zongZhnagType.current = val
|
|
|
|
|
|
- // upBiaoGeRef.current?.click()
|
|
|
+ upBiaoGeRef.current?.click()
|
|
|
}, [])
|
|
|
|
|
|
+ // 藏品总账点击查看
|
|
|
+
|
|
|
// 可以让父组件调用子组件的方法
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
openUpFu
|
|
@@ -160,21 +221,27 @@ function B1upXLSX({ closeFu, infoXLSX, clickSuccFu, upSuccFu, isZongZhang }: Pro
|
|
|
classKey='B1upXLSX'
|
|
|
yHeight={500}
|
|
|
list={btnAc === '成功' ? infoXLSX.succ : infoXLSX.err}
|
|
|
- columnsTemp={B1TableC2up(btnAc)}
|
|
|
+ columnsTemp={B1TableC2up(btnAc, pageType === '藏品总账')}
|
|
|
lastBtn={[]}
|
|
|
pagingInfo={false}
|
|
|
/>
|
|
|
|
|
|
<div className='B1XLbtn'>
|
|
|
- <Button type='primary' onClick={() => upBiaoGeRef.current?.click()}>
|
|
|
- 重新上传表格
|
|
|
- </Button>
|
|
|
-  
|
|
|
- <Button type='primary' disabled={infoXLSX.succ.length === 0} onClick={btnOk}>
|
|
|
- 导入当前数据
|
|
|
- </Button>
|
|
|
-  
|
|
|
- <MyPopconfirm txtK='取消' onConfirm={closeFu} Dom={<Button>取消导入</Button>} />
|
|
|
+ {infoXLSX.type === '查看' ? (
|
|
|
+ <Button onClick={closeFu}>关闭</Button>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Button type='primary' onClick={() => upBiaoGeRef.current?.click()}>
|
|
|
+ 重新上传表格
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Button type='primary' disabled={infoXLSX.succ.length === 0} onClick={btnOk}>
|
|
|
+ 导入当前数据
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <MyPopconfirm txtK='取消' onConfirm={closeFu} Dom={<Button>取消导入</Button>} />
|
|
|
+ </>
|
|
|
+ )}
|
|
|
</div>
|
|
|
</div>
|
|
|
</Modal>
|