index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { PromotionDataDay, getPromotionDataDatListApi, getPromotionDataDatTotalApi, newEditTTAdgroupsDataApi } from "@/services/gameData/adlist"
  3. import React, { useEffect, useState } from "react"
  4. import columns12 from "./tableConfig"
  5. import QueryForm from "@/components/QueryForm"
  6. import TableData from "../../components/TableData"
  7. import moment from "moment"
  8. import { getPresets } from "@/components/QueryForm/const"
  9. import DayAd from "./dayAd"
  10. import { Button, message, Modal, notification, Space, Table } from "antd"
  11. import { PauseCircleOutlined, PlayCircleOutlined } from "@ant-design/icons"
  12. const Monitor = () => {
  13. /***************************************/
  14. const [queryForm, setQueryForm] = useState<PromotionDataDay>({ pageNum: 1, pageSize: 50, sourceSystem: 'ZX_ONE', costBeginDate: moment().format('YYYY-MM-DD'), costEndDate: moment().format('YYYY-MM-DD') })
  15. const [totalData, setTotalData] = useState<any[]>([])
  16. const [visible, setVisible] = useState<boolean>(false)
  17. const [promotionId, setPromotionId] = useState<number>()
  18. const [adName, setAdName] = useState<string>('')
  19. const [selectedRows, setSelectedRows] = useState<any[]>([])
  20. const [failIdList, setFailIdList] = useState<{ adgroupId: number, code: number, message: string, messageCn: string }[]>([])
  21. const [failVisible, setFailVisible] = useState<boolean>(false)
  22. const getPromotionDataDatList = useAjax((params) => getPromotionDataDatListApi(params))
  23. const getPromotionDataDatTotal = useAjax((params) => getPromotionDataDatTotalApi(params))
  24. const newEditTTAdgroupsData = useAjax((params) => newEditTTAdgroupsDataApi(params))
  25. /***************************************/
  26. useEffect(() => {
  27. getPromotionDataDatList.run(queryForm)
  28. getPromotionDataDatTotal.run(queryForm).then((res: { id: number; accountName: string }) => {
  29. res.id = 1
  30. res.accountName = '总计'
  31. setTotalData([res])
  32. })
  33. }, [queryForm])
  34. const dayHandle = (data: any) => {
  35. setVisible(true)
  36. setAdName(data.promotionName)
  37. setPromotionId(data.promotionId)
  38. }
  39. // 批量启停
  40. const adStatus = (type: 'play' | 'suspend') => {
  41. let params: any = {}
  42. params.suspend = type === 'play' ? false : true
  43. params.adgroupIds = selectedRows.map(item => item.accountId + ',' + item.promotionId)
  44. if (params.adgroupIds.length === 0) {
  45. message.warn(`所以账号都是${type === 'play' ? '启动' : '暂停'}状态,无需${type === 'play' ? '启动' : '暂停'}操作`)
  46. return
  47. }
  48. let hide = message.loading(`正在设置...`, 0, () => {
  49. message.success('设置成功');
  50. });
  51. newEditTTAdgroupsData.run(params).then((res: any) => {
  52. if (res?.failIdList?.length === 0) {
  53. message.success(`操作完成!`)
  54. getPromotionDataDatList.refresh()
  55. setSelectedRows([])
  56. } else {
  57. setFailIdList(res?.list || [])
  58. setFailVisible(true)
  59. }
  60. hide()
  61. })
  62. }
  63. return <div>
  64. <TableData
  65. czChild={<Space>
  66. {/* <Switch checkedChildren="开启全选" unCheckedChildren="关闭全选" checked={!isZj} onChange={(e) => { setIsZj(!e); }} /> */}
  67. <Button type='primary' size="small" style={{ background: '#67c23a', borderColor: '#67c23a' }} loading={newEditTTAdgroupsData.loading} icon={<PlayCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('play')}>启动</Button>
  68. <Button type='primary' size="small" style={{ background: '#e6a23c', borderColor: '#e6a23c' }} loading={newEditTTAdgroupsData.loading} icon={<PauseCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('suspend')}>暂停</Button>
  69. {selectedRows.length > 0 && <Button type="link" danger onClick={() => setSelectedRows([])}>清空</Button>}
  70. <span style={{ color: 'red' }}>操作完数据结果延时5分钟之内,即时结果去腾讯后台查看</span>
  71. </Space>}
  72. leftChild={<QueryForm
  73. initialValues={{ sourceSystem: 'ZX_ONE', consumeDay: [moment(), moment()] }}
  74. onChange={(data: any) => {
  75. const { type, gameClassify, costBeginDay, costEndDay, sysUserName, regPayIntervalTime, ...params } = data
  76. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  77. newQueryForm.pageNum = 1
  78. newQueryForm.pitcherName = sysUserName
  79. newQueryForm.accountType = type
  80. newQueryForm.classify = gameClassify
  81. if (costBeginDay && costEndDay) {
  82. newQueryForm.costBeginDate = costBeginDay
  83. newQueryForm.costEndDate = costEndDay
  84. } else {
  85. delete newQueryForm.costBeginDate
  86. delete newQueryForm.costEndDate
  87. }
  88. if (regPayIntervalTime?.length > 0 && (regPayIntervalTime[0] || regPayIntervalTime[1])) {
  89. newQueryForm.firstRechargeAmountMin = regPayIntervalTime[0]
  90. newQueryForm.firstRechargeAmountMax = regPayIntervalTime[1]
  91. }
  92. setQueryForm({ ...newQueryForm, ...params })
  93. }}
  94. isSource
  95. isAccountId
  96. isAccount
  97. isType
  98. isAgentId
  99. isBGGameClassify
  100. isConsumeDay={{ ranges: getPresets() }}
  101. isCpName
  102. isGameId
  103. isSysUserId
  104. isProjectId
  105. isProjectName
  106. isPromotionId
  107. isPromotionName
  108. isAdTTStatus
  109. isPayIntervalTime={{ tips: '首日充值金额区间(元)' }}
  110. />}
  111. isZj
  112. totalData={totalData}
  113. scroll={{ x: 1000, y: 600 }}
  114. ajax={getPromotionDataDatList}
  115. fixed={{ left: 3, right: 1 }}
  116. dataSource={getPromotionDataDatList?.data?.records?.map((item: any, index: number) => ({ ...item, id: Number(queryForm.pageNum.toString() + index.toString()) }))}
  117. total={getPromotionDataDatList?.data?.total}
  118. page={queryForm.pageNum}
  119. pageSize={queryForm.pageSize}
  120. sortData={{
  121. field: queryForm?.sortFiled,
  122. order: queryForm?.sortType === 'asc' ? 'ascend' : 'descend'
  123. }}
  124. title='头条广告监控'
  125. onChange={(props: any) => {
  126. let { pagination, sortData } = props
  127. let { current, pageSize } = pagination
  128. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  129. if (sortData && sortData?.order) {
  130. newQueryForm['sortType'] = sortData?.order === 'ascend' ? 'asc' : 'desc'
  131. newQueryForm['sortFiled'] = sortData?.field
  132. } else {
  133. delete newQueryForm['sortType']
  134. delete newQueryForm['sortFiled']
  135. }
  136. newQueryForm.pageNum = current
  137. newQueryForm.pageSize = pageSize
  138. setQueryForm({ ...newQueryForm })
  139. }}
  140. config={columns12(dayHandle)}
  141. configName={'头条广告监控'}
  142. rowSelection={{
  143. selectedRowKeys: selectedRows.map(item => item.id + ''),
  144. getCheckboxProps: (record: any) => ({
  145. disabled: record.status === 'STATUS_DELETED' || record?.accountName === '总计'
  146. }),
  147. onSelect: (record: { promotionId: number }, selected: boolean) => {
  148. if (selected) {
  149. selectedRows.push({ ...record })
  150. setSelectedRows([...selectedRows])
  151. } else {
  152. let newSelectAccData = selectedRows.filter((item: { promotionId: number }) => item.promotionId !== record.promotionId)
  153. setSelectedRows([...newSelectAccData])
  154. }
  155. },
  156. onSelectAll: (selected: boolean, selectedRowss: { promotionId: number }[], changeRows: { promotionId: number }[]) => {
  157. if (selected) {
  158. let newSelectAccData = [...selectedRows]
  159. changeRows.forEach((item: { promotionId: number }) => {
  160. let index = newSelectAccData.findIndex((ite: { promotionId: number }) => ite.promotionId === item.promotionId)
  161. if (index === -1) {
  162. newSelectAccData.push({ ...item })
  163. }
  164. })
  165. setSelectedRows([...newSelectAccData])
  166. } else {
  167. let newSelectAccData = selectedRows.filter((item: { promotionId: number }) => {
  168. let index = changeRows.findIndex((ite: { promotionId: number }) => ite.promotionId === item.promotionId)
  169. if (index !== -1) {
  170. return false
  171. } else {
  172. return true
  173. }
  174. })
  175. setSelectedRows([...newSelectAccData])
  176. }
  177. }
  178. }}
  179. />
  180. {failVisible && <Modal
  181. title={<strong>报错信息</strong>}
  182. visible={failVisible}
  183. className='modalResetCss'
  184. width={650}
  185. onCancel={() => { setFailVisible(false); setFailIdList([]) }}
  186. footer={null}
  187. >
  188. <Table
  189. size="small"
  190. bordered
  191. rowKey={'creativeId'}
  192. columns={[{
  193. title: '创意ID',
  194. dataIndex: 'creativeId',
  195. key: 'creativeId',
  196. width: 110,
  197. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  198. }, {
  199. title: 'code',
  200. dataIndex: 'code',
  201. key: 'code',
  202. width: 70,
  203. align: 'center',
  204. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  205. }, {
  206. title: '错误信息',
  207. dataIndex: 'messageCn',
  208. key: 'messageCn',
  209. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  210. }]}
  211. dataSource={failIdList}
  212. />
  213. </Modal>}
  214. {visible && <DayAd adName={adName} visible={visible} onClose={() => { setVisible(false); setPromotionId(undefined) }} queryForm={queryForm} promotionId={promotionId} />}
  215. </div>
  216. }
  217. export default Monitor