adIdSearch.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import { Button, Progress, Select, Space, Statistic, Table, Tag } from "antd"
  2. import React, { useEffect, useState } from "react"
  3. import style from './index.less'
  4. import Draggable from "react-draggable"
  5. import { CloseCircleOutlined, SearchOutlined, SyncOutlined } from "@ant-design/icons"
  6. import { allPlanProps, getAllPlanListApi } from "@/services/adMonitor/adMonitor"
  7. import { useAjax } from "@/Hook/useAjax"
  8. import { ColumnsType } from "antd/lib/table"
  9. import { GGStateData } from "@/pages/adMonitor/adMonitorList/data"
  10. import { GUANGGAOZHUANGTAI } from "@/pages/adMonitor/adMonitorList/enum"
  11. import SearchSelect from "./searchSelect"
  12. import moment from "moment"
  13. import { getAdAccountApi } from "@/services/launchAdq/adAuthorize"
  14. interface Props {
  15. userId: string
  16. onChange?: (adidList?: number[]) => void
  17. }
  18. /**
  19. * 开启监控过滤
  20. * @returns
  21. */
  22. const AdIdSearch: React.FC<Props> = ({ userId, onChange }) => {
  23. /***************************/
  24. const [show, setShow] = useState<boolean>(false)
  25. const [editSelectedRow, setEditSelectedRow] = useState<any[]>([])
  26. const [queryFrom, setQueryForm] = useState<allPlanProps>({ pageNum: 1, pageSize: 20, createStartTime: moment().subtract(3, 'days').format('YYYY-MM-DD'), createEndTime: moment().format('YYYY-MM-DD') })
  27. const getAllPlanList = useAjax((params) => getAllPlanListApi(params))
  28. // 获取广告账号列表
  29. const getAdqAccountList = useAjax(() => getAdAccountApi(), { formatResult: true })
  30. /***************************/
  31. useEffect(() => {
  32. if (show) {
  33. getAllPlanList.run({ sysUserId: [userId], ...queryFrom })
  34. }
  35. }, [userId, show, queryFrom])
  36. const open = () => {
  37. setShow(true)
  38. getAdqAccountList.run()
  39. }
  40. const handleOk = () => {
  41. onChange?.(editSelectedRow)
  42. }
  43. return <>
  44. <Button onClick={() => open()}>开启监控过滤</Button>
  45. {show && <Draggable>
  46. <div className={`floating-window MYtable ${style.searchModal}`}>
  47. <div className={style.close} onClick={() => setShow(false)}><CloseCircleOutlined /></div>
  48. <Space>
  49. <Select
  50. showSearch
  51. mode='multiple'
  52. maxTagCount={1}
  53. value={queryFrom.accountId}
  54. style={{ minWidth: 140, maxWidth: 250 }}
  55. allowClear
  56. placeholder="请选择广告账号"
  57. onChange={(value: number[]) => {
  58. setQueryForm({ ...queryFrom, accountId: value, pageNum: 1 })
  59. }}
  60. >
  61. {getAdqAccountList?.data?.data?.map((item: { id: number, accountId: number }) => <Select.Option
  62. value={item.accountId}
  63. key={item.id}
  64. >
  65. {item.accountId}
  66. </Select.Option>)}
  67. </Select>
  68. <Select style={{ width: 140 }} placeholder="请选择广告状态" value={queryFrom.adStatus} onChange={(value: number) => {
  69. setQueryForm({ ...queryFrom, pageNum: 1, adStatus: value })
  70. }} allowClear>
  71. {Object.keys(GUANGGAOZHUANGTAI).map(key => {
  72. return <Select.Option value={key} key={key}>{GUANGGAOZHUANGTAI[key]}</Select.Option>
  73. })}
  74. </Select>
  75. <SearchSelect queryFrom={queryFrom} setQueryForm={setQueryForm} />
  76. <Button type="link" icon={<SyncOutlined />} style={{ padding: 0 }} onClick={() => getAllPlanList?.refresh()}>刷新</Button>
  77. </Space>
  78. <Table
  79. size="small"
  80. loading={getAllPlanList.loading}
  81. dataSource={getAllPlanList?.data?.records}
  82. columns={columns}
  83. rowKey={'id'}
  84. scroll={{ x: 300, y: 200 }}
  85. pagination={{
  86. total: getAllPlanList?.data?.total,
  87. showTotal: (total) => <Tag color="cyan">总共{total}数据</Tag>,
  88. current: getAllPlanList?.data?.current || 1,
  89. pageSize: getAllPlanList?.data?.size || 20,
  90. }}
  91. rowSelection={{
  92. selectedRowKeys: editSelectedRow,
  93. onChange: (selectedRowKeys: React.Key[], selectedRows: any[]) => {
  94. console.log(selectedRowKeys, selectedRows)
  95. setEditSelectedRow(selectedRowKeys)
  96. }
  97. }}
  98. onChange={(pagination, filters, sortData: any) => {
  99. let { current, pageSize } = pagination
  100. let newQueryForm = JSON.parse(JSON.stringify(queryFrom))
  101. newQueryForm.pageNum = current
  102. newQueryForm.pageSize = pageSize
  103. if (sortData && JSON.stringify('sortData') !== '{}') {
  104. let { field, order } = sortData // descend 降序 大到小 ascend 升序 小到大
  105. if (order) {
  106. newQueryForm.sortField = field
  107. newQueryForm.sort = order === 'ascend' ? 'ASC' : 'DESC'
  108. } else {
  109. Object.keys(newQueryForm).forEach(key => {
  110. if (key === 'sortField' || key === 'sort') {
  111. delete newQueryForm[key]
  112. }
  113. })
  114. }
  115. } else {
  116. Object.keys(newQueryForm).forEach(key => {
  117. if (key === 'sortField' || key === 'sort') {
  118. delete newQueryForm[key]
  119. }
  120. })
  121. }
  122. setQueryForm({ ...newQueryForm })
  123. }}
  124. />
  125. {editSelectedRow?.length > 0 && <div className={style.bts}>
  126. <Button icon={<SearchOutlined />} type="primary" onClick={() => handleOk()} />
  127. </div>}
  128. </div>
  129. </Draggable>}
  130. </>
  131. }
  132. const columns: ColumnsType<any> = [
  133. {
  134. title: '广告ID',
  135. dataIndex: 'adgroupId',
  136. key: 'adgroupId',
  137. align: 'center',
  138. width: 90,
  139. fixed: 'left',
  140. ellipsis: true
  141. },
  142. {
  143. title: '广告状态',
  144. dataIndex: 'adStatus',
  145. key: 'adStatus',
  146. align: 'center',
  147. width: 90,
  148. ellipsis: true,
  149. render: (a: any) => {
  150. return GGStateData[a] || '--'
  151. }
  152. },
  153. {
  154. title: '广告总消耗',
  155. dataIndex: 'cost',
  156. key: 'cost',
  157. align: 'center',
  158. width: 100,
  159. ellipsis: true,
  160. sorter: true,
  161. render: (a: any) => {
  162. return <div style={{ height: 26, position: 'relative' }}>
  163. <Progress
  164. strokeColor={{
  165. from: '#10c1e9',
  166. to: '#6892d0',
  167. }}
  168. status="active"
  169. showInfo={false}
  170. percent={a ? a / 3000 * 100 : 0}
  171. />
  172. <span style={{ position: 'absolute', left: 0, top: 2, bottom: 0, right: 0 }}><Statistic value={a || 0} valueStyle={a >= 30000 ? { color: '#000', fontWeight: 500 } : { fontWeight: 500 }} /></span>
  173. </div>
  174. }
  175. },
  176. {
  177. title: '曝光量',
  178. dataIndex: 'viewCount',
  179. key: 'viewCount',
  180. align: 'center',
  181. width: 75,
  182. sorter: true,
  183. ellipsis: true,
  184. render: (a: number) => {
  185. return <span style={a <= 8 ? { color: '#0f990f', fontWeight: 600 } : a >= 100 ? { color: 'red', fontWeight: 600 } : {}}> {a || '--'}</span >
  186. },
  187. },
  188. {
  189. title: '下单量',
  190. dataIndex: 'orderCount',
  191. key: 'orderCount',
  192. align: 'center',
  193. width: 75,
  194. sorter: true,
  195. ellipsis: true,
  196. render: (a: any) => {
  197. return <Statistic value={a || 0} />
  198. }
  199. },
  200. {
  201. title: '千次曝光成本',
  202. dataIndex: 'thousandDisplayPrice',
  203. key: 'thousandDisplayPrice',
  204. align: 'center',
  205. width: 95,
  206. // sorter: true,
  207. ellipsis: true,
  208. render: (a: any) => {
  209. return <Statistic value={a ? a?.toFixed(2) : 0} />
  210. }
  211. },
  212. {
  213. title: '点击量',
  214. dataIndex: 'clickCount',
  215. key: 'clickCount',
  216. align: 'center',
  217. width: 70,
  218. sorter: true,
  219. ellipsis: true,
  220. render: (a: number) => {
  221. return <span style={a <= 8 ? { color: '#0f990f', fontWeight: 600 } : a >= 100 ? { color: 'red', fontWeight: 600 } : {}}> {a || '--'}</span >
  222. },
  223. },
  224. ];
  225. export default React.memo(AdIdSearch)