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. if (day1 && day1?.length === 2) {
  109. newQueryForm['adCreateBegin'] = moment(day1[0]).format('YYYY-MM-DD')
  110. newQueryForm['adCreateEnd'] = moment(day1[1]).format('YYYY-MM-DD')
  111. } else {
  112. delete newQueryForm['adCreateBegin']
  113. delete newQueryForm['adCreateEnd']
  114. }
  115. if (day2 && day2?.length === 2) {
  116. newQueryForm['putDayBegin'] = moment(day2[0]).format('YYYY-MM-DD')
  117. newQueryForm['putDayEnd'] = moment(day2[1]).format('YYYY-MM-DD')
  118. } else {
  119. delete newQueryForm['putDayBegin']
  120. delete newQueryForm['putDayEnd']
  121. }
  122. if (day3 && day3?.length === 2) {
  123. newQueryForm['costDayBegin'] = moment(day3[0]).format('YYYY-MM-DD')
  124. newQueryForm['costDayEnd'] = moment(day3[1]).format('YYYY-MM-DD')
  125. } else {
  126. delete newQueryForm['costDayBegin']
  127. delete newQueryForm['costDayEnd']
  128. }
  129. setQueryForm({ ...newQueryForm, ...params })
  130. }}
  131. />}
  132. isZj
  133. totalData={totalData}
  134. config={columns12(dayHandle, () => { getGDTList.refresh() })}
  135. configName={'腾讯广告列表'}
  136. fixed={{ left: 4, right: 2 }}
  137. scroll={{ x: 1000, y: 620 }}
  138. title='腾讯广告列表'
  139. loading={getGDTList.loading}
  140. ajax={getGDTList}
  141. page={getGDTList?.data?.data?.current || 1}
  142. pageSize={getGDTList?.data?.data?.size || 20}
  143. total={getGDTList?.data?.data?.total || 0}
  144. dataSource={getGDTList?.data?.data?.records?.map((item: any, index: number) => ({ ...item, id: Number(queryForm.pageNum.toString() + (index + '')) }))}
  145. onChange={(pagination: any, _: any, sortData: any) => {
  146. let { current, pageSize } = pagination
  147. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  148. if (sortData && sortData?.order) {
  149. newQueryForm['sortAsc'] = sortData?.order === 'ascend' ? true : false
  150. newQueryForm['sortFiled'] = sortData?.field
  151. } else {
  152. delete newQueryForm['sortAsc']
  153. delete newQueryForm['sortFiled']
  154. }
  155. newQueryForm.pageNum = current || newQueryForm.pageNum
  156. newQueryForm.pageSize = pageSize || newQueryForm.pageSize
  157. setQueryForm({ ...newQueryForm })
  158. }}
  159. rowSelection={{
  160. selectedRowKeys: selectedRows.map(item => item.promotionId + ''),
  161. getCheckboxProps: (record: any) => ({
  162. disabled: record.status === 'STATUS_DELETED' || record?.accountId === '总计'
  163. }),
  164. onSelect: (record: { promotionId: number }, selected: boolean) => {
  165. if (selected) {
  166. selectedRows.push({ ...record })
  167. setSelectedRows([...selectedRows])
  168. } else {
  169. let newSelectAccData = selectedRows.filter((item: { promotionId: number }) => item.promotionId !== record.promotionId)
  170. setSelectedRows([...newSelectAccData])
  171. }
  172. },
  173. onSelectAll: (selected: boolean, selectedRowss: { promotionId: number }[], changeRows: { promotionId: number }[]) => {
  174. if (selected) {
  175. let newSelectAccData = [...selectedRows]
  176. changeRows.forEach((item: { promotionId: number }) => {
  177. let index = newSelectAccData.findIndex((ite: { promotionId: number }) => ite.promotionId === item.promotionId)
  178. if (index === -1) {
  179. newSelectAccData.push({ ...item })
  180. }
  181. })
  182. setSelectedRows([...newSelectAccData])
  183. } else {
  184. let newSelectAccData = selectedRows.filter((item: { promotionId: number }) => {
  185. let index = changeRows.findIndex((ite: { promotionId: number }) => ite.promotionId === item.promotionId)
  186. if (index !== -1) {
  187. return false
  188. } else {
  189. return true
  190. }
  191. })
  192. setSelectedRows([...newSelectAccData])
  193. }
  194. }
  195. }}
  196. />
  197. {visible && <DayAd iaaApp={initialState?.iaaApp as string} adName={adName} visible={visible} onClose={() => { setVisible(false); setPromotionId(undefined) }} queryForm={queryForm} promotionId={promotionId} />}
  198. </div>
  199. }
  200. export default TencentIaaAd