subAccount.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { Button, Input, message, Modal, Space, Table } from "antd"
  2. import React, { useEffect, useState } from "react"
  3. import '../../tencentAdPutIn/index.less'
  4. import { PlusOutlined, SearchOutlined } from "@ant-design/icons"
  5. import { useAjax } from "@/Hook/useAjax"
  6. import { getAccountAssetsGroupAccountListApi, revokeAuthAccountAssetsGroupApi } from "@/services/adqV3/global"
  7. import AddSubAccount from "./addSubAccount"
  8. import columns from "./tableConfigSub"
  9. interface Props {
  10. data?: any
  11. visible?: boolean
  12. onClose?: () => void
  13. }
  14. /**
  15. * 授权子账户
  16. * @param param0
  17. * @returns
  18. */
  19. const SubAccount: React.FC<Props> = ({ data, visible, onClose }) => {
  20. /********************************************/
  21. const [queryForm, setQueryForm] = useState<{ accountids?: string[] }>()
  22. const [visibleS, setVisibleS] = useState<boolean>(false)
  23. const [dataSource, setDataSource] = useState<any[]>([])
  24. const getAccountAssetsGroupAccountList = useAjax((params) => getAccountAssetsGroupAccountListApi(params))
  25. const revokeAuthAccountAssetsGroup = useAjax((params) => revokeAuthAccountAssetsGroupApi(params))
  26. /********************************************/
  27. useEffect(() => {
  28. getList()
  29. }, [data])
  30. const getList = () => {
  31. getAccountAssetsGroupAccountList.run({ groupId: data.id }).then(res => {
  32. handleSearch(res || [])
  33. })
  34. }
  35. const handleSearch = (data: any) => {
  36. let accountids = queryForm?.accountids || []
  37. if (accountids?.length) {
  38. setDataSource(data?.filter((item: { accountId: number }) => accountids?.some(val => item.accountId?.toString().toLowerCase()?.includes(val))))
  39. } else {
  40. setDataSource(data)
  41. }
  42. }
  43. const del = (accountId: number[], assetId?: number) => {
  44. const hide = message.loading('取消授权中。。。')
  45. revokeAuthAccountAssetsGroup.run({ accountAssetsGroupId: data.id, accountId, assetId }).then(res => {
  46. hide()
  47. if (res) {
  48. message.success('取消成功')
  49. getList()
  50. }
  51. }).catch(() => hide())
  52. }
  53. return <Modal
  54. title={<span><strong>{data.authMainAccountId} 授权子账户</strong><span style={{ fontSize: 12 }}>(主体:{data.corporationName})</span></span>}
  55. open={visible}
  56. className="modalResetCss"
  57. width={660}
  58. onCancel={onClose}
  59. footer={null}
  60. >
  61. <Space style={{ width: '100%' }} direction="vertical">
  62. <div className="flexStart" style={{ gap: 8 }}>
  63. <Input.TextArea
  64. style={{ width: 300 }}
  65. placeholder="请输入主账户ID列表(多个逗号隔开)"
  66. allowClear
  67. rows={1}
  68. onChange={(e) => {
  69. let value = e.target.value
  70. let arr: any[] = []
  71. if (value) {
  72. value = value.replace(/[,,\s]/g, ',')
  73. arr = value.split(',').filter((a: any) => a)
  74. }
  75. setQueryForm({ ...queryForm, accountids: arr })
  76. }}
  77. />
  78. <Button type="primary" icon={<SearchOutlined />} onClick={() => getList()}>搜索</Button>
  79. <Button type="primary" icon={<PlusOutlined />} onClick={() => { setVisibleS(true) }}>子账户授权</Button>
  80. </div>
  81. <Table
  82. columns={columns(del)}
  83. dataSource={dataSource}
  84. size="small"
  85. loading={getAccountAssetsGroupAccountList?.loading}
  86. scroll={{ y: 600 }}
  87. bordered
  88. rowKey={'id'}
  89. />
  90. </Space>
  91. {visibleS && <AddSubAccount
  92. authType={data.authType}
  93. corporationName={data.corporationName}
  94. corporationLicence={data.corporationLicence}
  95. authMainAccountId={data.authMainAccountId}
  96. accountAssetsGroupId={data.id}
  97. selectedAccountIdList={getAccountAssetsGroupAccountList?.data || []}
  98. visible={visibleS}
  99. onClose={() => {
  100. setVisibleS(false)
  101. }}
  102. onChange={() => {
  103. setVisibleS(false)
  104. getList()
  105. }}
  106. />}
  107. </Modal>
  108. }
  109. export default React.memo(SubAccount)