index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { Button } from 'antd'
  4. import MyTable from '@/components/MyTable'
  5. import MyPopconfirm from '@/components/MyPopconfirm'
  6. import { baseURL } from '@/utils/http'
  7. import B1upXLSX from '@/pages/B_enterTibet/B1collect/B1edit/B1upXLSX'
  8. import { TypeinfoXLSX } from '@/pages/B_enterTibet/B1collect/type'
  9. import C4impImg from './C4impImg'
  10. import { C4tableCFu } from '@/utils/tableData'
  11. import { A3m_APIdel, A3m_APIgetList, A3m_APIlookInfo } from '@/store/action/A3machineReg'
  12. import { MessageFu } from '@/utils/message'
  13. import { B1Xtype } from '@/pages/B_enterTibet/B1collect/data'
  14. type Props = {
  15. colseFu: (flag: boolean) => void
  16. }
  17. function C4import({ colseFu }: Props) {
  18. const [formData, setFormData] = useState({
  19. pageNum: 1,
  20. pageSize: 10
  21. })
  22. // 列表数据
  23. const [tableObj, setTableObj] = useState({
  24. list: [],
  25. total: 0
  26. })
  27. // 获取列表信息
  28. const getListFu = useCallback(async () => {
  29. const res = await A3m_APIgetList({
  30. ...formData,
  31. type: '4'
  32. })
  33. if (res.code === 0) {
  34. setTableObj({
  35. list: res.data.records || [],
  36. total: res.data.total
  37. })
  38. }
  39. }, [formData])
  40. useEffect(() => {
  41. getListFu()
  42. }, [getListFu])
  43. const [acTxt, setAcTxt] = useState('导入藏品数据')
  44. const delFu = useCallback(
  45. async (id: number) => {
  46. const res = await A3m_APIdel(id)
  47. if (res.code === 0) {
  48. MessageFu.success('删除成功')
  49. getListFu()
  50. }
  51. },
  52. [getListFu]
  53. )
  54. // 点击查看
  55. const lookTableFu = useCallback(async (id: number) => {
  56. const res = await A3m_APIlookInfo('4', id)
  57. if (res.code === 0) {
  58. const succArr: B1Xtype[] = []
  59. const errArr: B1Xtype[] = []
  60. res.data.forEach((v: any) => {
  61. if (v.importError === 0) succArr.push({ ...v, row: v.id })
  62. else {
  63. errArr.push({
  64. ...v,
  65. row: v.id,
  66. error: JSON.parse(v.importDesc || '[]')
  67. })
  68. }
  69. })
  70. setInfoXLSX({
  71. show: true,
  72. succ: succArr,
  73. err: errArr,
  74. type: '查看'
  75. })
  76. }
  77. }, [])
  78. const tableLastBtn = useMemo(() => {
  79. return [
  80. {
  81. title: '导入结果',
  82. render: (item: any) => (
  83. <Button size='small' type='text' onClick={() => lookTableFu(item.id)}>
  84. 查看
  85. </Button>
  86. )
  87. },
  88. {
  89. title: '操作',
  90. render: (item: any) => {
  91. return (
  92. <MyPopconfirm
  93. txtK='删除'
  94. onConfirm={() => delFu(item.id)}
  95. Dom={
  96. <Button size='small' type='text' danger>
  97. 删除记录
  98. </Button>
  99. }
  100. />
  101. )
  102. }
  103. }
  104. ]
  105. }, [delFu, lookTableFu])
  106. const flagRef = useRef(false)
  107. // 导入合格数据之后变成true
  108. const B1upXLSXRef = useRef<any>(null)
  109. // 上传表格数据
  110. const [infoXLSX, setInfoXLSX] = useState<TypeinfoXLSX>({
  111. show: false,
  112. succ: [],
  113. err: []
  114. })
  115. // 页码变化
  116. const paginationChange = useCallback((pageNum: number, pageSize: number) => {
  117. setFormData({ pageNum, pageSize })
  118. }, [])
  119. return (
  120. <div className={styles.C4import}>
  121. <div className='C4top'>
  122. <div>
  123. <span className='C4top11'>
  124. {['导入藏品数据', '导入藏品图片'].map(v => (
  125. <Button
  126. onClick={() => setAcTxt(v)}
  127. key={v}
  128. type={acTxt === v ? 'primary' : 'default'}
  129. >
  130. {v}
  131. </Button>
  132. ))}
  133. </span>
  134. {acTxt === '导入藏品数据' ? (
  135. <>
  136. 一普数据{' '}
  137. <a
  138. href={`${baseURL}/baseData/ZP_TEMP.xlsx`}
  139. download='一普数据模板'
  140. target='_blank'
  141. rel='noreferrer'
  142. >
  143. <Button>下载模板</Button>
  144. </a>
  145. <Button type='primary' onClick={() => B1upXLSXRef.current?.openUpFu('1')}>
  146. 上传表格
  147. </Button>
  148. <span className='jianGe'></span>
  149. 省平台数据{' '}
  150. <a
  151. href={`${baseURL}/baseData/ZP_TEMP.xlsx`}
  152. download='省平台数据模板'
  153. target='_blank'
  154. rel='noreferrer'
  155. >
  156. <Button>下载模板</Button>
  157. </a>
  158. <Button type='primary' onClick={() => B1upXLSXRef.current?.openUpFu('2')}>
  159. 上传表格
  160. </Button>
  161. <span className='C4tit'>每组数据最多1000条</span>
  162. <B1upXLSX
  163. pageType='藏品总账'
  164. ref={B1upXLSXRef}
  165. closeFu={() => setInfoXLSX({ show: false, succ: [], err: [] })}
  166. infoXLSX={infoXLSX}
  167. upSuccFu={(succ, err) => setInfoXLSX({ show: true, succ, err })}
  168. isZongZhang={true}
  169. url='cms/import/im/upload/excel'
  170. clickSuccFu={arr => {
  171. // console.log(123, arr)
  172. getListFu()
  173. // 导入成功
  174. flagRef.current = true
  175. }}
  176. />
  177. </>
  178. ) : null}
  179. </div>
  180. <Button onClick={() => colseFu(flagRef.current)}>返回</Button>
  181. </div>
  182. <div hidden={acTxt !== '导入藏品数据'}>
  183. <MyTable
  184. classKey='C4import'
  185. yHeight={655}
  186. list={tableObj.list}
  187. columnsTemp={C4tableCFu('导入藏品数据')}
  188. lastBtn={tableLastBtn}
  189. pageNum={formData.pageNum}
  190. pageSize={formData.pageSize}
  191. total={tableObj.total}
  192. onChange={(pageNum, pageSize) => paginationChange(pageNum, pageSize)}
  193. />
  194. </div>
  195. <C4impImg hidden={acTxt === '导入藏品数据'} />
  196. {/* 表格 */}
  197. </div>
  198. )
  199. }
  200. const MemoC4import = React.memo(C4import)
  201. export default MemoC4import