index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import QueryForm from "@/components/QueryForm";
  2. import TablePro from "@/components/TablePro";
  3. import { Button, message, Modal, Space, Table } from "antd";
  4. import React, { useEffect, useState } from "react"
  5. import { useModel } from "umi";
  6. import moment from "moment";
  7. import { getByteAdListApi, GetByteAdListProps, getByteAdTotalApi } from "@/services/iaaData";
  8. import { useAjax } from "@/Hook/useAjax";
  9. import columns12 from "./tableConfig";
  10. import { PauseCircleOutlined, PlayCircleOutlined } from "@ant-design/icons";
  11. import DayAd from "./dayAd";
  12. import { newEditTTAdgroupsDataApi } from "@/services/gameData";
  13. /**
  14. * 头条广告列表
  15. * @returns
  16. */
  17. const AdList: React.FC = () => {
  18. /****************************************/
  19. const { initialState } = useModel('@@initialState');
  20. const [selectedRows, setSelectedRows] = useState<any[]>([])
  21. const [queryForm, setQueryForm] = useState<GetByteAdListProps>({
  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 [failIdList, setFailIdList] = useState<{ adgroupId: number, code: number, message: string, messageCn: string }[]>([])
  32. const [failVisible, setFailVisible] = useState<boolean>(false)
  33. // const editAdqAdgroupsData = useAjax((params) => newEditAdqAdgroupsDataApi(params))
  34. const getByteAdList = useAjax((params) => getByteAdListApi(params))
  35. const getByteAdTotal = useAjax((params) => getByteAdTotalApi(params))
  36. const newEditTTAdgroupsData = useAjax((params) => newEditTTAdgroupsDataApi(params))
  37. /****************************************/
  38. useEffect(() => {
  39. if (initialState?.iaaApp?.length && initialState?.productType) {
  40. getByteAdList.run({ ...queryForm, appId: initialState.iaaApp, productType: initialState.productType })
  41. getByteAdTotal.run({ ...queryForm, appId: initialState.iaaApp, productType: initialState.productType }).then((res: { data: { id: number; accountId: string } }) => {
  42. if (res?.data) {
  43. let data = res?.data
  44. data.id = 1
  45. data.accountId = '总计'
  46. setTotalData([data])
  47. } else {
  48. setTotalData([{ id: 1, accountId: '总计' }])
  49. }
  50. })
  51. }
  52. }, [queryForm, initialState?.iaaApp, initialState?.productType])
  53. const dayHandle = (data: any) => {
  54. setVisible(true)
  55. setAdName(data.adName)
  56. setPromotionId(data.adId)
  57. }
  58. // 批量启停
  59. const adStatus = (type: 'play' | 'suspend') => {
  60. let params: any = {}
  61. params.suspend = type === 'play' ? false : true
  62. params.adgroupIds = selectedRows.map(item => item.accountId + ',' + item.adId)
  63. if (params.adgroupIds.length === 0) {
  64. message.warn(`所以账号都是${type === 'play' ? '启动' : '暂停'}状态,无需${type === 'play' ? '启动' : '暂停'}操作`)
  65. return
  66. }
  67. let hide = message.loading(`正在设置...`, 0, () => {
  68. message.success('设置成功');
  69. });
  70. newEditTTAdgroupsData.run(params).then((res: any) => {
  71. if (res?.failIdList?.length === 0) {
  72. message.success(`操作完成!`)
  73. getByteAdList.refresh()
  74. setSelectedRows([])
  75. } else {
  76. setFailIdList(res?.list || [])
  77. setFailVisible(true)
  78. }
  79. hide()
  80. })
  81. }
  82. return <div>
  83. <TablePro
  84. czChild={<Space>
  85. {/* <Switch checkedChildren="开启全选" unCheckedChildren="关闭全选" checked={!isZj} onChange={(e) => { setIsZj(!e); }} /> */}
  86. <Button type='primary' size="small" style={{ background: '#67c23a', borderColor: '#67c23a' }} loading={newEditTTAdgroupsData.loading} icon={<PlayCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('play')}>启动</Button>
  87. <Button type='primary' size="small" style={{ background: '#e6a23c', borderColor: '#e6a23c' }} loading={newEditTTAdgroupsData.loading} icon={<PauseCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('suspend')}>暂停</Button>
  88. <span style={{ color: 'red' }}>操作完数据结果延时5分钟之内,即时结果去腾讯后台查看</span>
  89. </Space>}
  90. leftChild={<QueryForm
  91. initialValues={{ day3: [moment(), moment()] }}
  92. isAccountId
  93. isPromotionName
  94. isPutUserIdList
  95. isCpaBid
  96. isDeleted
  97. isTTPricing
  98. isTTStatus
  99. isPromotionId
  100. day1={{ placeholder: ['广告创建日期开始', '广告创建日期结束'] }}
  101. day2={{ placeholder: ['投放日期开始', '投放日期结束'] }}
  102. day3={{ placeholder: ['消耗日期开始', '消耗日期结束'] }}
  103. onChange={(data: any) => {
  104. console.log(data)
  105. const { promotionId, promotionName, day1, day2, day3, ...params } = data
  106. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  107. newQueryForm.adId = promotionId
  108. newQueryForm.adName = promotionName
  109. newQueryForm.pageNum = 1
  110. if (day1 && day1?.length === 2) {
  111. newQueryForm['adCreateBegin'] = moment(day1[0]).format('YYYY-MM-DD')
  112. newQueryForm['adCreateEnd'] = moment(day1[1]).format('YYYY-MM-DD')
  113. } else {
  114. delete newQueryForm['adCreateBegin']
  115. delete newQueryForm['adCreateEnd']
  116. }
  117. if (day2 && day2?.length === 2) {
  118. newQueryForm['putDayBegin'] = moment(day2[0]).format('YYYY-MM-DD')
  119. newQueryForm['putDayEnd'] = moment(day2[1]).format('YYYY-MM-DD')
  120. } else {
  121. delete newQueryForm['putDayBegin']
  122. delete newQueryForm['putDayEnd']
  123. }
  124. if (day3 && day3?.length === 2) {
  125. newQueryForm['costDayBegin'] = moment(day3[0]).format('YYYY-MM-DD')
  126. newQueryForm['costDayEnd'] = moment(day3[1]).format('YYYY-MM-DD')
  127. } else {
  128. delete newQueryForm['costDayBegin']
  129. delete newQueryForm['costDayEnd']
  130. }
  131. setQueryForm({ ...newQueryForm, ...params })
  132. }}
  133. />}
  134. isZj
  135. totalData={totalData}
  136. config={columns12(dayHandle)}
  137. configName={'头条广告列表'}
  138. fixed={{ left: 4, right: 2 }}
  139. scroll={{ x: 1000, y: 620 }}
  140. title='头条广告列表'
  141. loading={getByteAdList.loading}
  142. ajax={getByteAdList}
  143. page={getByteAdList?.data?.data?.current || 1}
  144. pageSize={getByteAdList?.data?.data?.size || 20}
  145. total={getByteAdList?.data?.data?.total || 0}
  146. dataSource={getByteAdList?.data?.data?.records?.map((item: any, index: number) => ({ ...item, id: item.adId.toString(16) }))}
  147. rowKey={'id'}
  148. onChange={(pagination: any, _: any, sortData: any) => {
  149. let { current, pageSize } = pagination
  150. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  151. if (sortData && sortData?.order) {
  152. newQueryForm['sortAsc'] = sortData?.order === 'ascend' ? true : false
  153. newQueryForm['sortFiled'] = sortData?.field
  154. } else {
  155. delete newQueryForm['sortAsc']
  156. delete newQueryForm['sortFiled']
  157. }
  158. newQueryForm.pageNum = current || newQueryForm.pageNum
  159. newQueryForm.pageSize = pageSize || newQueryForm.pageSize
  160. setQueryForm({ ...newQueryForm })
  161. }}
  162. rowSelection={{
  163. selectedRowKeys: selectedRows.map(item => item.id),
  164. getCheckboxProps: (record: any) => ({
  165. disabled: record.adStatus === 'PROJECT_STATUS_DELETE' || record?.accountId === '总计'
  166. }),
  167. onSelect: (record: { adId: string }, selected: boolean) => {
  168. if (selected) {
  169. selectedRows.push({ ...record })
  170. setSelectedRows([...selectedRows])
  171. } else {
  172. let newSelectAccData = selectedRows.filter((item: { adId: string }) => item.adId !== record.adId)
  173. setSelectedRows([...newSelectAccData])
  174. }
  175. },
  176. onSelectAll: (selected: boolean, selectedRowss: { adId: number }[], changeRows: { adId: number }[]) => {
  177. if (selected) {
  178. let newSelectAccData = [...selectedRows]
  179. changeRows.forEach((item: { adId: number }) => {
  180. let index = newSelectAccData.findIndex((ite: { adId: number }) => ite.adId === item.adId)
  181. if (index === -1) {
  182. newSelectAccData.push({ ...item })
  183. }
  184. })
  185. setSelectedRows([...newSelectAccData])
  186. } else {
  187. let newSelectAccData = selectedRows.filter((item: { adId: number }) => {
  188. let index = changeRows.findIndex((ite: { adId: number }) => ite.adId === item.adId)
  189. if (index !== -1) {
  190. return false
  191. } else {
  192. return true
  193. }
  194. })
  195. setSelectedRows([...newSelectAccData])
  196. }
  197. }
  198. }}
  199. />
  200. {visible && <DayAd appId={initialState?.iaaApp as number[]} productType={initialState?.productType as string} adName={adName} visible={visible} onClose={() => { setVisible(false); setPromotionId(undefined) }} queryForm={queryForm} promotionId={promotionId} />}
  201. {failVisible && <Modal
  202. title={<strong>报错信息</strong>}
  203. open={failVisible}
  204. className='modalResetCss'
  205. width={650}
  206. onCancel={() => { setFailVisible(false); setFailIdList([]) }}
  207. footer={null}
  208. >
  209. <Table
  210. size="small"
  211. bordered
  212. rowKey={'creativeId'}
  213. columns={[{
  214. title: '创意ID',
  215. dataIndex: 'creativeId',
  216. key: 'creativeId',
  217. width: 110,
  218. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  219. }, {
  220. title: 'code',
  221. dataIndex: 'code',
  222. key: 'code',
  223. width: 70,
  224. align: 'center',
  225. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  226. }, {
  227. title: '错误信息',
  228. dataIndex: 'messageCn',
  229. key: 'messageCn',
  230. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  231. }]}
  232. dataSource={failIdList}
  233. />
  234. </Modal>}
  235. </div>
  236. }
  237. export default AdList