GoodsAll.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import { Button, Input, Modal, Table } from 'antd'
  2. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  3. import styles from './index.module.scss'
  4. import { getGoodsListAllAPI } from '@/store/action/object4'
  5. import { useDispatch, useSelector } from 'react-redux'
  6. import { RootState } from '@/store'
  7. import ImageLazy from '@/components/ImageLazy'
  8. import '../../Object3/AddObject3/GoodsAll.css'
  9. import { MessageFu } from '@/utils/message'
  10. type Props = {
  11. colsePage: any
  12. addPage: boolean
  13. }
  14. function GoodsAll({ colsePage, addPage }: Props) {
  15. const dispatch = useDispatch()
  16. // 进页面获取列表
  17. useEffect(() => {
  18. dispatch(getGoodsListAllAPI(''))
  19. }, [dispatch])
  20. // 藏品名称
  21. const [name, setName] = useState('')
  22. const nameTime = useRef(-1)
  23. const nameChange = useCallback(
  24. (e: React.ChangeEvent<HTMLInputElement>) => {
  25. setName(e.target.value)
  26. clearTimeout(nameTime.current)
  27. nameTime.current = window.setTimeout(() => {
  28. dispatch(getGoodsListAllAPI(e.target.value))
  29. }, 500)
  30. },
  31. [dispatch]
  32. )
  33. // 有关表格
  34. const results = useSelector((state: RootState) => state.object4Store.goodsAllList)
  35. // 已经选中的表格数据
  36. const resultsAc = useSelector((state: RootState) => state.object4Store.goodsTableList)
  37. const columns = useMemo(() => {
  38. return [
  39. {
  40. title: '缩略图',
  41. render: (item: any) => <ImageLazy width={120} height={70} src={item.thumb} />
  42. },
  43. {
  44. title: '藏品编号名称',
  45. dataIndex: 'dictNum'
  46. },
  47. {
  48. title: '藏品编号',
  49. render: (item: any) => (item.num ? item.num : '-')
  50. },
  51. {
  52. title: '藏品名称',
  53. dataIndex: 'name'
  54. },
  55. {
  56. title: '类别',
  57. dataIndex: 'dictGoodType'
  58. }
  59. ]
  60. }, [])
  61. // 选中的表格数据
  62. const [tableSelectList, setTableSelectList] = useState([])
  63. // 表格的多选
  64. const rowSelection = useMemo(() => {
  65. return {
  66. onChange: (selectedRowKeys: any, selectedRows: any) => {
  67. setTableSelectList(selectedRows)
  68. },
  69. // 默认选中
  70. defaultSelectedRowKeys: resultsAc.map((v: any) => v.id)
  71. }
  72. }, [resultsAc])
  73. // 点击确定
  74. const btnOkFu = useCallback(() => {
  75. dispatch({
  76. type: 'object4/getGoodsTableList',
  77. payload: tableSelectList.map((v: any) => {
  78. return {
  79. ...v,
  80. outLocation: ''
  81. }
  82. })
  83. })
  84. MessageFu.success('添加成功!')
  85. colsePage()
  86. }, [colsePage, dispatch, tableSelectList])
  87. return (
  88. <div className={styles.GoodsAll}>
  89. <Modal
  90. open={addPage}
  91. destroyOnClose
  92. wrapClassName='GoodsAllModel'
  93. title='添加藏品'
  94. onCancel={colsePage}
  95. footer={
  96. [] // 设置footer为空,去掉 取消 确定默认按钮
  97. }
  98. >
  99. <div className='ObjectAddTit'>
  100. <div className='topSearch'>
  101. <span>藏品编号:</span>
  102. <Input
  103. value={name}
  104. maxLength={10}
  105. style={{ width: 300 }}
  106. placeholder='请输入'
  107. allowClear
  108. onChange={e => nameChange(e)}
  109. />
  110. </div>
  111. </div>
  112. <div className='tableBox'>
  113. <Table
  114. size='small'
  115. scroll={{ y: 500 }}
  116. rowSelection={{
  117. type: 'checkbox',
  118. ...rowSelection
  119. }}
  120. dataSource={results}
  121. columns={columns}
  122. rowKey='id'
  123. pagination={false}
  124. />
  125. </div>
  126. <br />
  127. <div className='moveBtn'>
  128. <Button type='primary' onClick={btnOkFu} disabled={tableSelectList.length === 0}>
  129. 提交
  130. </Button>
  131. </div>
  132. </Modal>
  133. </div>
  134. )
  135. }
  136. const MemoGoodsAll = React.memo(GoodsAll)
  137. export default MemoGoodsAll