index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import HocError from '@/Hoc/HocError'
  2. import { Col, Modal, Row, Input, message, Space, Tabs, Button, Radio } from 'antd'
  3. import React, { useCallback, useEffect, useState } from 'react'
  4. import { columnsMp } from './tableConfig'
  5. import { useAjax } from '@/Hook/useAjax'
  6. import { getAdAccountListApi, GetAdAccountParams, putAdAccountApi } from '@/services/launchAdq/adAuthorize'
  7. import style from './index.less'
  8. import TableData from '../components/TableData'
  9. import GroupLeft from './groupLeft'
  10. import QQAuth from './qqAuto'
  11. import { MenuFoldOutlined, MenuUnfoldOutlined, PlusOutlined, SwapOutlined } from '@ant-design/icons'
  12. import TeamMembers from '../components/teamMembers'
  13. import { getAdAccountAllOfMember } from '@/services/launchAdq/adq'
  14. import AddAccountToGroup from './addAccountToGroup'
  15. import { delAccountToGroupApi } from '@/services/launchAdq/subgroup'
  16. import { useModel } from 'umi'
  17. import ChangeRecord from './changeRecord'
  18. import CheckAccount from './checkAccount'
  19. import AppointPut from './appointPut'
  20. /** 投放管理 */
  21. const AdAuthorize: React.FC = () => {
  22. let [visible, setVisible] = useState(false)
  23. /*************************/
  24. const { groupListInit } = useModel('useLaunchAdq.useAdAuthorize')
  25. const userInfo = useModel('@@initialState', model => model.initialState?.currentUser)
  26. const [queryForm, setQueryForm] = useState<GetAdAccountParams>({ pageNum: 1, pageSize: 20 })
  27. const [remarkData, set_remarkData] = useState<{ visible: boolean, remark: string, data: any }>({
  28. visible: false,
  29. remark: '',
  30. data: null
  31. })
  32. const [activeKey, setActiveKey] = useState<string>('1')
  33. const [showLeft, setShowLeft] = useState<boolean>(false)
  34. const [crShow, setCrShow] = useState<boolean>(false) // 变更记录控制
  35. const [crData, setCrData] = useState<{ name: number, id: number } | null>(null)
  36. const [checkAccShow, setCheckAccShow] = useState<boolean>(false)
  37. const [data, setData] = useState<{
  38. putResourceId?: number | undefined,
  39. beginTime?: string | undefined,
  40. gdtAccountId?: number,
  41. accountIds?: string,
  42. accountId?: string,
  43. gdtAccountIds?: string,
  44. advertiserId?: string,
  45. accountName?: string,
  46. account?: string,
  47. accountPassword?: string,
  48. quickAppAccountIds?: string
  49. resourceNames?: string
  50. } | undefined>(undefined)
  51. const [selectAccData, setSelectAccData] = useState<any[]>([])
  52. const [puShow, setPuShow] = useState<boolean>(false)
  53. const [puData, setPuData] = useState<any[]>([])
  54. const [switchType, setSwitchType] = useState<'account' | 'putUser'>('account')
  55. const putRemark = useAjax((adAccountId: any, remark: any) => putAdAccountApi(adAccountId, remark))
  56. const delAccountToGroup = useAjax((params) => delAccountToGroupApi(params))
  57. const getAdAccountList = useAjax((params) => getAdAccountListApi(params), { formatResult: true })
  58. const allOfMember = useAjax(() => getAdAccountAllOfMember(), { formatResult: true })
  59. /*************************/
  60. useEffect(() => {
  61. groupListInit()
  62. }, [])
  63. useEffect(() => {
  64. getList()
  65. }, [queryForm])
  66. /** 获取账号列表 */
  67. const getList = () => {
  68. let params = JSON.parse(JSON.stringify(queryForm))
  69. if (params.accountIds) {
  70. params.accountIds = params.accountIds.split(/[\,\,]/)
  71. } else {
  72. delete params?.accountIds
  73. }
  74. getAdAccountList.run(params)
  75. }
  76. const remark = () => {
  77. if (remarkData.remark && remarkData.data) {
  78. putRemark.run(remarkData.data.id, remarkData.remark).then(res => {
  79. set_remarkData({ ...remarkData, visible: false, remark: '', data: null })
  80. getList()
  81. })
  82. } else {
  83. message.error('请输入备注!')
  84. }
  85. }
  86. const edit = useCallback((data) => {
  87. set_remarkData({ ...remarkData, visible: true, data, remark: data.remark })
  88. }, [remarkData])
  89. /** 移除分组里账号 */
  90. const del = (groupId: number, accountId: number) => {
  91. delAccountToGroup.run({ currGroupId: groupId, accountIds: [accountId] }).then(res => {
  92. message.success('移出成功')
  93. getAdAccountList.refresh()
  94. })
  95. }
  96. /** 切号 */
  97. const checkAccount = (value: any[]) => {
  98. let ids = value?.map((item: any) => item.id)
  99. setData({ resourceNames: value?.map((item: any) => item.putResourceName).toString(), accountIds: value?.map((item: any) => item.accountId).toString(), gdtAccountIds: ids.toString(), putResourceId: undefined, beginTime: undefined })
  100. setCheckAccShow(true);
  101. }
  102. /** 变更记录 */
  103. const changeRecord = (name: number, id: number) => {
  104. setCrData({ name, id })
  105. setCrShow(true)
  106. }
  107. /** 指派投手 */
  108. const putUserHandle = (data: any[]) => {
  109. setPuData(data)
  110. setPuShow(true)
  111. }
  112. return <div style={{ height: '100%' }}>
  113. <Tabs
  114. tabBarStyle={{ marginBottom: 1 }}
  115. activeKey={activeKey}
  116. type="card"
  117. // tabBarExtraContent={<Button type='primary' onClick={()=>setVisible(true)}><PlusOutlined />广告账号授权</Button>}
  118. onChange={(activeKey) => {
  119. if (activeKey !== 'contract') {
  120. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  121. delete newQueryForm?.groupId
  122. delete newQueryForm?.putUserId
  123. setQueryForm(newQueryForm)
  124. setActiveKey(activeKey)
  125. } else {
  126. setShowLeft(!showLeft)
  127. }
  128. }}
  129. >
  130. <Tabs.TabPane tab='我的' key='1' />
  131. <Tabs.TabPane tab='组员' key='2' />
  132. <Tabs.TabPane tab={showLeft ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />} key='contract' />
  133. </Tabs>
  134. <div className={style.manage}>
  135. {!showLeft && activeKey === '1' && <GroupLeft onChange={(groupId) => setQueryForm({ ...queryForm, groupId, pageNum: 1 })} value={queryForm?.groupId} />}
  136. {!showLeft && activeKey === '2' && <TeamMembers allOfMember={allOfMember} onChange={(putUserId) => setQueryForm({ ...queryForm, putUserId, pageNum: 1 })} value={queryForm?.putUserId} />}
  137. <div className={style.manage__left} style={showLeft ? { width: '100%' } : { width: 'calc(100% - 200px)' }}>
  138. <TableData
  139. ajax={getAdAccountList}
  140. dataSource={getAdAccountList?.data?.data?.records}
  141. loading={getAdAccountList?.loading}
  142. columns={() => columnsMp(edit, del, checkAccount, changeRecord, putUserHandle, activeKey, userInfo?.userId?.toString(), queryForm?.groupId, getAdAccountList)}
  143. total={getAdAccountList?.data?.data?.total}
  144. page={getAdAccountList?.data?.data?.current}
  145. pageSize={getAdAccountList?.data?.data?.size}
  146. size="small"
  147. scroll={{ y: 600 }}
  148. leftChild={<Space>
  149. <Radio.Group value={switchType} onChange={(e) => { setSwitchType(e.target.value); setSelectAccData([]) }}>
  150. <Radio.Button value="account">批量切号</Radio.Button>
  151. <Radio.Button value="putUser">批量指派投放助理</Radio.Button>
  152. </Radio.Group>
  153. <Input.TextArea
  154. placeholder="广告账号, 多个以,隔开(id1,id2)"
  155. allowClear
  156. style={{ minWidth: 200 }}
  157. rows={1}
  158. value={queryForm?.accountIds}
  159. onChange={(e) => {
  160. setQueryForm({ ...queryForm, accountIds: e.target.value })
  161. }}
  162. />
  163. <Button onClick={getList} type='primary' loading={getAdAccountList.loading}>搜索</Button>
  164. <AddAccountToGroup onChange={() => getAdAccountList.refresh()} />
  165. <Button type='primary' onClick={() => setVisible(true)}><PlusOutlined />广告账号授权</Button>
  166. {switchType === 'account' ?
  167. (selectAccData?.length > 0 && <Button type="primary" ghost icon={<SwapOutlined />} onClick={() => { checkAccount(selectAccData) }}>批量切号</Button>) :
  168. (selectAccData?.length > 0 && <Button type="primary" ghost icon={<SwapOutlined />} onClick={() => { putUserHandle(selectAccData) }}>批量指派投放助理</Button>)}
  169. </Space>}
  170. rowSelection={{
  171. selectedRowKeys: selectAccData?.map((item: any) => item.id?.toString()),
  172. getCheckboxProps: (record: any) => ({
  173. disabled: switchType === 'putUser' ? activeKey === '2' || userInfo?.userId !== record?.putUserInfo?.userId : false
  174. }),
  175. onSelect: (record: { id: number, mpName: string }, selected: boolean) => {
  176. if (selected) {
  177. selectAccData.push({ ...record })
  178. setSelectAccData([...selectAccData])
  179. } else {
  180. let newSelectAccData = selectAccData.filter((item: { id: number }) => item.id !== record.id)
  181. setSelectAccData([...newSelectAccData])
  182. }
  183. },
  184. onSelectAll: (selected: boolean, selectedRows: { id: number }[], changeRows: { id: number }[]) => {
  185. if (selected) {
  186. let newSelectAccData = [...selectAccData]
  187. changeRows.forEach((item: { id: number }) => {
  188. let index = newSelectAccData.findIndex((ite: { id: number }) => ite.id === item.id)
  189. if (index === -1) {
  190. newSelectAccData.push({ ...item })
  191. }
  192. })
  193. setSelectAccData([...newSelectAccData])
  194. } else {
  195. let newSelectAccData = selectAccData.filter((item: { id: number }) => {
  196. let index = changeRows.findIndex((ite: { id: number }) => ite.id === item.id)
  197. if (index !== -1) {
  198. return false
  199. } else {
  200. return true
  201. }
  202. })
  203. setSelectAccData([...newSelectAccData])
  204. }
  205. }
  206. }}
  207. onChange={(props: any) => {
  208. let { pagination } = props
  209. let { current, pageSize } = pagination
  210. setQueryForm({ ...queryForm, pageNum: current, pageSize })
  211. }}
  212. />
  213. </div>
  214. </div>
  215. {/* 广告授权 */}
  216. {visible && <QQAuth qqVisible={visible} callBack={() => setVisible(false)} />}
  217. {/* 变更记录 */}
  218. {crShow && <ChangeRecord visible={crShow} data={crData} onClose={() => { setCrShow(false); setCrData(null) }} />}
  219. {/* 切号 */}
  220. {checkAccShow && <CheckAccount value={data} visible={checkAccShow} onChange={() => { getList(); setCheckAccShow(false); setSelectAccData([]) }} onClose={() => { setCheckAccShow(false) }} />}
  221. {/* 指派 */}
  222. {puShow && <AppointPut value={puData} visible={puShow} onClose={() => { setPuShow(false) }} allOfMember={allOfMember} onChange={() => { setPuShow(false); getAdAccountList.refresh(); setSelectAccData([]) }} />}
  223. {remarkData.visible && <Modal
  224. visible={remarkData.visible}
  225. title='编辑账户'
  226. onCancel={() => { set_remarkData({ ...remarkData, visible: false, data: null }) }}
  227. onOk={remark}
  228. confirmLoading={putRemark.loading}
  229. >
  230. <Row gutter={[20, 20]}>
  231. <Col span={24} className={style.boxCol}><strong>广告主ID:</strong><span>{remarkData?.data.accountId}</span></Col>
  232. <Col span={24} className={style.boxCol}><strong>类型:</strong><span>{remarkData?.data.sourceType === 0 ? '微信' : 'QQ'}</span></Col>
  233. <Col span={24} className={style.boxCol}><strong>公众号信息:</strong><span>{remarkData?.data.wechatAccountName || '无'}</span></Col>
  234. <Col span={24} className={style.boxCol}><strong>企业名称:</strong><span>{remarkData?.data.corporationName || '无'}</span></Col>
  235. <Col span={24} className={style.boxCol}><strong>服务商ID列表:</strong><span>{remarkData?.data.agencyIdList ? remarkData.data.agencyIdList?.join() : '无'}</span></Col>
  236. <Col span={24} className={style.boxCol}><strong>行业ID:</strong><span>{remarkData?.data.systemIndustryId || '无'}</span></Col>
  237. <Col span={24} className={style.boxCol}><strong>授权状态:</strong><span>{remarkData?.data.authStatus || '无'}</span></Col>
  238. <Col span={24} className={style.boxCol}><strong>日限额(分):</strong><span>{remarkData?.data.dailyBudget || '无'}</span></Col>
  239. <Col span={24} className={style.boxCol}><strong>授权时间:</strong><span>{remarkData?.data.createTime || '无'}</span></Col>
  240. <Col span={24} className={style.boxCol}><strong>备注:</strong><span><Input.TextArea rows={5} maxLength={200} value={remarkData.remark} onChange={(e) => {
  241. let value = e.target.value
  242. set_remarkData({ ...remarkData, remark: value })
  243. }} /></span></Col>
  244. </Row>
  245. </Modal>}
  246. </div>
  247. }
  248. export default HocError(AdAuthorize)