selectPage.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { Badge, Button, Input, Modal, Space, Table, Tag, Typography } from 'antd';
  2. import React, { useEffect, useState } from 'react';
  3. import '../../tencentAdPutIn/index.less'
  4. import { getAdqLandingPageOfficialListApi } from '@/services/adqV3/global';
  5. import { useAjax } from '@/Hook/useAjax';
  6. import { SyncOutlined } from '@ant-design/icons';
  7. import { PageStatusEnum } from '@/services/launchAdq/enum';
  8. const { Text } = Typography;
  9. /**
  10. * 选择落地页
  11. * @returns
  12. */
  13. const SelectPage: React.FC<{ accountId: number, value?: any, onChange?: (e: any) => void }> = ({ accountId, value, onChange }) => {
  14. /***********************************/
  15. const [visible, setVisible] = useState<boolean>(false)
  16. const [selectedRowKeys, setSelectedRowKeys] = useState<any[]>([])
  17. const [queryForm, setQueryForm] = useState<{ accountId?: number, pageName?: string, ownerUid?: number, pageSize: number, pageNum: number, isSqDownPage: boolean }>({ pageNum: 1, pageSize: 20, isSqDownPage: false })
  18. const listAjax = useAjax((params) => getAdqLandingPageOfficialListApi(params))
  19. /***********************************/
  20. useEffect(() => {
  21. if (accountId) {
  22. const params: any = {
  23. ...queryForm,
  24. // pageStatus: 'NORMAL',
  25. pageType: 'PAGE_TYPE_OFFICIAL',
  26. accountId
  27. }
  28. delete params.isSqDownPage
  29. listAjax.run(params)
  30. }
  31. }, [accountId, queryForm])
  32. const handleOk = () => {
  33. onChange?.(selectedRowKeys?.[0])
  34. setVisible(false)
  35. }
  36. return <>
  37. <div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
  38. {value && <div style={{ flex: 1, overflow: 'hidden' }}><Text ellipsis>{Array.isArray(value) ? value.map((item: { pageName: any; pageId: any; }) => `${item.pageName}(${item.pageId})`) : `${value?.pageName}(${value?.pageId})`}</Text></div>}
  39. <Button type="primary" onClick={() => {
  40. setVisible(true)
  41. if (value) setSelectedRowKeys(Array.isArray(value) ? value : [value])
  42. else setSelectedRowKeys([])
  43. }}>选择官方落地页</Button>
  44. </div>
  45. {visible && <Modal
  46. title={<strong>官方落地页</strong>}
  47. open={visible}
  48. onOk={handleOk}
  49. onCancel={() => {
  50. setVisible(false)
  51. }}
  52. className='modalResetCss'
  53. width={750}
  54. >
  55. <Space style={{ marginBottom: 10 }}>
  56. <Input value={queryForm?.pageName} style={{ width: 150 }} allowClear placeholder='请输入落地页名称' onChange={(e) => setQueryForm({ ...queryForm, pageNum: 1, pageName: e.target.value })} />
  57. <Button style={{ padding: 0, margin: 0 }} icon={<SyncOutlined />} type='link' loading={listAjax?.loading} onClick={() => { listAjax?.refresh() }}><span style={{ fontSize: 12 }}>刷新</span></Button>
  58. </Space>
  59. <Table
  60. columns={[
  61. {
  62. title: '落地页ID',
  63. dataIndex: 'pageId',
  64. key: 'pageId',
  65. align: 'center',
  66. width: 85
  67. },
  68. {
  69. title: '落地页名称',
  70. dataIndex: 'pageName',
  71. key: 'pageName',
  72. ellipsis: true,
  73. width: 300
  74. },
  75. {
  76. title: '落地页状态',
  77. dataIndex: 'pageStatus',
  78. key: 'pageStatus',
  79. align: 'center',
  80. width: 90,
  81. render: (a: string | number) => {
  82. return <Badge status={a === 'NORMAL' ? "success" : a === 'DELETED' ? "error" : 'processing'} text={PageStatusEnum[a as keyof typeof PageStatusEnum]} />
  83. }
  84. },
  85. ]}
  86. dataSource={listAjax?.data?.records}
  87. size="small"
  88. loading={listAjax?.loading}
  89. scroll={{ y: 400 }}
  90. bordered
  91. rowKey={'pageId'}
  92. pagination={{
  93. total: listAjax?.data?.total,
  94. defaultPageSize: 20,
  95. current: listAjax?.data?.current,
  96. pageSize: listAjax?.data?.size
  97. }}
  98. onChange={(pagination) => {
  99. const { current, pageSize } = pagination
  100. setQueryForm({ ...queryForm, pageNum: current as number, pageSize: pageSize as number || 20 })
  101. }}
  102. rowSelection={{
  103. selectedRowKeys: selectedRowKeys?.map((item: any) => item?.pageId),
  104. type: 'radio',
  105. onChange(selectedRowKeys, selectedRows, info) {
  106. setSelectedRowKeys(selectedRows)
  107. },
  108. }}
  109. />
  110. </Modal>}
  111. </>;
  112. };
  113. export default SelectPage;