index.tsx 12 KB

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