index.tsx 14 KB

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