index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import React, { useState, useEffect, useCallback } from 'react'
  2. import { Badge, Card, Col, Menu, Row, Select, Tabs, Tag } from 'antd';
  3. // import './index.less'
  4. import Campaign from './campaign';
  5. import AdAccount from './adAccount';
  6. import Ad from './ad';
  7. import Creative from './creative';
  8. import LandingPage from './landingPage';
  9. import { getAdAccountAllOfMember } from '@/services/launchAdq/adq';
  10. import Targeting from './targeting';
  11. import { useAjax } from '@/Hook/useAjax';
  12. import { IdcardFilled } from '@ant-design/icons';
  13. import { useModel } from 'umi';
  14. const { TabPane } = Tabs;
  15. let Menus: any = Menu
  16. const tabsConfig = [
  17. { key: '1', tab: '账户信息', jsx: (props: any) => <AdAccount {...props} /> },
  18. { key: '2', tab: '计划', jsx: (props: any) => <Campaign {...props} /> },
  19. { key: '3', tab: '广告', jsx: (props: any) => <Ad {...props} /> },
  20. { key: '4', tab: '创意', jsx: (props: any) => <Creative {...props} /> },
  21. { key: '5', tab: '落地页', jsx: (props: any) => <LandingPage {...props} /> },
  22. { key: '6', tab: '定向', jsx: (props: any) => <Targeting {...props} /> },
  23. ]
  24. function Adq() {
  25. const userInfo = useModel('@@initialState', model => model.initialState?.currentUser)
  26. const allOfMember = useAjax(() => getAdAccountAllOfMember(), { formatResult: true })
  27. const [userAll, setUserAll] = useState([])
  28. const [activeKey, setActiveKey] = useState('1')
  29. const [userId, setUserId] = useState<any>(userInfo?.userId?.toString())
  30. const [selectedArr, setSelectedArr] = useState([])
  31. const [queryParmas, setQueryParmas] = useState<any>({
  32. accountId: undefined,//账户ID
  33. campaignId: undefined,//计划ID
  34. adgroupId: undefined,//广告ID
  35. adcreativeId: undefined,//创意ID
  36. pageId: undefined,//落地页ID
  37. targetingId: undefined,//定向ID
  38. })
  39. const [idS, setIds] = useState({//需要用到的accountId,adAccountId
  40. accountId: '',
  41. adAccountId: ''
  42. })
  43. // 点击table中的ID添加对应条件
  44. const tableIdClick = useCallback((props: {
  45. activeKey: string,
  46. parma: {
  47. accountId?: string,//账户ID
  48. campaignId?: string,//计划ID
  49. adgroupId?: string,//广告ID
  50. adcreativeId?: string,//创意ID
  51. pageId?: string,//落地页ID
  52. targetingId?: string,//定向ID
  53. }
  54. }) => {
  55. // 暂时注释不开放
  56. let { activeKey, parma } = props
  57. setQueryParmas({ ...queryParmas, ...parma })
  58. setActiveKey(activeKey)
  59. }, [queryParmas, activeKey])
  60. // 获取组员
  61. useEffect(() => {
  62. allOfMember.run().then(res => {
  63. if (res?.data) {
  64. let useAll: any = []
  65. res?.data?.forEach((item: { key: { userId: any; nickName: any; }; value: any[]; }) => {
  66. let obj = {
  67. key: item.key.userId,
  68. label: item.key.nickName,
  69. icon: <IdcardFilled />,
  70. }
  71. if (item?.value) {
  72. obj['childrenarr'] = item?.value?.map(item => {
  73. return { key: item.accountId + '_' + item.id, label: item?.remark ? item.accountId + '_' + item?.remark : item.accountId }
  74. })
  75. }
  76. useAll.push(obj)
  77. })
  78. setUserAll(useAll)
  79. }
  80. })
  81. }, [])
  82. //选中的组员的子账号
  83. useEffect(() => {
  84. if (userAll.length > 0 && userId) {
  85. let newArr: any = userAll?.filter((item: any) => item.key == userId)
  86. setSelectedArr(newArr[0]?.childrenarr || [])
  87. }
  88. }, [userAll, userId])
  89. // 用户点击table中的账号ID处理
  90. useEffect(() => {
  91. if (selectedArr.length > 0 && queryParmas.accountId) {
  92. let obj: any = selectedArr?.filter((item: any) => item.key.includes(queryParmas.accountId))[0]
  93. if (obj) {
  94. let arr = obj.key.split('_')
  95. setIds({ accountId: arr[0], adAccountId: arr[1] })
  96. }
  97. }
  98. }, [queryParmas, selectedArr])
  99. // // 初始跳转到自己的名称
  100. useEffect(() => {
  101. if (userAll?.length > 0 && userId) {
  102. let topEq = userAll?.findIndex((item: any) => item.key == userId)
  103. let em: any = document.getElementById('myMenus')
  104. console.log(topEq)
  105. if (em) {
  106. em.scrollTop = (52 - 4) * topEq
  107. }
  108. }
  109. }, [userId, userAll])
  110. //判定是否从任务列表跳转过来
  111. useEffect(()=>{
  112. let data = sessionStorage.getItem('adqQuery')
  113. if(data){
  114. let obj = JSON.parse(data)
  115. Object.keys(obj).forEach(key=>{
  116. switch(key){
  117. case 'accountId':
  118. setQueryParmas(obj)
  119. setActiveKey('1')
  120. break
  121. case 'campaignId':
  122. setQueryParmas(obj)
  123. setActiveKey('2')
  124. break
  125. case 'adgroupId':
  126. setQueryParmas(obj)
  127. setActiveKey('3')
  128. break
  129. case 'adcreativeId':
  130. setQueryParmas(obj)
  131. setActiveKey('4')
  132. break
  133. }
  134. })
  135. sessionStorage.removeItem('adqQuery')
  136. }
  137. },[])
  138. return <Row style={{ position: 'relative' }}>
  139. <Col style={{ height: '100%', minHeight: 'calc(100vh - 100px)', overflowY: 'auto', position: 'absolute', left: 0, top: 0, bottom: 0, width: 150, background: '#fff' }}>
  140. <Select
  141. placeholder='名称搜索'
  142. style={{ width: '100%' }}
  143. showSearch
  144. filterOption={(input: any, option: any) => {
  145. return (option!?.children as unknown as string)?.toLowerCase()?.includes(input?.toLowerCase())
  146. }
  147. } allowClear onChange={(value: any) => {
  148. if (value) {
  149. setUserId(value.toString())
  150. }
  151. }}>
  152. {
  153. userAll.map((item: any) => {
  154. return <Select.Option value={item.key} key={item.key}>{item.label}</Select.Option>
  155. })
  156. }
  157. </Select>
  158. <Menus
  159. id='myMenus'
  160. theme='light'
  161. onClick={(e: any) => {//点击菜单
  162. setUserId(e.key)
  163. }}
  164. selectedKeys={userId}
  165. mode="inline"
  166. multiple={false}
  167. items={userAll}
  168. style={{
  169. overflowY: 'auto',
  170. height: 'calc(100vh - 150px)',
  171. overflowX: 'hidden'
  172. }}
  173. />
  174. </Col>
  175. <Col span={21} style={{ marginLeft: 150 }}>
  176. <Card>
  177. <Tabs activeKey={activeKey} type="card" onChange={(activeKey) => { setActiveKey(activeKey) }} tabBarExtraContent={
  178. <Select
  179. placeholder='广点通账号'
  180. style={{ minWidth: 200 }}
  181. showSearch
  182. allowClear
  183. onChange={(value: any) => {
  184. let accountId = ''
  185. let adAccountId = ''
  186. if (value) {
  187. let arr = value.split('_')
  188. accountId = arr[0]
  189. adAccountId = arr[1]
  190. }
  191. setIds({ accountId, adAccountId })
  192. }}
  193. value={idS.accountId ? idS.accountId + '_' + idS.adAccountId : null}
  194. >
  195. {
  196. selectedArr?.map((item: any) => {
  197. return <Select.Option value={item.key} key={item.key}>{item.label}</Select.Option>
  198. })
  199. }
  200. </Select>
  201. }>
  202. {
  203. tabsConfig?.map(item => {
  204. return <TabPane tab={item.tab} key={item.key} >
  205. <>
  206. {/* 点击了列表中的ID默认展示并搜索对应ID条件 */}
  207. <Row >
  208. <Col>
  209. {
  210. Object.keys(queryParmas)?.filter(key => queryParmas[key])?.map(key => {
  211. enum nameEnum {
  212. accountId = '账户ID',
  213. campaignId = '计划ID',
  214. adgroupId = '广告ID',
  215. adcreativeId = '创意ID',
  216. pageId = '落地页ID',
  217. targetingId = '定向ID',
  218. }
  219. return <Badge
  220. key={key}
  221. count={
  222. <span
  223. style={{ width: 14, height: 14, borderRadius: '50%', background: '#ff4d4f', boxShadow: '0 0 0 1px #fff', color: '#fff', textAlign: 'center' }}
  224. onClick={() => {
  225. setQueryParmas({ ...queryParmas, [key]: '' })
  226. setIds({
  227. accountId: '',
  228. adAccountId: ''
  229. })
  230. }}
  231. >x</span>}
  232. size='small'
  233. offset={[-20, 2]}
  234. style={{ cursor: 'pointer' }}
  235. >
  236. <Tag style={{ marginRight: 20, marginBottom: 20 }}>{nameEnum[key]}:{queryParmas[key]}</Tag>
  237. </Badge>
  238. })
  239. }
  240. </Col>
  241. </Row>
  242. {activeKey === item.key && item.jsx({ ...idS, userId, queryParmas, tableIdClick })}
  243. </>
  244. </TabPane>
  245. })
  246. }
  247. </Tabs>
  248. </Card>
  249. </Col>
  250. </Row>
  251. }
  252. export default Adq