index.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. import { useAjax } from "@/Hook/useAjax";
  2. import { PauseCircleOutlined, PlayCircleOutlined, PlusOutlined, QuestionCircleOutlined, TransactionOutlined } from "@ant-design/icons";
  3. import { Button, Checkbox, Col, Input, Row, Select, Space, Tooltip, Typography, 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. import AddDynamic from "../../tencentAdPutIn/create/addDynamic";
  12. import { arraysHaveSameValues } from "@/utils/utils";
  13. import { MARKETING_GOAL_ENUM } from "../../tencentAdPutIn/const";
  14. const { Text } = Typography;
  15. const Ad: React.FC<ADQV3.AdProps> = ({ userId, creativeHandle }) => {
  16. /*****************************************/
  17. const [queryFrom, set_queryFrom] = useState<ADQV3.GetAdListProps>({ pageNum: 1, pageSize: 20, useType: 1 })
  18. const [isClearSelect, setIsClearSelect] = useState(true)
  19. const [selectedRows, setSelectedRows] = useState<any[]>([])
  20. const [update, setUpdate] = useState<{ visible: boolean }>({ visible: false })
  21. const [addDynamicVisible, setAddDynamicVisible] = useState<boolean>(false)
  22. const [handleType, setHandleType] = useState<number>(1)
  23. const syncBatch = useAjax((params) => syncBatchApi(params))
  24. const modifyStatusBatch = useAjax((params) => modifyStatusBatchApi(params))
  25. const getAdqV3AdList = useAjax((params) => getAdqV3AdListApi(params), { formatResult: true })
  26. /*****************************************/
  27. useEffect(() => {
  28. getList({ pageNum: 1, pageSize: 20, useType: 1 })
  29. }, [userId])
  30. // 获取列表
  31. const getList = useCallback((params: ADQV3.GetAdListProps) => {
  32. getAdqV3AdList.run({ ...params, userId })
  33. }, [userId, getAdqV3AdList])
  34. // 同步
  35. const sync = useCallback(() => {
  36. if (selectedRows?.length > 0) {
  37. let accountAdgroupMaps = [...new Set(selectedRows?.map(item => item.accountId + ',' + item.adgroupId))]
  38. syncBatch.run({ accountAdgroupMaps }).then(res => {
  39. res && getAdqV3AdList.refresh()
  40. res ? message.success('同步成功!') : message.error('同步失败!')
  41. })
  42. } else {
  43. message.error('请勾选')
  44. }
  45. }, [getAdqV3AdList, selectedRows])
  46. // 批量启停
  47. const adStatus = (type: boolean) => {
  48. let newSelectedRows = []
  49. if (type) {
  50. newSelectedRows = selectedRows.filter((item: { configuredStatus: string, adgroupId: number }) => item.configuredStatus === 'AD_STATUS_SUSPEND')
  51. } else {
  52. newSelectedRows = selectedRows.filter((item: { configuredStatus: string, adgroupId: number }) => item.configuredStatus === 'AD_STATUS_NORMAL')
  53. }
  54. if (newSelectedRows.length === 0) {
  55. message.warn(`所有广告都是${type ? '启动' : '暂停'}状态,无需${type ? '启动' : '暂停'}操作`)
  56. return
  57. }
  58. let accountAdgroupMaps = [...new Set(newSelectedRows?.map(item => item.accountId + ',' + item.adgroupId))]
  59. modifyStatusBatch.run({ accountAdgroupMaps, suspend: !type }).then(res => {
  60. message.success(`${type ? '启动' : '暂停'}成功`)
  61. getAdqV3AdList.refresh()
  62. setSelectedRows([])
  63. })
  64. }
  65. // 添加创意
  66. const addDynamic = () => {
  67. setAddDynamicVisible(true)
  68. }
  69. return <div>
  70. <Row gutter={[6, 6]} align='middle' style={{ marginBottom: 15 }}>
  71. <Col>
  72. <Select
  73. placeholder='应用类型'
  74. style={{ width: 90 }}
  75. showSearch
  76. filterOption={(input: any, option: any) =>
  77. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  78. }
  79. value={queryFrom.useType}
  80. onChange={(value: any) => {
  81. set_queryFrom({ ...queryFrom, useType: value })
  82. }}
  83. >
  84. <Select.Option value={1}>小说</Select.Option>
  85. <Select.Option value={2}>游戏</Select.Option>
  86. </Select>
  87. </Col>
  88. <Col>
  89. <Input
  90. placeholder='广告账号(多个,分割)'
  91. allowClear
  92. style={{ width: 160 }}
  93. onChange={(e) => {
  94. let value = e.target.value
  95. let arr: any = []
  96. if (value) {
  97. value = value.replace(/[,,\s]/g, ',')
  98. arr = value.split(',').filter((a: any) => a)
  99. }
  100. set_queryFrom({ ...queryFrom, accountIdList: arr })
  101. }}
  102. />
  103. </Col>
  104. <Col>
  105. <Input
  106. placeholder='广告ID(多个,分割)'
  107. allowClear
  108. style={{ width: 150 }}
  109. onChange={(e) => {
  110. let value = e.target.value
  111. let arr: any = []
  112. if (value) {
  113. value = value.replace(/[,,\s]/g, ',')
  114. arr = value.split(',').filter((a: any) => a)
  115. }
  116. set_queryFrom({ ...queryFrom, adgroupIdList: arr })
  117. }}
  118. />
  119. </Col>
  120. <Col>
  121. <Select
  122. placeholder='广告状态'
  123. mode="multiple"
  124. style={{ minWidth: 120 }}
  125. showSearch
  126. filterOption={(input: any, option: any) =>
  127. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  128. }
  129. allowClear
  130. onChange={(value: any) => {
  131. set_queryFrom({ ...queryFrom, systemStatusList: value })
  132. }}
  133. >
  134. {Object.keys(ADGROUP_STATUS).map(key => {
  135. return <Select.Option value={key} key={key}>{ADGROUP_STATUS[key]}</Select.Option>
  136. })}
  137. </Select>
  138. </Col>
  139. <Col>
  140. <Input
  141. placeholder='广告名称'
  142. allowClear
  143. style={{ width: 120 }}
  144. onChange={(e) => {
  145. let value = e.target.value
  146. set_queryFrom({ ...queryFrom, adgroupName: value })
  147. }}
  148. />
  149. </Col>
  150. <Col>
  151. <Input
  152. placeholder='腾讯备注'
  153. allowClear
  154. style={{ width: 120 }}
  155. onChange={(e) => {
  156. let value = e.target.value
  157. let arr: any = []
  158. if (value) {
  159. value = value.replace(/[,,\s]/g, ',')
  160. arr = value.split(',').filter((a: any) => a)
  161. }
  162. set_queryFrom({ ...queryFrom, accountMemo: arr })
  163. }}
  164. />
  165. </Col>
  166. <Col>
  167. <Input
  168. placeholder='本地备注'
  169. allowClear
  170. style={{ width: 120 }}
  171. onChange={(e) => {
  172. let value = e.target.value
  173. let arr: any = []
  174. if (value) {
  175. value = value.replace(/[,,\s]/g, ',')
  176. arr = value.split(',').filter((a: any) => a)
  177. }
  178. set_queryFrom({ ...queryFrom, accountRemark: arr })
  179. }}
  180. />
  181. </Col>
  182. <Col>
  183. <Space>
  184. <Button
  185. type="primary"
  186. onClick={() => {
  187. if (isClearSelect) {
  188. setSelectedRows([])
  189. }
  190. getList({ ...queryFrom, pageNum: 1 })
  191. }}
  192. >
  193. <Space>
  194. <span>搜索</span>
  195. <Checkbox className='clearCheckbox' onClick={(e) => e.stopPropagation()} checked={isClearSelect} onChange={(e) => setIsClearSelect(e.target.checked)} />
  196. <Tooltip title="勾选搜索清空已选">
  197. <QuestionCircleOutlined />
  198. </Tooltip>
  199. </Space>
  200. </Button>
  201. {selectedRows?.length > 0 && <Button type='link' style={{ padding: 0, color: 'red' }} onClick={() => {
  202. setSelectedRows([])
  203. }}>清空已选({selectedRows?.length})</Button>}
  204. </Space>
  205. </Col>
  206. </Row>
  207. <TableData
  208. isCard={false}
  209. columns={() => tableConfig(() => getAdqV3AdList.refresh(), creativeHandle)}
  210. ajax={getAdqV3AdList}
  211. syncAjax={sync}
  212. fixed={{ left: 2, right: 5 }}
  213. dataSource={getAdqV3AdList?.data?.data?.records}
  214. loading={getAdqV3AdList?.loading || syncBatch?.loading}
  215. scroll={{ y: 560 }}
  216. total={getAdqV3AdList?.data?.data?.total}
  217. page={getAdqV3AdList?.data?.data?.current}
  218. pageSize={getAdqV3AdList?.data?.data?.size}
  219. myKey={'adgroupId'}
  220. gutter={[0, 10]}
  221. config={txAdConfig}
  222. configName="腾讯广告3.0"
  223. leftChild={<Space direction='vertical'>
  224. <Row gutter={[10, 10]} align='middle'>
  225. <Col><Select
  226. style={{ width: 120 }}
  227. onChange={(e) => {
  228. setHandleType(e)
  229. setSelectedRows([])
  230. }}
  231. value={handleType}
  232. options={[{ label: '广告操作', value: 1 }]}
  233. /></Col>
  234. {handleType === 1 ? <>
  235. <Col><Button type='primary' style={{ background: '#67c23a', borderColor: '#67c23a' }} loading={modifyStatusBatch.loading} icon={<PlayCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus(true)}>启动</Button></Col>
  236. <Col><Button type='primary' style={{ background: '#e6a23c', borderColor: '#e6a23c' }} loading={modifyStatusBatch.loading} icon={<PauseCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus(false)}>暂停</Button></Col>
  237. <Col><Button type='primary' icon={<TransactionOutlined />} disabled={selectedRows.length === 0} onClick={() => setUpdate({ visible: true })}>修改出价</Button></Col>
  238. </> : handleType === 2 ? <>
  239. <Col><Button type='primary' icon={<PlusOutlined />} disabled={selectedRows.length === 0} onClick={addDynamic}>添加创意</Button></Col>
  240. <Col>
  241. {selectedRows?.length > 0 && <Text type="danger" strong style={{ fontSize: 12, marginRight: 6 }}>
  242. {`当前选择:营销目的:${MARKETING_GOAL_ENUM[selectedRows?.[0]?.marketingGoal]}`}
  243. </Text>}
  244. <Tooltip title="选择的广告必须与已选广告的营销目的、营销载体、推广内容、广告版位一致">
  245. <QuestionCircleOutlined style={{ color: 'red' }} />
  246. </Tooltip>
  247. </Col>
  248. </> : null}
  249. </Row>
  250. </Space>}
  251. rowSelection={{
  252. selectedRowKeys: selectedRows.map(item => item.adgroupId.toString()),
  253. getCheckboxProps: (record: any) => {
  254. if (handleType === 2 && selectedRows?.length > 0) {
  255. const { siteSet, marketingCarrierType, marketingGoal, marketingTargetType, sceneSpec, automaticSiteEnabled } = selectedRows[0]
  256. return {
  257. disabled: record.isDeleted || !(
  258. record?.marketingGoal === marketingGoal && // 营销内容
  259. record?.marketingCarrierType === marketingCarrierType && // 营销载体
  260. record?.marketingTargetType === marketingTargetType && // 推广产品
  261. record?.automaticSiteEnabled === automaticSiteEnabled && // 自动版位
  262. arraysHaveSameValues(siteSet || [], record?.siteSet || []) && // 版位选择
  263. arraysHaveSameValues(record?.sceneSpec?.wechatPosition || [], sceneSpec?.wechatPosition || []) // 微信公众号与小程序定投
  264. )
  265. }
  266. } else {
  267. return {
  268. disabled: record.isDeleted
  269. }
  270. }
  271. },
  272. onSelect: (record: { adgroupId: number, mpName: string }, selected: boolean) => {
  273. if (selected) {
  274. selectedRows.push({ ...record })
  275. setSelectedRows([...selectedRows])
  276. } else {
  277. let newSelectAccData = selectedRows.filter((item: { adgroupId: number }) => item.adgroupId !== record.adgroupId)
  278. setSelectedRows([...newSelectAccData])
  279. }
  280. },
  281. onSelectAll: (selected: boolean, selectedRowss: { adgroupId: number }[], changeRows: { adgroupId: number }[]) => {
  282. if (selected) {
  283. let newSelectAccData = [...selectedRows]
  284. let firstRow = newSelectAccData?.[0] || changeRows?.[0] || {}
  285. changeRows.forEach((item: { adgroupId: number }) => {
  286. let index = newSelectAccData.findIndex((ite: { adgroupId: number }) => ite.adgroupId === item.adgroupId)
  287. if (index === -1) {
  288. let data: any = { ...item }
  289. if (handleType === 2) {
  290. const { siteSet, marketingCarrierType, marketingGoal, marketingTargetType, sceneSpec, automaticSiteEnabled } = firstRow
  291. if (
  292. data?.marketingGoal === marketingGoal && // 营销内容
  293. data?.marketingCarrierType === marketingCarrierType && // 营销载体
  294. data?.marketingTargetType === marketingTargetType && // 推广产品
  295. data?.automaticSiteEnabled === automaticSiteEnabled && // 自动版位
  296. arraysHaveSameValues(siteSet || [], data?.siteSet || []) && // 版位选择
  297. arraysHaveSameValues(data?.sceneSpec?.wechatPosition || [], sceneSpec?.wechatPosition || []) // 微信公众号与小程序定投
  298. ) {
  299. newSelectAccData.push(data)
  300. }
  301. } else {
  302. newSelectAccData.push(data)
  303. }
  304. }
  305. })
  306. setSelectedRows([...newSelectAccData])
  307. } else {
  308. let newSelectAccData = selectedRows.filter((item: { adgroupId: number }) => {
  309. let index = changeRows.findIndex((ite: { adgroupId: number }) => ite.adgroupId === item.adgroupId)
  310. if (index !== -1) {
  311. return false
  312. } else {
  313. return true
  314. }
  315. })
  316. setSelectedRows([...newSelectAccData])
  317. }
  318. }
  319. }}
  320. onChange={(props: any) => {
  321. let { pagination } = props
  322. let { current, pageSize } = pagination
  323. set_queryFrom({ ...queryFrom, pageNum: current, pageSize })
  324. getList({ ...queryFrom, pageNum: current, pageSize })
  325. }}
  326. />
  327. {/* 修改广告 */}
  328. {update.visible && <UpdateAd
  329. {...update}
  330. selectedRows={selectedRows}
  331. onChange={() => {
  332. setUpdate({ visible: false })
  333. getAdqV3AdList.refresh()
  334. setSelectedRows([])
  335. }}
  336. onClose={() => { setUpdate({ visible: false }) }}
  337. />}
  338. {/* 新增创意 */}
  339. {addDynamicVisible && <AddDynamic
  340. adData={selectedRows}
  341. visible={addDynamicVisible}
  342. onClose={() => {
  343. setAddDynamicVisible(false)
  344. }}
  345. onChange={() => {
  346. }}
  347. />}
  348. </div>
  349. }
  350. export default React.memo(Ad)