index.tsx 14 KB

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