index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { useDispatch, useSelector } from 'react-redux'
  4. import { B2_APIdel, B2_APIgetList, B2_APIupdate } from '@/store/action/B2exhiLog'
  5. import { RootState } from '@/store'
  6. import { MessageFu } from '@/utils/message'
  7. import { B2FromDataType, B2tableType } from './type'
  8. import { Button, Input, Select, Switch } from 'antd'
  9. import MyPopconfirm from '@/components/MyPopconfirm'
  10. import MyTable from '@/components/MyTable'
  11. import { B2tableC } from '@/utils/tableData'
  12. import B2look from './B2look'
  13. import { B2selectArr } from './data'
  14. const fromDataBase: B2FromDataType = {
  15. searchKey: '',
  16. status: '',
  17. pageNum: 1,
  18. pageSize: 10
  19. }
  20. function B2exhiLog() {
  21. const dispatch = useDispatch()
  22. const [fromData, setFromData] = useState(fromDataBase)
  23. const getListFu = useCallback(() => {
  24. dispatch(B2_APIgetList(fromData))
  25. }, [dispatch, fromData])
  26. useEffect(() => {
  27. getListFu()
  28. }, [getListFu])
  29. const [inputKey, setInputKey] = useState(1)
  30. // 输入框的输入
  31. const timeRef = useRef(-1)
  32. const txtChangeFu = useCallback(
  33. (e: React.ChangeEvent<HTMLInputElement>, key: 'searchKey') => {
  34. clearTimeout(timeRef.current)
  35. timeRef.current = window.setTimeout(() => {
  36. setFromData({
  37. ...fromData,
  38. [key]: e.target.value.replaceAll("'", ''),
  39. pageNum: 1
  40. })
  41. }, 500)
  42. },
  43. [fromData]
  44. )
  45. // 点击重置
  46. const resetSelectFu = useCallback(() => {
  47. setInputKey(Date.now())
  48. setFromData(fromDataBase)
  49. }, [])
  50. const { tableInfo } = useSelector((state: RootState) => state.B2exhiLog)
  51. // 点击删除
  52. const delTableFu = useCallback(
  53. async (id: number) => {
  54. const res = await B2_APIdel(id)
  55. if (res.code === 0) {
  56. MessageFu.success('删除成功!')
  57. getListFu()
  58. }
  59. },
  60. [getListFu]
  61. )
  62. // 核销
  63. const updateFu = useCallback(
  64. async (id: number, status: 0 | 1) => {
  65. const res = await B2_APIupdate(id, status)
  66. if (res.code === 0) {
  67. MessageFu.success('操作成功!')
  68. getListFu()
  69. }
  70. },
  71. [getListFu]
  72. )
  73. const tableLastBtn = useMemo(() => {
  74. return [
  75. {
  76. title: '核销状态',
  77. render: (item: B2tableType) => (
  78. <Switch
  79. checkedChildren='已核销'
  80. unCheckedChildren='未核销'
  81. value={item.status === 1}
  82. onChange={() => updateFu(item.id, item.status === 1 ? 0 : 1)}
  83. />
  84. )
  85. },
  86. {
  87. title: '操作',
  88. render: (item: B2tableType) => (
  89. <>
  90. <Button size='small' type='text' onClick={() => setLookId(item.id)}>
  91. 查看
  92. </Button>
  93. <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
  94. </>
  95. )
  96. }
  97. ]
  98. }, [delTableFu, updateFu])
  99. // 点击查看
  100. const [lookId, setLookId] = useState(0)
  101. return (
  102. <div className={styles.B2exhiLog}>
  103. <div className='pageTitle'>展馆预约记录</div>
  104. <div className='B2top'>
  105. <div className='B2top1'>
  106. <div className='B2topRow'>
  107. <span>搜索:</span>
  108. <Input
  109. key={inputKey}
  110. maxLength={50}
  111. style={{ width: 200 }}
  112. placeholder='请输入姓名/联系电话'
  113. allowClear
  114. onChange={e => txtChangeFu(e, 'searchKey')}
  115. />
  116. </div>
  117. <div className='B2topRow'>
  118. <span>核销状态:</span>
  119. <Select
  120. style={{ width: 200 }}
  121. value={fromData.status}
  122. onChange={e => setFromData({ ...fromData, pageNum: 1, status: e })}
  123. options={B2selectArr}
  124. />
  125. </div>
  126. </div>
  127. <div className='B2top1'>
  128. <Button onClick={resetSelectFu}>重置</Button>
  129. </div>
  130. </div>
  131. <MyTable
  132. yHeight={626}
  133. list={tableInfo.list}
  134. columnsTemp={B2tableC}
  135. lastBtn={tableLastBtn}
  136. pageNum={fromData.pageNum}
  137. pageSize={fromData.pageSize}
  138. total={tableInfo.total}
  139. onChange={(pageNum, pageSize) => setFromData({ ...fromData, pageNum, pageSize })}
  140. />
  141. {/* 点击查看 */}
  142. {lookId ? <B2look sId={lookId} closeFu={() => setLookId(0)} /> : null}
  143. </div>
  144. )
  145. }
  146. const MemoB2exhiLog = React.memo(B2exhiLog)
  147. export default MemoB2exhiLog