index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import React, { useEffect, useState } from "react"
  2. import { useAjax } from "@/Hook/useAjax"
  3. import { getGDTListApi, GetGDTListProps, getGDTTotalApi } from "@/services/iaaData"
  4. import TablePro from "@/components/TablePro"
  5. import columns12 from "./tableConfig"
  6. import QueryForm from "@/components/QueryForm"
  7. import moment from "moment"
  8. import { useModel } from "umi"
  9. import { Button, message, notification, Space } from "antd"
  10. import { newEditAdqAdgroupsDataApi } from "@/services/gameData"
  11. import { PauseCircleOutlined, PlayCircleOutlined } from "@ant-design/icons"
  12. import DayAd from "./dayAd"
  13. /**
  14. * 腾讯广告列表
  15. * @returns
  16. */
  17. const TencentIaaAd: React.FC = () => {
  18. /****************************************/
  19. const { initialState } = useModel('@@initialState');
  20. const [selectedRows, setSelectedRows] = useState<any[]>([])
  21. const [queryForm, setQueryForm] = useState<GetGDTListProps>({
  22. pageNum: 1,
  23. pageSize: 30,
  24. costDayBegin: moment().format('YYYY-MM-DD'),
  25. costDayEnd: moment().format('YYYY-MM-DD'),
  26. })
  27. const [totalData, setTotalData] = useState<any[]>([])
  28. const [visible, setVisible] = useState<boolean>(false)
  29. const [promotionId, setPromotionId] = useState<number>()
  30. const [adName, setAdName] = useState<string>('')
  31. const editAdqAdgroupsData = useAjax((params) => newEditAdqAdgroupsDataApi(params))
  32. const getGDTList = useAjax((params) => getGDTListApi(params))
  33. const getGDTTotal = useAjax((params) => getGDTTotalApi(params))
  34. /****************************************/
  35. useEffect(() => {
  36. if (initialState?.iaaApp) {
  37. const [appId, productType] = initialState.iaaApp.split('||')
  38. getGDTList.run({ ...queryForm, appId, productType })
  39. getGDTTotal.run({ ...queryForm, appId, productType }).then((res: { data: { id: number; accountId: string } }) => {
  40. if (res?.data) {
  41. let data = res?.data
  42. data.id = 1
  43. data.accountId = '总计'
  44. setTotalData([data])
  45. } else {
  46. setTotalData([{ id: 1, accountId: '总计' }])
  47. }
  48. })
  49. }
  50. }, [queryForm, initialState?.iaaApp])
  51. const dayHandle = (data: any) => {
  52. setVisible(true)
  53. setAdName(data.promotionName)
  54. setPromotionId(data.promotionId)
  55. }
  56. // 批量启停
  57. const adStatus = (type: 'play' | 'suspend') => {
  58. let params: any = {}
  59. if (type === 'play') {
  60. params.configuredStatus = 'AD_STATUS_NORMAL'
  61. params.adgroupIds = selectedRows.filter((item: { configuredStatus: string, promotionId: number }) => item.configuredStatus === 'AD_STATUS_SUSPEND').map(item => item.promotionId)
  62. } else {
  63. params.configuredStatus = 'AD_STATUS_SUSPEND'
  64. params.adgroupIds = selectedRows.filter((item: { configuredStatus: string, promotionId: number }) => item.configuredStatus === 'AD_STATUS_NORMAL').map(item => item.promotionId)
  65. }
  66. if (params.adgroupIds.length === 0) {
  67. message.warn(`所以账号都是${type === 'play' ? '启动' : '暂停'}状态,无需${type === 'play' ? '启动' : '暂停'}操作`)
  68. return
  69. }
  70. editAdqAdgroupsData.run(params).then(res => {
  71. message.success(`${type === 'play' ? '启动' : '暂停'}成功: ${res.success},失败: ${res.fail}`)//
  72. if (res?.fail) {
  73. notification.error({
  74. message: `${type === 'play' ? '启动' : '暂停'}失败`,
  75. description: `成功: ${res.success},修改失败${res.fail}条,失败的请到任务列表查看`,
  76. duration: 0
  77. });
  78. }
  79. getGDTList.refresh()
  80. setSelectedRows([])
  81. })
  82. }
  83. return <div>
  84. <TablePro
  85. czChild={<Space>
  86. {/* <Switch checkedChildren="开启全选" unCheckedChildren="关闭全选" checked={!isZj} onChange={(e) => { setIsZj(!e); }} /> */}
  87. <Button type='primary' size="small" style={{ background: '#67c23a', borderColor: '#67c23a' }} loading={editAdqAdgroupsData.loading} icon={<PlayCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('play')}>启动</Button>
  88. <Button type='primary' size="small" style={{ background: '#e6a23c', borderColor: '#e6a23c' }} loading={editAdqAdgroupsData.loading} icon={<PauseCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('suspend')}>暂停</Button>
  89. <span style={{ color: 'red' }}>操作完数据结果延时5分钟之内,即时结果去腾讯后台查看</span>
  90. </Space>}
  91. leftChild={<QueryForm
  92. initialValues={{ day3: [moment(), moment()] }}
  93. isAccountId
  94. isPromotionName
  95. isPutUserIdList
  96. isCpaBid
  97. isDeleted
  98. isPricing
  99. isStatus
  100. isPromotionId
  101. day1={{ placeholder: ['广告创建日期开始', '广告创建日期结束'] }}
  102. day2={{ placeholder: ['投放日期开始', '投放日期结束'] }}
  103. day3={{ placeholder: ['消耗日期开始', '消耗日期结束'] }}
  104. onChange={(data: any) => {
  105. console.log(data)
  106. const { day1, day2, day3, ...params } = data
  107. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  108. newQueryForm.pageNum = 1
  109. if (day1 && day1?.length === 2) {
  110. newQueryForm['adCreateBegin'] = moment(day1[0]).format('YYYY-MM-DD')
  111. newQueryForm['adCreateEnd'] = moment(day1[1]).format('YYYY-MM-DD')
  112. } else {
  113. delete newQueryForm['adCreateBegin']
  114. delete newQueryForm['adCreateEnd']
  115. }
  116. if (day2 && day2?.length === 2) {
  117. newQueryForm['putDayBegin'] = moment(day2[0]).format('YYYY-MM-DD')
  118. newQueryForm['putDayEnd'] = moment(day2[1]).format('YYYY-MM-DD')
  119. } else {
  120. delete newQueryForm['putDayBegin']
  121. delete newQueryForm['putDayEnd']
  122. }
  123. if (day3 && day3?.length === 2) {
  124. newQueryForm['costDayBegin'] = moment(day3[0]).format('YYYY-MM-DD')
  125. newQueryForm['costDayEnd'] = moment(day3[1]).format('YYYY-MM-DD')
  126. } else {
  127. delete newQueryForm['costDayBegin']
  128. delete newQueryForm['costDayEnd']
  129. }
  130. setQueryForm({ ...newQueryForm, ...params })
  131. }}
  132. />}
  133. isZj
  134. totalData={totalData}
  135. config={columns12(dayHandle, () => { getGDTList.refresh() })}
  136. configName={'腾讯广告列表'}
  137. fixed={{ left: 4, right: 2 }}
  138. scroll={{ x: 1000, y: 620 }}
  139. title='腾讯广告列表(游戏)'
  140. loading={getGDTList.loading}
  141. ajax={getGDTList}
  142. page={getGDTList?.data?.data?.current || 1}
  143. pageSize={getGDTList?.data?.data?.size || 20}
  144. total={getGDTList?.data?.data?.total || 0}
  145. dataSource={getGDTList?.data?.data?.records?.map((item: any) => ({ ...item, id: item.promotionId }))}
  146. onChange={(pagination: any, _: any, sortData: any) => {
  147. let { current, pageSize } = pagination
  148. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  149. if (sortData && sortData?.order) {
  150. newQueryForm['sortAsc'] = sortData?.order === 'ascend' ? true : false
  151. newQueryForm['sortFiled'] = sortData?.field
  152. } else {
  153. delete newQueryForm['sortAsc']
  154. delete newQueryForm['sortFiled']
  155. }
  156. newQueryForm.pageNum = current || newQueryForm.pageNum
  157. newQueryForm.pageSize = pageSize || newQueryForm.pageSize
  158. setQueryForm({ ...newQueryForm })
  159. }}
  160. rowSelection={{
  161. selectedRowKeys: selectedRows.map(item => item.promotionId + ''),
  162. getCheckboxProps: (record: any) => ({
  163. disabled: record.status === 'STATUS_DELETED' || record?.accountId === '总计'
  164. }),
  165. onSelect: (record: { promotionId: number }, selected: boolean) => {
  166. if (selected) {
  167. selectedRows.push({ ...record })
  168. setSelectedRows([...selectedRows])
  169. } else {
  170. let newSelectAccData = selectedRows.filter((item: { promotionId: number }) => item.promotionId !== record.promotionId)
  171. setSelectedRows([...newSelectAccData])
  172. }
  173. },
  174. onSelectAll: (selected: boolean, selectedRowss: { promotionId: number }[], changeRows: { promotionId: number }[]) => {
  175. if (selected) {
  176. let newSelectAccData = [...selectedRows]
  177. changeRows.forEach((item: { promotionId: number }) => {
  178. let index = newSelectAccData.findIndex((ite: { promotionId: number }) => ite.promotionId === item.promotionId)
  179. if (index === -1) {
  180. newSelectAccData.push({ ...item })
  181. }
  182. })
  183. setSelectedRows([...newSelectAccData])
  184. } else {
  185. let newSelectAccData = selectedRows.filter((item: { promotionId: number }) => {
  186. let index = changeRows.findIndex((ite: { promotionId: number }) => ite.promotionId === item.promotionId)
  187. if (index !== -1) {
  188. return false
  189. } else {
  190. return true
  191. }
  192. })
  193. setSelectedRows([...newSelectAccData])
  194. }
  195. }
  196. }}
  197. />
  198. {visible && <DayAd iaaApp={initialState?.iaaApp as string} adName={adName} visible={visible} onClose={() => { setVisible(false); setPromotionId(undefined) }} queryForm={queryForm} promotionId={promotionId} />}
  199. </div>
  200. }
  201. export default TencentIaaAd