index.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import { App, Button, Card, Input, Pagination, Popconfirm, Select, Table } from 'antd';
  2. import React, { useEffect, useRef, useState } from 'react';
  3. import style from '../bookLink/index.less'
  4. import { useSize } from 'ahooks';
  5. import { useAjax } from '@/Hook/useAjax';
  6. import { delCorpUserChatApi, getCorpUserChatListApi, getCorpUserChatListProps } from '../../API/groupLeaderManage';
  7. import { GroupLeaderTableConfig } from './tableConfig';
  8. import SearchBox from '../../components/searchBox';
  9. import { SearchOutlined, PlusOutlined, DeleteOutlined } from '@ant-design/icons';
  10. import { getAdAccountAllOfMember, getCorpAllListApi } from '@/API/global';
  11. import './global.less'
  12. import AddGL from './addGL';
  13. /**
  14. * 群主号管理
  15. * @returns
  16. */
  17. const GroupLeaderManage: React.FC = () => {
  18. /*******************************************/
  19. const { message } = App.useApp();
  20. const ref = useRef<HTMLDivElement>(null)
  21. const size = useSize(ref)
  22. const [queryParams, setQueryParams] = useState<getCorpUserChatListProps>({ pageNum: 1, pageSize: 20 })
  23. const [queryParamsNew, setQueryParamsNew] = useState<getCorpUserChatListProps>({ pageNum: 1, pageSize: 20 })
  24. const [visible, setVisible] = useState<boolean>(false)
  25. const [selectedRows, setselectedRows] = useState<any[]>([])
  26. const getCorpUserChatList = useAjax((params) => getCorpUserChatListApi(params))
  27. const delCorpUserChat = useAjax((params) => delCorpUserChatApi(params))
  28. const getCorpAllList = useAjax((params) => getCorpAllListApi(params))
  29. const allOfMember = useAjax(() => getAdAccountAllOfMember())
  30. /*******************************************/
  31. useEffect(() => {
  32. allOfMember.run()
  33. getCorpAllList.run({})
  34. }, [])
  35. useEffect(() => {
  36. getCorpUserChatList.run(queryParamsNew)
  37. }, [queryParamsNew])
  38. const handleDel = () => {
  39. delCorpUserChat.run(selectedRows.map(item => item.id)).then(res => {
  40. setselectedRows([])
  41. getCorpUserChatList.refresh()
  42. message.success('删除成功')
  43. })
  44. }
  45. return <Card
  46. styles={{ body: { padding: 0, display: 'flex', flexDirection: 'column', height: 'calc(100vh - 74px)', overflow: 'hidden' } }}
  47. >
  48. <div>
  49. <SearchBox
  50. bodyPadding={`10px 16px 4px`}
  51. buttons={<>
  52. <Button type="primary" onClick={() => {
  53. setQueryParamsNew({ ...queryParams, pageNum: 1 })
  54. }} loading={getCorpUserChatList.loading} icon={<SearchOutlined />}>搜索</Button>
  55. <Button type="primary" icon={<PlusOutlined />} onClick={() => setVisible(true)}>新增群主号</Button>
  56. <Popconfirm
  57. title="确认删除?"
  58. onConfirm={handleDel}
  59. disabled={selectedRows.length === 0}
  60. >
  61. <Button type="primary" danger icon={<DeleteOutlined />} disabled={selectedRows.length === 0}>删除</Button>
  62. </Popconfirm>
  63. </>}
  64. >
  65. <>
  66. <Select
  67. value={queryParams?.corpIds}
  68. onChange={(e) => setQueryParams({ ...queryParams, corpIds: e })}
  69. showSearch
  70. mode='multiple'
  71. style={{ minWidth: 110 }}
  72. maxTagCount={1}
  73. placeholder="主体"
  74. filterOption={(input, option) =>
  75. ((option?.label ?? '') as string).toLowerCase().includes(input.toLowerCase())
  76. }
  77. allowClear
  78. options={getCorpAllList?.data?.data?.map((item: any) => ({ label: item.corpName, value: item.corpId }))}
  79. />
  80. <Input onChange={(e) => setQueryParams({ ...queryParams, corpUserName: e.target.value as any })} value={queryParams?.corpUserName} placeholder="客服号名称" allowClear />
  81. <Input onChange={(e) => setQueryParams({ ...queryParams, corpUserIds: e.target.value as any })} value={queryParams?.corpUserIds} placeholder="客服ID(多个,,空格换行)" allowClear />
  82. <Select
  83. value={queryParams?.operUserId}
  84. onChange={(e) => setQueryParams({ ...queryParams, operUserId: e })}
  85. showSearch
  86. style={{ width: 110 }}
  87. placeholder="运营"
  88. filterOption={(input, option) =>
  89. ((option?.label ?? '') as string).toLowerCase().includes(input.toLowerCase())
  90. }
  91. allowClear
  92. options={allOfMember?.data?.data?.map((item: any) => ({ label: item.nickname, value: item.userId }))}
  93. />
  94. <Select
  95. value={queryParams?.putUserId}
  96. onChange={(e) => setQueryParams({ ...queryParams, putUserId: e })}
  97. showSearch
  98. style={{ width: 110 }}
  99. placeholder="投手"
  100. filterOption={(input, option) =>
  101. ((option?.label ?? '') as string).toLowerCase().includes(input.toLowerCase())
  102. }
  103. allowClear
  104. options={allOfMember?.data?.data?.map((item: any) => ({ label: item.nickname, value: item.userId }))}
  105. />
  106. <Select
  107. style={{ width: 90 }}
  108. showSearch
  109. placeholder="状态"
  110. value={queryParams?.status}
  111. onChange={(value) => setQueryParams({ ...queryParams, status: value })}
  112. filterOption={(input, option) =>
  113. ((option?.label ?? '') as string).toLowerCase().includes(input.toLowerCase())
  114. }
  115. allowClear
  116. options={[{ label: '可用', value: 1 }, { label: '禁用', value: 0 }]}
  117. />
  118. </>
  119. </SearchBox>
  120. </div>
  121. <div className={style.bookLinkTable} ref={ref}>
  122. <Table
  123. dataSource={getCorpUserChatList?.data?.data?.records}
  124. columns={GroupLeaderTableConfig()}
  125. bordered
  126. className='resetTable'
  127. pagination={false}
  128. rowKey={'id'}
  129. size='small'
  130. loading={getCorpUserChatList?.loading}
  131. scroll={{ y: size?.height && ref.current ? size?.height - ref.current.querySelector('.ant-table-thead').clientHeight : 300 }}
  132. rowSelection={{
  133. selectedRowKeys: selectedRows?.map((item: any) => item?.id),
  134. onSelect: (record: { id: string }, selected: boolean) => {
  135. let newData = JSON.parse(JSON.stringify(selectedRows))
  136. if (selected) {
  137. newData.push({ ...record })
  138. } else {
  139. newData = newData.filter((item: { id: string }) => item.id !== record.id)
  140. }
  141. setselectedRows(newData)
  142. },
  143. onSelectAll: (selected: boolean, _: { id: string }[], changeRows: { id: string }[]) => {
  144. let newData = JSON.parse(JSON.stringify(selectedRows || '[]'))
  145. if (selected) {
  146. changeRows.forEach((item: { id: string }) => {
  147. const index = newData.findIndex((ite: { id: string }) => ite.id === item.id)
  148. if (index === -1) {
  149. newData.push(item)
  150. }
  151. })
  152. } else {
  153. const newSelectAccData = newData.filter((item: { id: string }) => {
  154. const index = changeRows.findIndex((ite: { id: string }) => ite.id === item.id)
  155. if (index !== -1) {
  156. return false
  157. } else {
  158. return true
  159. }
  160. })
  161. newData = newSelectAccData
  162. }
  163. setselectedRows(newData)
  164. }
  165. }}
  166. />
  167. </div>
  168. <div className={style.bookLinkPagination}>
  169. <Pagination
  170. size="small"
  171. total={getCorpUserChatList?.data?.data?.total || 0}
  172. showSizeChanger
  173. showQuickJumper
  174. pageSize={getCorpUserChatList?.data?.data?.size || 20}
  175. current={getCorpUserChatList?.data?.data?.current || 1}
  176. onChange={(page: number, pageSize: number) => {
  177. // ref.current?.scrollTo({ top: 0 })
  178. setTimeout(() => {
  179. setQueryParams({ ...queryParams, pageNum: page, pageSize })
  180. setQueryParamsNew({ ...queryParamsNew, pageNum: page, pageSize })
  181. }, 50)
  182. }}
  183. showTotal={(total: number) => <span style={{ fontSize: 12 }}>共 {total} 条</span>}
  184. />
  185. </div>
  186. {/* 新增群主号 */}
  187. {visible && <AddGL
  188. visible={visible}
  189. onChange={() => {
  190. setVisible(false)
  191. getCorpUserChatList.refresh()
  192. }}
  193. onClose={() => {
  194. setVisible(false)
  195. }}
  196. />}
  197. </Card>
  198. };
  199. export default GroupLeaderManage;