index.tsx 11 KB

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