index.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { getTagsList } from "@/services/launchAdq/global"
  3. import { getsysTargetingInfo } from "@/services/launchAdq/targeting"
  4. import { Popover, Spin } from "antd"
  5. import React, { useState } from "react"
  6. import TargetingTooltip from "../targetingTooltip"
  7. import style from './index.less'
  8. /**
  9. * 表格查看信息
  10. * @returns
  11. */
  12. interface Props {
  13. id: number
  14. }
  15. const TargetingPopover: React.FC<Props> = (props) => {
  16. /***************************/
  17. const { id } = props
  18. const [visible, setVisible] = useState<boolean>(false)
  19. const [geoLocationList, setGeoLocationList] = useState<any>({}) // 所有地域列表
  20. const [modelList, setModelList] = useState<any>({}) // 所有品牌手机
  21. const tagsList_REGION = useAjax((params) => getTagsList(params))
  22. const tagsList_MODEL = useAjax((params) => getTagsList(params))
  23. const getsysTargeting = useAjax((params) => getsysTargetingInfo(params))
  24. /***************************/
  25. const handleVisibleChange = (newVisible: boolean) => {
  26. setVisible(newVisible)
  27. if (id && newVisible) {
  28. getsysTargeting.run(id)
  29. tagsList_REGION.run({ type: 'REGION' }).then(res => {
  30. if (res) {
  31. setGeoLocationList(() => (res as any[])?.reduce((prev: any, cur: { id: number }) => {
  32. prev[cur.id] = cur
  33. return prev
  34. }, {}))
  35. }
  36. })
  37. tagsList_MODEL.run({ type: 'DEVICE_BRAND_MODEL' }).then(res => {
  38. if (res) {
  39. setModelList(() => (res as any[])?.reduce((prev: any, cur: { id: number }) => {
  40. prev[cur.id] = cur
  41. return prev
  42. }, {}))
  43. }
  44. })
  45. }
  46. }
  47. return <Popover
  48. content={<Spin spinning={getsysTargeting.loading || tagsList_MODEL.loading || tagsList_REGION.loading}>
  49. <div className={style.popover}>
  50. {getsysTargeting?.data && <>
  51. <div>定向名称: <span>{getsysTargeting?.data?.targetingName}</span></div>
  52. <div>定向描述: <span>{getsysTargeting?.data?.description}</span></div>
  53. <TargetingTooltip data={getsysTargeting?.data} geoLocationList={geoLocationList} modelList={modelList} />
  54. </>}
  55. </div>
  56. </Spin>}
  57. // title="定向"
  58. trigger="click"
  59. placement="left"
  60. visible={visible}
  61. onVisibleChange={handleVisibleChange}
  62. >
  63. <a style={{ color: '#1890ff', fontSize: 12 }}>查看定向</a>
  64. </Popover>
  65. }
  66. export default React.memo(TargetingPopover)