index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import React, { useCallback, useMemo, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { Button } from 'antd'
  4. import MyTable from '@/components/MyTable'
  5. import { B3eTableC } from '@/utils/tableData'
  6. import MyPopconfirm from '@/components/MyPopconfirm'
  7. import classNames from 'classnames'
  8. import Y1cathet from '@/pages/Y_goodsDetails/Y1cathet'
  9. import { openGoodsInfoFu } from '@/utils/history'
  10. import { useParams } from 'react-router-dom'
  11. import B3GaddNow from './B3GaddNow'
  12. import { forwardRef, useImperativeHandle } from 'react'
  13. import B3GaddNew from './B3GaddNew'
  14. import { TypeB3PageSta } from '../B3_4page/type'
  15. type Props = {
  16. pageSta: TypeB3PageSta
  17. }
  18. function B3goodsTable({ pageSta }: Props, ref: any) {
  19. const { key, id } = useParams<any>()
  20. // 点击删除
  21. const delTableFu = useCallback(async (id: number) => {}, [])
  22. // 打开侧边栏
  23. const [cathet, setCathet] = useState(0)
  24. const startBtn = useMemo(() => {
  25. return [
  26. {
  27. title: '藏品编号',
  28. render: (item: any) => {
  29. return (
  30. <span
  31. onClick={() => setCathet(item.id)}
  32. className={classNames('D1GtNum', item.id === cathet ? 'D1GtNumAc' : '')}
  33. >
  34. {item.num}
  35. </span>
  36. )
  37. }
  38. }
  39. ]
  40. }, [cathet])
  41. const tableLastBtn = useMemo(() => {
  42. return [
  43. {
  44. title: '操作',
  45. render: (item: any) => {
  46. return (
  47. <>
  48. <Button size='small' type='text' onClick={() => openGoodsInfoFu(item.id)}>
  49. 查看
  50. </Button>
  51. {['查看', '审批'].includes(pageSta) ? null : (
  52. <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
  53. )}
  54. </>
  55. )
  56. }
  57. }
  58. ]
  59. }, [delTableFu, pageSta])
  60. // 从已存在的藏品中添加
  61. const [nowSta, setNowSta] = useState({ key: '', id: '', type: '' })
  62. // 可以让父组件调用子组件的方法
  63. const resData = useCallback(() => {
  64. return { xxx: '藏品清单数据' }
  65. }, [])
  66. useImperativeHandle(ref, () => ({
  67. resData
  68. }))
  69. return (
  70. <div className={styles.B3goodsTable}>
  71. <div className='B3eGtop'>
  72. <div className='B3eGtop1'>藏品清单</div>
  73. <div>
  74. {['查看', '审批'].includes(pageSta) ? null : (
  75. <>
  76. <Button type='primary' onClick={() => setNowSta({ key, id, type: 'now' })}>
  77. 从已存在的藏品中添加
  78. </Button>
  79. &emsp;
  80. <Button type='primary' onClick={() => setNowSta({ key, id, type: 'new' })}>
  81. 新增
  82. </Button>
  83. </>
  84. )}
  85. </div>
  86. </div>
  87. {/* 表格 */}
  88. <MyTable
  89. list={[{ id: 99, thumb: '', num: '一段编号_可点击' }]}
  90. columnsTemp={B3eTableC}
  91. startBtn={startBtn}
  92. lastBtn={tableLastBtn}
  93. pagingInfo={false}
  94. />
  95. {/* 打开侧边栏 */}
  96. <Y1cathet sId={cathet} closeFu={() => setCathet(0)} />
  97. {nowSta.id ? (
  98. nowSta.type === 'now' ? (
  99. <B3GaddNow nowSta={nowSta} closeFu={() => setNowSta({ key: '', id: '', type: '' })} />
  100. ) : (
  101. <B3GaddNew nowSta={nowSta} closeFu={() => setNowSta({ key: '', id: '', type: '' })} />
  102. )
  103. ) : null}
  104. </div>
  105. )
  106. }
  107. export default forwardRef(B3goodsTable)