group.tsx 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { Button, Select, Table } from 'antd';
  2. import React, { useEffect, useState } from 'react';
  3. import '../../tencentAdPutIn/index.less'
  4. import { useAjax } from '@/Hook/useAjax';
  5. import { getCorpRelationAllApi, getCustomerServiceGroupListApi } from '@/services/adqV3/global';
  6. import { SearchOutlined } from '@ant-design/icons';
  7. import columns from './tableConfig';
  8. import SettingsEnterprise from './settingsEnterprise';
  9. const Group: React.FC<{ adAccountId?: number }> = ({ adAccountId }) => {
  10. /**********************************/
  11. const [queryParamsNew, setQueryParamsNew] = useState<{ adAccountId: number, pageNum: number, pageSize: number, tencentCorpId?: string }>({ pageNum: 1, pageSize: 20, adAccountId: adAccountId || 0 })
  12. const [settingsData, setSettingsData] = useState<{ visible: boolean, data: any }>({ visible: false, data: {} })
  13. const getCustomerServiceGroupList = useAjax((params) => getCustomerServiceGroupListApi(params))
  14. const getCorpRelationAll = useAjax((params) => getCorpRelationAllApi(params))
  15. /**********************************/
  16. useEffect(() => {
  17. if (adAccountId) {
  18. getCorpRelationAll.run({ adAccountId })
  19. }
  20. }, [adAccountId])
  21. useEffect(() => {
  22. if (adAccountId) {
  23. getCustomerServiceGroupList.run({ ...queryParamsNew, adAccountId })
  24. }
  25. }, [queryParamsNew, adAccountId])
  26. const handleEdit = (data: any) => {
  27. setSettingsData({ visible: true, data })
  28. // setQueryParamsNew({ ...queryParamsNew, tencentCorpId: data.tencentCorpId })
  29. }
  30. return <>
  31. <div className="flexStart" style={{ gap: 8, marginBottom: 16 }}>
  32. <Select
  33. showSearch
  34. placeholder="请选择企业"
  35. filterOption={(input, option) =>
  36. ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
  37. }
  38. style={{ width: 200 }}
  39. allowClear
  40. value={queryParamsNew?.tencentCorpId}
  41. loading={getCorpRelationAll.loading}
  42. onChange={(e) => {
  43. setQueryParamsNew({ ...queryParamsNew, tencentCorpId: e, pageNum: 1 })
  44. }}
  45. options={getCorpRelationAll?.data?.map((item: { corpName: string; tencentCorpId: string; }) => ({ label: item.corpName, value: item.tencentCorpId }))}
  46. />
  47. <Button type="primary" icon={<SearchOutlined />} loading={getCustomerServiceGroupList.loading} onClick={() => getCustomerServiceGroupList.refresh()}>刷新</Button>
  48. </div>
  49. <Table
  50. columns={columns(handleEdit)}
  51. dataSource={getCustomerServiceGroupList.data?.records}
  52. size="small"
  53. loading={getCustomerServiceGroupList?.loading}
  54. scroll={{ y: 600, x: 1000 }}
  55. rowKey={'groupId'}
  56. pagination={{
  57. total: getCustomerServiceGroupList.data?.total,
  58. defaultPageSize: 20,
  59. current: getCustomerServiceGroupList.data?.current,
  60. pageSize: getCustomerServiceGroupList.data?.size
  61. }}
  62. onChange={(pagination) => {
  63. const { current, pageSize } = pagination
  64. setQueryParamsNew({ ...queryParamsNew, pageNum: current as number, pageSize: pageSize as number || 20 })
  65. }}
  66. />
  67. {/* 设置修改 */}
  68. {settingsData.visible && <SettingsEnterprise
  69. {...settingsData}
  70. adAccountId={adAccountId as number}
  71. onClose={() => setSettingsData({ visible: false, data: {} })}
  72. onChange={() => {
  73. getCustomerServiceGroupList.refresh()
  74. setSettingsData({ visible: false, data: {} })
  75. }}
  76. />}
  77. </>
  78. };
  79. export default React.memo(Group);