pageTieUp.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import { useAjax } from '@/Hook/useAjax';
  2. import { delPageCustomerGroupApi, getAdqLandingPageOfficialListApi, getCorpRelationAllApi, getCustomerServiceGroupListApi, getPageCustomerGroupListApi, GetPageCustomerGroupListProps } from '@/services/adqV3/global';
  3. import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
  4. import { Button, Input, message, Popconfirm, Select, Table } from 'antd';
  5. import React, { useEffect, useState } from 'react';
  6. import AddPageTieUp from './addPageTieUp';
  7. import { useDebounce } from 'ahooks';
  8. /**
  9. * 落地页与客服组关系
  10. * @returns
  11. */
  12. const PageTieUp: React.FC<{ adAccountId?: number }> = ({ adAccountId }) => {
  13. /*******************************/
  14. const [queryParamsNew, setQueryParamsNew] = useState<GetPageCustomerGroupListProps>({ pageNum: 1, pageSize: 50, adAccountId: 0 })
  15. const [visible, setVisible] = useState<boolean>(false)
  16. const [corpList, setCorpList] = useState<{ label: string, value: string }[]>([])
  17. const [groupList, setGroupList] = useState<{ label: string, value: number }[]>([])
  18. const [queryForm, setQueryForm] = useState<{ accountId?: number, pageName?: string, ownerUid?: number, pageSize: number, pageNum: number, isSqDownPage: boolean }>({ pageNum: 1, pageSize: 20, isSqDownPage: false })
  19. const [pageName, setPageName] = useState<string>();
  20. const debouncedValue = useDebounce(pageName, { wait: 500 });
  21. const getPageCustomerGroupList = useAjax((params) => getPageCustomerGroupListApi(params))
  22. const delPageCustomerGroup = useAjax((params) => delPageCustomerGroupApi(params))
  23. const getCorpRelationAll = useAjax((params) => getCorpRelationAllApi(params))
  24. const getCustomerServiceGroupList = useAjax((params) => getCustomerServiceGroupListApi(params))
  25. const listAjax = useAjax((params) => getAdqLandingPageOfficialListApi(params))
  26. /*******************************/
  27. // 落地页
  28. useEffect(() => {
  29. if (adAccountId) {
  30. const params: any = {
  31. ...queryForm,
  32. // pageStatus: 'NORMAL',
  33. pageType: 'PAGE_TYPE_OFFICIAL',
  34. accountId: adAccountId,
  35. pageName: debouncedValue
  36. }
  37. delete params.isSqDownPage
  38. listAjax.run(params)
  39. }
  40. }, [adAccountId, queryForm, debouncedValue])
  41. /** 客服组 */
  42. useEffect(() => {
  43. if (adAccountId) {
  44. getCustomerServiceGroupList.run({ adAccountId, pageNum: 1, pageSize: 100, tencentCorpId: queryParamsNew?.tencentCorpId }).then(res => {
  45. setGroupList(res?.records?.map((item: { groupName: string; groupId: number; }) => ({ label: item.groupName, value: item.groupId })))
  46. }).catch(() => setGroupList([]))
  47. }
  48. }, [adAccountId, queryParamsNew?.tencentCorpId])
  49. /** 企业列表 */
  50. useEffect(() => {
  51. if (adAccountId) {
  52. getCorpRelationAll.run({ adAccountId }).then(res => {
  53. setCorpList(res?.map((item: { corpName: string; tencentCorpId: string; }) => ({ label: item.corpName, value: item.tencentCorpId })))
  54. }).catch(() => setCorpList([]))
  55. }
  56. }, [adAccountId])
  57. /** 获取关系列表 */
  58. useEffect(() => {
  59. if (adAccountId) {
  60. getPageCustomerGroupList.run({ ...queryParamsNew, adAccountId })
  61. }
  62. }, [adAccountId, queryParamsNew])
  63. /**
  64. * 删除
  65. * @param id
  66. */
  67. const handleDel = (id: number) => {
  68. delPageCustomerGroup.run(id).then((res) => {
  69. if (res) {
  70. message.success('删除成功')
  71. getPageCustomerGroupList.refresh()
  72. }
  73. })
  74. }
  75. return <>
  76. <div className="flexStart" style={{ gap: 8, marginBottom: 16 }}>
  77. <Select
  78. showSearch
  79. placeholder="请选择企业"
  80. filterOption={(input, option) =>
  81. ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
  82. }
  83. style={{ width: 200 }}
  84. allowClear
  85. value={queryParamsNew?.tencentCorpId}
  86. loading={getCorpRelationAll.loading}
  87. onChange={(e) => {
  88. setQueryParamsNew({ ...queryParamsNew, tencentCorpId: e, pageNum: 1 })
  89. }}
  90. options={corpList}
  91. />
  92. <Select
  93. showSearch
  94. placeholder="请选择客服组"
  95. filterOption={(input, option) =>
  96. ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
  97. }
  98. style={{ width: 200 }}
  99. allowClear
  100. value={queryParamsNew?.customerGroupId}
  101. loading={getCustomerServiceGroupList.loading}
  102. onChange={(e) => {
  103. setQueryParamsNew({ ...queryParamsNew, customerGroupId: e, pageNum: 1 })
  104. }}
  105. options={groupList}
  106. />
  107. <Input style={{ width: 140 }} value={queryParamsNew?.customerGroupName} onChange={(e) => setQueryParamsNew({ ...queryParamsNew, pageNum: 1, customerGroupName: e.target.value })} placeholder='客服组名称' />
  108. <Select
  109. showSearch
  110. placeholder="请选择落地页"
  111. filterOption={false}
  112. style={{ width: 200 }}
  113. allowClear
  114. value={queryParamsNew?.pageId}
  115. loading={listAjax.loading}
  116. onChange={(e) => {
  117. setQueryParamsNew({ ...queryParamsNew, pageId: e, pageNum: 1 })
  118. }}
  119. defaultActiveFirstOption={false}
  120. showArrow={false}
  121. onSearch={(newValue: string) => {
  122. setPageName(newValue)
  123. }}
  124. options={listAjax?.data?.records?.map((item: { pageId: number; pageName: string; }) => ({ label: item.pageName, value: item.pageId }))}
  125. />
  126. <Button type="primary" icon={<SearchOutlined />} loading={getPageCustomerGroupList.loading} onClick={() => getPageCustomerGroupList.refresh()}>刷新</Button>
  127. <Button
  128. type="primary"
  129. icon={<PlusOutlined />}
  130. onClick={() => {
  131. setVisible(true)
  132. }}
  133. >新增</Button>
  134. </div>
  135. <Table
  136. columns={[
  137. {
  138. title: '广告账号',
  139. dataIndex: 'adAccountId',
  140. key: 'adAccountId',
  141. width: 90,
  142. ellipsis: true,
  143. align: 'center',
  144. render(value) {
  145. return <span style={{ fontSize: 12 }}>{value}</span>
  146. },
  147. },
  148. {
  149. title: '落地页名称',
  150. dataIndex: 'pageName',
  151. key: 'pageName',
  152. width: 120,
  153. ellipsis: true,
  154. render(value) {
  155. return <span style={{ fontSize: 12 }}>{value}</span>
  156. },
  157. },
  158. {
  159. title: '落地页ID',
  160. dataIndex: 'pageId',
  161. key: 'pageId',
  162. width: 100,
  163. ellipsis: true,
  164. align: 'center',
  165. render(value) {
  166. return <span style={{ fontSize: 12 }}>{value}</span>
  167. },
  168. },
  169. {
  170. title: '客服组名称',
  171. dataIndex: 'customerGroupName',
  172. key: 'customerGroupName',
  173. width: 120,
  174. ellipsis: true,
  175. render(value) {
  176. return <span style={{ fontSize: 12 }}>{value}</span>
  177. },
  178. },
  179. {
  180. title: '客服组ID',
  181. dataIndex: 'customerGroupId',
  182. key: 'customerGroupId',
  183. align: 'center',
  184. width: 100,
  185. ellipsis: true,
  186. render(value) {
  187. return <span style={{ fontSize: 12 }}>{value}</span>
  188. },
  189. },
  190. {
  191. title: '投放端企业ID',
  192. dataIndex: 'tencentCorpId',
  193. key: 'tencentCorpId',
  194. width: 300,
  195. ellipsis: true,
  196. render(value) {
  197. return <span style={{ fontSize: 12 }}>{value}</span>
  198. },
  199. },
  200. {
  201. title: '操作',
  202. dataIndex: 'cz',
  203. key: 'cz',
  204. width: 300,
  205. render(_, record) {
  206. return <Popconfirm
  207. title="确定删除?"
  208. onConfirm={() => handleDel(record.id)}
  209. >
  210. <a style={{ color: 'red', fontSize: 12 }}>删除</a>
  211. </Popconfirm>
  212. },
  213. },
  214. ]}
  215. dataSource={getPageCustomerGroupList.data?.records || []}
  216. loading={getPageCustomerGroupList.loading}
  217. scroll={{ x: 1000 }}
  218. pagination={{
  219. current: queryParamsNew.pageNum,
  220. pageSize: queryParamsNew.pageSize,
  221. total: getPageCustomerGroupList.data?.total,
  222. onChange: (pageNum, pageSize) => setQueryParamsNew({ ...queryParamsNew, pageNum, pageSize }),
  223. }}
  224. size="small"
  225. bordered
  226. rowKey="id"
  227. />
  228. {/* 新增 */}
  229. {visible && <AddPageTieUp
  230. adAccountId={adAccountId as number}
  231. corpList={corpList}
  232. visible={visible}
  233. onChange={() => {
  234. getPageCustomerGroupList.refresh()
  235. setVisible(false)
  236. }}
  237. onClose={() => {
  238. setVisible(false)
  239. }}
  240. />}
  241. </>;
  242. };
  243. export default React.memo(PageTieUp);