index.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import Tables from "@/components/Tables"
  2. import { useAjax } from "@/Hook/useAjax"
  3. import { getAdqLandingPageList, putAdqLandingPage } from "@/services/launchAdq/adq"
  4. import { CheckOutlined, SyncOutlined } from "@ant-design/icons"
  5. import { Button, message, Modal, Space } from "antd"
  6. import React, { useEffect, useState } from "react"
  7. import style from '../goodsModal/index.less'
  8. import columns from "./tableConfig"
  9. /**
  10. * 获取adq落地页
  11. * @returns
  12. */
  13. interface Props {
  14. cloudParams: { adcreativeTemplateId?: number }
  15. visible?: boolean,
  16. onClose?: () => void,
  17. onChange?: (data: any) => void,
  18. data: any
  19. }
  20. const PageModal: React.FC<Props> = (props) => {
  21. /*************************/
  22. const { cloudParams, visible, onClose, data: data1, onChange } = props
  23. const [selectAdz, setSelectAdz] = useState<number>(1) // 选择广告主
  24. const [data, setData] = useState<any>(data1 || [])
  25. const [queryForm, setQueryForm] = useState<{ accountId?: number, pageSize: number, pageNum: number }>({ pageNum: 1, pageSize: 20 })
  26. const [loading, setLoading] = useState<boolean>(false)
  27. const listAjax = useAjax((params) => getAdqLandingPageList(params))
  28. /*************************/
  29. useEffect(() => {
  30. if (data?.length > 0) {
  31. setQueryForm({ ...queryForm, accountId: data[selectAdz - 1].adAccountId })
  32. }
  33. }, [selectAdz])
  34. useEffect(() => {
  35. if (queryForm?.accountId) {
  36. getList()
  37. }
  38. }, [queryForm])
  39. // 获取落地页列表
  40. const getList = () => {
  41. console.log('data-->', cloudParams);
  42. listAjax.run({ ...queryForm, ...cloudParams })
  43. }
  44. const handleOk = () => {
  45. console.log('data---->', data);
  46. if (data?.every((item: { pageList: any }) => item.pageList)) {
  47. onChange && onChange(data)
  48. } else {
  49. message.error('还有账号未选择落地页!')
  50. }
  51. }
  52. /** 设置选中广告主 */
  53. const handleSelectAdz = (value: number, item: any) => {
  54. if (value === selectAdz) {
  55. return
  56. }
  57. setSelectAdz(value)
  58. }
  59. /** 表格选折 */
  60. const onChangeTable = (selectedRowKeys: React.Key[], selectedRows: any) => {
  61. let newData = JSON.parse(JSON.stringify(data))
  62. newData[selectAdz - 1]['pageList'] = selectedRows
  63. setData([...newData])
  64. }
  65. /** 同步落地页 */
  66. const synPageList = () => {
  67. setLoading(true)
  68. let ajaxs = data?.map((item: { id: number }) => putAdqLandingPage(item.id))
  69. Promise.all(ajaxs).then(res => {
  70. setLoading(false)
  71. listAjax.refresh()
  72. }).catch(() => setLoading(false))
  73. }
  74. console.log('data---->', data);
  75. return <Modal
  76. title={<Space>
  77. <span>ADQ落地页</span>
  78. <Button size="small" onClick={() => { synPageList() }} type="link" loading={loading}>同步落地页</Button>
  79. </Space>}
  80. visible={visible}
  81. onCancel={() => { onClose && onClose() }}
  82. onOk={handleOk}
  83. width={1100}
  84. className={style.SelectPackage}
  85. bodyStyle={{ padding: '0 10px 0 10px' }}
  86. >
  87. <div className={style.content}>
  88. <div className={style.left}>
  89. <h4 className={style.title}>媒体账户</h4>
  90. {data?.map((item: { adAccountId: number, id: number }, index: number) => (
  91. <div key={index} onClick={() => { handleSelectAdz(index + 1, item) }} className={`${style.accItem} ${selectAdz === index + 1 && style.select} `}>
  92. {item?.adAccountId}
  93. {data[index].pageList?.length > 0 && <CheckOutlined style={{ color: '#1890ff' }} />}
  94. </div>))}
  95. </div>
  96. <div className={style.right}>
  97. <Space style={{ marginBottom: 10 }} align="end">
  98. <Button icon={<SyncOutlined />} type='link' loading={listAjax?.loading} onClick={() => { listAjax?.refresh() }}></Button>
  99. </Space>
  100. <Tables
  101. columns={columns()}
  102. dataSource={listAjax?.data?.records?.map((item: any) => ({ ...item, id: item.pageId }))}
  103. size="small"
  104. loading={listAjax?.loading}
  105. scroll={{ y: 300 }}
  106. bordered
  107. total={listAjax?.data?.total}
  108. defaultPageSize={20}
  109. pageChange={(page: number, pageSize?: number) => {
  110. setQueryForm({ ...queryForm, pageNum: page, pageSize: pageSize as number || 20 })
  111. }}
  112. rowSelection={{
  113. type: 'radio',
  114. selectedRowKeys: data[selectAdz - 1]?.pageList?.map((item: any) => item?.id?.toString()),
  115. onChange: onChangeTable
  116. }}
  117. />
  118. </div>
  119. </div>
  120. </Modal>
  121. }
  122. export default React.memo(PageModal)