index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { delAuthAccountAssetsGroupApi, getAccountAssetsGroupListApi } from "@/services/adqV3/global"
  3. import { PlusOutlined, SearchOutlined } from "@ant-design/icons"
  4. import { Button, Card, Input, message, Radio, Select, Table } from "antd"
  5. import React, { useEffect, useState } from "react"
  6. import '../../tencentAdPutIn/index.less'
  7. import ModifyAccountGroup from "./modifyAccountGroup"
  8. import columns from "./tableConfig"
  9. import SubAccount from "./subAccount"
  10. /**
  11. * 账户资产共享
  12. * @returns
  13. */
  14. const AccountAssetSharing: React.FC = () => {
  15. /****************************************/
  16. const [queryForm, setQueryForm] = useState<{ accountGroupName?: string, authMainAccountIds?: number[], authType?: string, pageNum: number, pageSize: number }>({ pageNum: 1, pageSize: 20 })
  17. const [queryFormNew, setQueryFormNew] = useState<{ accountGroupName?: string, authMainAccountIds?: number[], authType?: string, pageNum: number, pageSize: number }>({ pageNum: 1, pageSize: 20 })
  18. const [visible, setVisible] = useState<boolean>(false)
  19. const [initialValues, setInitialValues] = useState<any>(undefined)
  20. const [subAccountData, setSubAccountData] = useState<{ visible: boolean, data: any }>({ visible: false, data: undefined })
  21. const getAccountAssetsGroupList = useAjax((params) => getAccountAssetsGroupListApi(params))
  22. const delAuthAccountAssetsGroup = useAjax((params) => delAuthAccountAssetsGroupApi(params))
  23. /****************************************/
  24. useEffect(() => {
  25. getAccountAssetsGroupList.run(queryFormNew)
  26. }, [queryFormNew])
  27. const del = (id: number) => {
  28. delAuthAccountAssetsGroup.run({ id }).then(res => {
  29. if (res) {
  30. message.success('删除成功')
  31. getAccountAssetsGroupList.refresh()
  32. }
  33. })
  34. }
  35. const update = (data: any) => {
  36. setInitialValues(data)
  37. setVisible(true)
  38. }
  39. const handleSubAccount = (data: any) => {
  40. setSubAccountData({ visible: true, data })
  41. }
  42. return <Card
  43. className="cardResetCss"
  44. title={<div className="flexStart" style={{ gap: 8 }}>
  45. <Select
  46. value={queryForm?.authType}
  47. allowClear
  48. onChange={(e) => setQueryForm({ ...queryForm, authType: e, pageNum: 1 })}
  49. placeholder="授权类型"
  50. style={{ width: 110 }}
  51. options={[{ label: '素材', value: 'material' }, { label: '转化归因', value: 'conversion' }, { label: '原生落地页', value: 'wechatDownPage' }]}
  52. />
  53. <Input style={{ width: 200 }} placeholder="请输入账户组名称" value={queryForm?.accountGroupName} allowClear onChange={(e) => setQueryForm({ ...queryForm, accountGroupName: e.target.value, pageNum: 1 })} />
  54. <Input.TextArea
  55. style={{ width: 300 }}
  56. placeholder="请输入主账户ID列表(多个逗号隔开)"
  57. allowClear
  58. rows={1}
  59. onChange={(e) => {
  60. let value = e.target.value
  61. let arr: any[] = []
  62. if (value) {
  63. value = value.replace(/[,,\s]/g, ',')
  64. arr = value.split(',').filter((a: any) => a)
  65. }
  66. setQueryForm({ ...queryForm, authMainAccountIds: arr, pageNum: 1 })
  67. }}
  68. />
  69. <Button type="primary" icon={<SearchOutlined />} onClick={() => setQueryFormNew({ ...queryForm })}>搜索</Button>
  70. <Button type="primary" icon={<PlusOutlined />} onClick={() => { setVisible(true) }}>新增账户资产共享组</Button>
  71. </div>}
  72. >
  73. <Table
  74. columns={columns(del, update, handleSubAccount)}
  75. dataSource={getAccountAssetsGroupList.data?.records}
  76. size="small"
  77. loading={getAccountAssetsGroupList?.loading}
  78. scroll={{ y: 600, x: 1100 }}
  79. bordered
  80. rowKey={'id'}
  81. pagination={{
  82. defaultPageSize: 20,
  83. current: getAccountAssetsGroupList.data?.current || 1,
  84. pageSize: getAccountAssetsGroupList.data?.size || 10,
  85. total: getAccountAssetsGroupList.data?.total || 0
  86. }}
  87. onChange={(pagination) => {
  88. const { current, pageSize } = pagination
  89. setQueryForm({ ...queryForm, pageNum: current || 1, pageSize: pageSize || 10 })
  90. setQueryFormNew({ ...queryForm, pageNum: current || 1, pageSize: pageSize || 10 })
  91. }}
  92. />
  93. {/* 新增修改 */}
  94. {visible && <ModifyAccountGroup
  95. initialValues={initialValues}
  96. visible={visible}
  97. onClose={() => {
  98. setVisible(false)
  99. setInitialValues(undefined)
  100. }}
  101. onChange={() => {
  102. setVisible(false)
  103. setInitialValues(undefined)
  104. getAccountAssetsGroupList.refresh()
  105. }}
  106. />}
  107. {/* 授权子账户 */}
  108. {subAccountData?.visible && <SubAccount
  109. {...subAccountData}
  110. onClose={() => {
  111. setSubAccountData({ visible: false, data: undefined })
  112. }}
  113. />}
  114. </Card>
  115. }
  116. export default AccountAssetSharing