adIdSearch.tsx 9.1 KB

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