index.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { getPromotedObjectList, putPromotedObjectSync } from "@/services/launchAdq/adq"
  3. import { PromotedObjectType } from "@/services/launchAdq/enum"
  4. import { Button, Col, Input, message, Row, Select } from "antd"
  5. import React, { useCallback, useEffect, useState } from "react"
  6. import TableData from "../../components/TableData"
  7. import tableConfig from "./tableConfig"
  8. type Props = {
  9. accountId: string,
  10. adAccountId: string,
  11. userId: string,
  12. queryParmas: {
  13. accountId?: string,//账户ID
  14. adgroupId?: string,//广告ID
  15. },
  16. tableIdClick: (props: {
  17. activeKey: string, parma: {
  18. accountId?: string,//账户ID
  19. campaignId?: string,//计划ID
  20. adgroupId?: string,//广告ID
  21. adcreativeId?: string,//创意ID
  22. pageId?: string,//落地页ID
  23. targetingId?: string,//定向ID
  24. }
  25. }) => void
  26. }
  27. /**
  28. * 操作记录
  29. */
  30. const Promoted: React.FC<Props> = (props) => {
  31. /**************************/
  32. let { tableIdClick, queryParmas, userId } = props
  33. const [queryparams, setQueryparams] = useState<{ accountIdList?: string, promotedObjectName?: string, promotedObjectType?: string, pageNum: number, pageSize: number, userId: string }>({ pageNum: 1, pageSize: 20, userId })
  34. const getLogList = useAjax((params) => getPromotedObjectList(params), { formatResult: true })
  35. const syncAjax = useAjax((adAccountId) => putPromotedObjectSync(adAccountId))
  36. const [selectedRows, setSelectedRows] = useState<any[]>([])
  37. /**************************/
  38. useEffect(() => {
  39. getList(queryparams)
  40. }, [userId])
  41. const getList = useCallback((params: any) => {
  42. getLogList.run({ ...params, userId })
  43. }, [userId])
  44. // 同步
  45. const sync = useCallback(() => {
  46. // if (selectedRows?.length === 0) {
  47. // message.error('请先勾选要同步的广点通账号!')
  48. // return
  49. // }
  50. let arr = [...new Set(selectedRows?.map(item => item.accountId))]
  51. syncAjax.run({ accountIdList: arr }).then(res => {
  52. res && getLogList.refresh()
  53. res ? message.success('同步成功!') : message.error('同步失败!')
  54. })
  55. }, [getLogList, selectedRows])
  56. return <div>
  57. <TableData
  58. isCard={false}
  59. columns={() => tableConfig(tableIdClick)}
  60. ajax={getLogList}
  61. dataSource={getLogList?.data?.data?.records}
  62. loading={getLogList?.data?.loading}
  63. scroll={{ y: 550 }}
  64. total={getLogList?.data?.data?.total}
  65. page={getLogList?.data?.data?.current}
  66. pageSize={getLogList?.data?.data?.size}
  67. syncAjax={sync}
  68. leftChild={<>
  69. <Row gutter={[10, 10]}>
  70. <Col>
  71. <Input
  72. placeholder='广告账号'
  73. allowClear
  74. style={{ width: 150 }}
  75. onChange={(e) => {
  76. let value = e.target.value
  77. let arr: any = []
  78. if (value) {
  79. value = value.replace(/[,,\s]/g, ',')
  80. arr = value.split(',').filter((a: any) => a)
  81. }
  82. setQueryparams({ ...queryparams, accountIdList: arr })
  83. }}
  84. />
  85. </Col>
  86. <Col>
  87. <Input
  88. placeholder='推广目标名称'
  89. allowClear
  90. style={{ width: 150 }}
  91. value={queryparams.promotedObjectName}
  92. onChange={(e) => {
  93. setQueryparams({ ...queryparams, promotedObjectName: e.target.value })
  94. }}
  95. />
  96. </Col>
  97. <Col>
  98. <Select
  99. placeholder='推广目标选择'
  100. style={{ width: 120 }}
  101. showSearch
  102. filterOption={(input: any, option: any) =>
  103. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  104. }
  105. allowClear
  106. onChange={(value: any) => {
  107. setQueryparams({ ...queryparams, promotedObjectType: value })
  108. }}
  109. >
  110. {Object.keys(PromotedObjectType).map(key => {
  111. return <Select.Option value={key} key={key}>{PromotedObjectType[key]}</Select.Option>
  112. })}
  113. </Select>
  114. </Col>
  115. <Col>
  116. <Button type='primary' onClick={() => { getList({ ...queryparams, pageNum: 1 }) }}>搜索</Button>
  117. </Col>
  118. </Row>
  119. </>}
  120. onChange={(props: any) => {
  121. let { sortData, pagination } = props
  122. let { current, pageSize } = pagination
  123. setQueryparams({ ...queryparams, pageNum: current, pageSize })
  124. getList({ ...queryparams, pageNum: current, pageSize })
  125. }}
  126. rowSelection={{
  127. onChange: (selectedRowKeys: any, selectedRows: any) => {
  128. setSelectedRows(selectedRows)
  129. }
  130. }}
  131. />
  132. </div>
  133. }
  134. export default React.memo(Promoted)