expandedRowTable.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { delAdSysWarningRuleApi, delAdSysWarningRuleBlackApi, DelAdSysWarningRuleProps, getSysWarningRuleApi, removeAccountApi } from "@/services/adMonitor/earlyWarning"
  3. import { SyncOutlined } from "@ant-design/icons"
  4. import { Drawer, message, Space, Table } from "antd"
  5. import React, { useEffect, useState } from "react"
  6. import columns, { columnsAccount, columnsBlack } from "./expandedColumns"
  7. interface Props {
  8. data: any,
  9. onClose?: () => void
  10. onChange?: () => void
  11. visible?: boolean
  12. }
  13. const ExpandedRowTable: React.FC<Props> = ({ data, visible, onChange, onClose }) => {
  14. /*****************************/
  15. const [adgroupList, setAdgroupList] = useState<any[]>([])
  16. const [accountList, setAccountList] = useState<any[]>([])
  17. const [blackAdgroupList, setBlackAdgroupList] = useState<any[]>([])
  18. const getSysWarningRule = useAjax((params) => getSysWarningRuleApi(params), { formatResult: true })
  19. const delAdSysWarningRule = useAjax((params) => delAdSysWarningRuleApi(params))
  20. const delAdSysWarningRuleBlack = useAjax((params) => delAdSysWarningRuleBlackApi(params))
  21. const removeAccount = useAjax((params) => removeAccountApi(params))
  22. /*****************************/
  23. useEffect(() => {
  24. if (data?.id) {
  25. getList()
  26. }
  27. }, [])
  28. const getList = () => {
  29. getSysWarningRule.run(data.id).then(res => {
  30. console.log(res)
  31. if (res?.data) {
  32. setAdgroupList(res?.data?.adgroupList)
  33. setAccountList(res?.data?.accountList)
  34. setBlackAdgroupList(res?.data?.blackAdgroupList)
  35. }
  36. })
  37. }
  38. const delAdgroup = (value: DelAdSysWarningRuleProps) => {
  39. let { accountId, adgroupId } = value
  40. delAdSysWarningRule.run({ accountId, adgroupId, ruleId: data.id }).then(res => {
  41. message.success('删除成功')
  42. getList()
  43. })
  44. }
  45. const delAccount = (value: any) => {
  46. let { accountId } = value
  47. removeAccount.run({ accountId, ruleId: data.id }).then(res => {
  48. message.success('删除成功')
  49. getList()
  50. })
  51. }
  52. const delBlack = (value: DelAdSysWarningRuleProps) => {
  53. let { accountId, adgroupId } = value
  54. delAdSysWarningRuleBlack.run({ accountId, adgroupId, ruleId: data.id }).then(res => {
  55. message.success('删除成功')
  56. getList()
  57. })
  58. }
  59. return <Drawer
  60. title="详情"
  61. visible={visible}
  62. onClose={onClose}
  63. width={'70%'}
  64. extra={<a onClick={() => getList()}><SyncOutlined />刷新</a>}
  65. >
  66. <Space style={{ width: '100%' }} direction="vertical">
  67. <Table
  68. size="small"
  69. bordered
  70. columns={columns(delAdgroup)}
  71. loading={getSysWarningRule.loading}
  72. dataSource={adgroupList}
  73. rowKey={'adgroupId'}
  74. title={() => <div style={{ fontWeight: 700, color: '#1890ff' }}>
  75. <span>广告列表</span>
  76. </div>}
  77. />
  78. <Table
  79. size="small"
  80. bordered
  81. columns={columnsAccount(delAccount)}
  82. loading={getSysWarningRule.loading}
  83. dataSource={accountList}
  84. rowKey={'accountId'}
  85. title={() => <div style={{ fontWeight: 700, color: '#1890ff' }}>
  86. <span>广告账号列表</span>
  87. </div>}
  88. />
  89. <Table
  90. size="small"
  91. bordered
  92. columns={columnsBlack(delBlack)}
  93. loading={getSysWarningRule.loading}
  94. dataSource={blackAdgroupList}
  95. rowKey={'adgroupId'}
  96. title={() => <div style={{ fontWeight: 700, color: '#1890ff' }}>
  97. <span>广告黑名单列表</span>
  98. </div>}
  99. />
  100. </Space>
  101. </Drawer>;
  102. }
  103. export default React.memo(ExpandedRowTable)