index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { useAjax } from "@/Hook/useAjax";
  2. import { PauseCircleOutlined, PlayCircleOutlined, QuestionCircleOutlined, TransactionOutlined } from "@ant-design/icons";
  3. import { Button, Checkbox, Col, Input, Row, Select, Space, Tooltip, message } from "antd"
  4. import React, { useCallback, useEffect, useState } from "react"
  5. import { ADGROUP_STATUS } from "../const";
  6. import { getAdqV3AdListApi, modifyStatusBatchApi, syncBatchApi } from "@/services/launchAdq/adqv3";
  7. import tableConfig from "./tableConfig";
  8. import { txAdConfig } from "../config";
  9. import UpdateAd from "./updateAd";
  10. import TableData from "@/pages/launchSystemNew/components/TableData";
  11. const Ad: React.FC<ADQV3.AdProps> = ({ userId, creativeHandle }) => {
  12. /*****************************************/
  13. const [queryFrom, set_queryFrom] = useState<ADQV3.GetAdListProps>({ pageNum: 1, pageSize: 20, useType: 1 })
  14. const [isClearSelect, setIsClearSelect] = useState(true)
  15. const [selectedRows, setSelectedRows] = useState<any[]>([])
  16. const [update, setUpdate] = useState<{ visible: boolean }>({ visible: false })
  17. const syncBatch = useAjax((params) => syncBatchApi(params))
  18. const modifyStatusBatch = useAjax((params) => modifyStatusBatchApi(params))
  19. const getAdqV3AdList = useAjax((params) => getAdqV3AdListApi(params), { formatResult: true })
  20. /*****************************************/
  21. useEffect(() => {
  22. getList({ pageNum: 1, pageSize: 20, useType: 1 })
  23. }, [userId])
  24. // 获取列表
  25. const getList = useCallback((params: ADQV3.GetAdListProps) => {
  26. getAdqV3AdList.run({ ...params, userId })
  27. }, [userId, getAdqV3AdList])
  28. // 同步
  29. const sync = useCallback(() => {
  30. if (selectedRows?.length > 0) {
  31. let accountAdgroupMaps = [...new Set(selectedRows?.map(item => item.accountId + ',' + item.adgroupId))]
  32. syncBatch.run({ accountAdgroupMaps }).then(res => {
  33. res && getAdqV3AdList.refresh()
  34. res ? message.success('同步成功!') : message.error('同步失败!')
  35. })
  36. } else {
  37. message.error('请勾选')
  38. }
  39. }, [getAdqV3AdList, selectedRows])
  40. // 批量启停
  41. const adStatus = (type: boolean) => {
  42. let newSelectedRows = []
  43. if (type) {
  44. newSelectedRows = selectedRows.filter((item: { configuredStatus: string, adgroupId: number }) => item.configuredStatus === 'AD_STATUS_SUSPEND')
  45. } else {
  46. newSelectedRows = selectedRows.filter((item: { configuredStatus: string, adgroupId: number }) => item.configuredStatus === 'AD_STATUS_NORMAL')
  47. }
  48. if (newSelectedRows.length === 0) {
  49. message.warn(`所有广告都是${type ? '启动' : '暂停'}状态,无需${type ? '启动' : '暂停'}操作`)
  50. return
  51. }
  52. let accountAdgroupMaps = [...new Set(newSelectedRows?.map(item => item.accountId + ',' + item.adgroupId))]
  53. modifyStatusBatch.run({ accountAdgroupMaps, suspend: type }).then(res => {
  54. message.success(`${type ? '启动' : '暂停'}成功`)
  55. getAdqV3AdList.refresh()
  56. setSelectedRows([])
  57. })
  58. }
  59. return <div>
  60. <Row gutter={[6, 6]} align='middle' style={{ marginBottom: 15 }}>
  61. <Col>
  62. <Select
  63. placeholder='应用类型'
  64. style={{ width: 90 }}
  65. showSearch
  66. filterOption={(input: any, option: any) =>
  67. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  68. }
  69. value={queryFrom.useType}
  70. onChange={(value: any) => {
  71. set_queryFrom({ ...queryFrom, useType: value })
  72. }}
  73. >
  74. <Select.Option value={1}>小说</Select.Option>
  75. <Select.Option value={2}>游戏</Select.Option>
  76. </Select>
  77. </Col>
  78. <Col>
  79. <Input
  80. placeholder='广告账号(多个,分割)'
  81. allowClear
  82. style={{ width: 160 }}
  83. onChange={(e) => {
  84. let value = e.target.value
  85. let arr: any = []
  86. if (value) {
  87. value = value.replace(/[,,\s]/g, ',')
  88. arr = value.split(',').filter((a: any) => a)
  89. }
  90. set_queryFrom({ ...queryFrom, accountIdList: arr })
  91. }}
  92. />
  93. </Col>
  94. <Col>
  95. <Input
  96. placeholder='广告ID(多个,分割)'
  97. allowClear
  98. style={{ width: 150 }}
  99. onChange={(e) => {
  100. let value = e.target.value
  101. let arr: any = []
  102. if (value) {
  103. value = value.replace(/[,,\s]/g, ',')
  104. arr = value.split(',').filter((a: any) => a)
  105. }
  106. set_queryFrom({ ...queryFrom, adgroupIdList: arr })
  107. }}
  108. />
  109. </Col>
  110. <Col>
  111. <Select
  112. placeholder='广告状态'
  113. mode="multiple"
  114. style={{ minWidth: 120 }}
  115. showSearch
  116. filterOption={(input: any, option: any) =>
  117. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  118. }
  119. allowClear
  120. onChange={(value: any) => {
  121. set_queryFrom({ ...queryFrom, systemStatusList: value })
  122. }}
  123. >
  124. {Object.keys(ADGROUP_STATUS).map(key => {
  125. return <Select.Option value={key} key={key}>{ADGROUP_STATUS[key]}</Select.Option>
  126. })}
  127. </Select>
  128. </Col>
  129. <Col>
  130. <Input
  131. placeholder='广告名称'
  132. allowClear
  133. style={{ width: 120 }}
  134. onChange={(e) => {
  135. let value = e.target.value
  136. set_queryFrom({ ...queryFrom, adgroupName: value })
  137. }}
  138. />
  139. </Col>
  140. <Col>
  141. <Input
  142. placeholder='腾讯备注'
  143. allowClear
  144. style={{ width: 120 }}
  145. onChange={(e) => {
  146. let value = e.target.value
  147. let arr: any = []
  148. if (value) {
  149. value = value.replace(/[,,\s]/g, ',')
  150. arr = value.split(',').filter((a: any) => a)
  151. }
  152. set_queryFrom({ ...queryFrom, accountMemo: arr })
  153. }}
  154. />
  155. </Col>
  156. <Col>
  157. <Input
  158. placeholder='本地备注'
  159. allowClear
  160. style={{ width: 120 }}
  161. onChange={(e) => {
  162. let value = e.target.value
  163. let arr: any = []
  164. if (value) {
  165. value = value.replace(/[,,\s]/g, ',')
  166. arr = value.split(',').filter((a: any) => a)
  167. }
  168. set_queryFrom({ ...queryFrom, accountRemark: arr })
  169. }}
  170. />
  171. </Col>
  172. <Col>
  173. <Space>
  174. <Button
  175. type="primary"
  176. onClick={() => {
  177. if (isClearSelect) {
  178. setSelectedRows([])
  179. }
  180. getList({ ...queryFrom, pageNum: 1 })
  181. }}
  182. >
  183. <Space>
  184. <span>搜索</span>
  185. <Checkbox className='clearCheckbox' onClick={(e) => e.stopPropagation()} checked={isClearSelect} onChange={(e) => setIsClearSelect(e.target.checked)} />
  186. <Tooltip title="勾选搜索清空已选">
  187. <QuestionCircleOutlined />
  188. </Tooltip>
  189. </Space>
  190. </Button>
  191. {selectedRows?.length > 0 && <Button type='link' style={{ padding: 0, color: 'red' }} onClick={() => {
  192. setSelectedRows([])
  193. }}>清空已选({selectedRows?.length})</Button>}
  194. </Space>
  195. </Col>
  196. </Row>
  197. <TableData
  198. isCard={false}
  199. columns={() => tableConfig(() => getAdqV3AdList.refresh(), creativeHandle)}
  200. ajax={getAdqV3AdList}
  201. syncAjax={sync}
  202. fixed={{ left: 2, right: 5 }}
  203. dataSource={getAdqV3AdList?.data?.data?.records}
  204. loading={getAdqV3AdList?.loading || syncBatch?.loading}
  205. scroll={{ y: 560 }}
  206. total={getAdqV3AdList?.data?.data?.total}
  207. page={getAdqV3AdList?.data?.data?.current}
  208. pageSize={getAdqV3AdList?.data?.data?.size}
  209. myKey={'adgroupId'}
  210. gutter={[0, 10]}
  211. config={txAdConfig}
  212. configName="腾讯广告3.0"
  213. leftChild={<Space direction='vertical'>
  214. <Row gutter={[10, 10]} align='middle'>
  215. <Col><Button type='primary' style={{ background: '#67c23a', borderColor: '#67c23a' }} loading={modifyStatusBatch.loading} icon={<PlayCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus(true)}>启动</Button></Col>
  216. <Col><Button type='primary' style={{ background: '#e6a23c', borderColor: '#e6a23c' }} loading={modifyStatusBatch.loading} icon={<PauseCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus(false)}>暂停</Button></Col>
  217. <Col><Button type='primary' icon={<TransactionOutlined />} disabled={selectedRows.length === 0} onClick={() => setUpdate({ visible: true })}>修改出价</Button></Col>
  218. </Row>
  219. </Space>}
  220. rowSelection={{
  221. selectedRowKeys: selectedRows.map(item => item.adgroupId.toString()),
  222. getCheckboxProps: (record: any) => ({
  223. disabled: record.isDeleted
  224. }),
  225. onSelect: (record: { adgroupId: number, mpName: string }, selected: boolean) => {
  226. if (selected) {
  227. selectedRows.push({ ...record })
  228. setSelectedRows([...selectedRows])
  229. } else {
  230. let newSelectAccData = selectedRows.filter((item: { adgroupId: number }) => item.adgroupId !== record.adgroupId)
  231. setSelectedRows([...newSelectAccData])
  232. }
  233. },
  234. onSelectAll: (selected: boolean, selectedRowss: { adgroupId: number }[], changeRows: { adgroupId: number }[]) => {
  235. if (selected) {
  236. let newSelectAccData = [...selectedRows]
  237. changeRows.forEach((item: { adgroupId: number }) => {
  238. let index = newSelectAccData.findIndex((ite: { adgroupId: number }) => ite.adgroupId === item.adgroupId)
  239. if (index === -1) {
  240. newSelectAccData.push({ ...item })
  241. }
  242. })
  243. setSelectedRows([...newSelectAccData])
  244. } else {
  245. let newSelectAccData = selectedRows.filter((item: { adgroupId: number }) => {
  246. let index = changeRows.findIndex((ite: { adgroupId: number }) => ite.adgroupId === item.adgroupId)
  247. if (index !== -1) {
  248. return false
  249. } else {
  250. return true
  251. }
  252. })
  253. setSelectedRows([...newSelectAccData])
  254. }
  255. }
  256. }}
  257. onChange={(props: any) => {
  258. let { pagination } = props
  259. let { current, pageSize } = pagination
  260. set_queryFrom({ ...queryFrom, pageNum: current, pageSize })
  261. getList({ ...queryFrom, pageNum: current, pageSize })
  262. }}
  263. />
  264. {/* 修改广告 */}
  265. {update.visible && <UpdateAd
  266. {...update}
  267. selectedRows={selectedRows}
  268. onChange={() => {
  269. setUpdate({ visible: false })
  270. getAdqV3AdList.refresh()
  271. setSelectedRows([])
  272. }}
  273. onClose={() => { setUpdate({ visible: false }) }}
  274. />}
  275. </div>
  276. }
  277. export default React.memo(Ad)