index.tsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. import Selector from "@/pages/launchSystemNew/launchManage/createAd/selector"
  2. import React, { useEffect, useState } from "react"
  3. import style from './index.less'
  4. import { Button, Col, Form, Input, Row, Select, Space, Table, Tag, Tooltip, Typography } from "antd";
  5. import { CloseCircleFilled } from "@ant-design/icons";
  6. import { useAjax } from "@/Hook/useAjax";
  7. import { getUserAccountListApi } from "@/services/launchAdq/adAuthorize";
  8. import { arraysHaveSameValues } from "@/utils/utils";
  9. import '@/pages/launchSystemV3/tencentAdPutIn/index.less'
  10. const { Text } = Typography;
  11. interface Props {
  12. value?: number[]
  13. onChange?: (value?: number[] | number, data?: any[] | any) => void
  14. type?: 'checkbox' | 'radio'
  15. /** 是否第一次获取的时候返回值 */
  16. isReturnFirstValue?: boolean
  17. allowClear?: boolean
  18. initialValues?: any
  19. }
  20. const SelectAdAccount: React.FC<Props> = ({ value, onChange, isReturnFirstValue, type = 'checkbox', allowClear = true, initialValues = {} }) => {
  21. value = value && typeof value !== 'object' ? [value] : value
  22. /***********************************/
  23. const [form] = Form.useForm()
  24. const [visible, setVisible] = useState<boolean>(false)
  25. const [selectedRows, setSelectedRows] = useState<any[]>([])
  26. const [queryForm, setQueryForm] = useState<{ accountIdList?: number[], adUnitTypeList?: string[], groupId?: number, remark?: string, putInType?: 'NOVEL' | 'GAME', sysGroupId?: number, pageNum: number, pageSize: number }>({ pageNum: 1, pageSize: 50, ...initialValues })
  27. const [isFirstReturn, setIsFirstReturn] = useState<boolean>(false)
  28. const getUserAccountList = useAjax((params) => getUserAccountListApi(params))
  29. /***********************************/
  30. const onFinish = (data: any) => {
  31. let oldQueryFrom = JSON.parse(JSON.stringify(queryForm))
  32. let params = { ...oldQueryFrom, ...data, pageNum: 1 }
  33. if (params?.accountIdList) {
  34. params.accountIdList = params?.accountIdList.split(/[,,\n\s]+/ig).filter((item: any) => item)
  35. } else {
  36. delete params?.accountIdList
  37. }
  38. setQueryForm(params)
  39. }
  40. useEffect(() => {
  41. if (visible) {
  42. setSelectedRows(value?.map(accountId => ({ accountId })) || [])
  43. }
  44. }, [value, visible])
  45. useEffect(() => {
  46. if (visible || isReturnFirstValue) {
  47. let params = { ...queryForm }
  48. if (queryForm?.putInType) {
  49. params.adUnitTypeList = queryForm?.putInType === 'NOVEL' ? ['NOVEL', 'NOVEL_IAA', 'SKIT_IAA'] : ['GAME', 'GAME_IAA']
  50. delete queryForm.putInType
  51. } else {
  52. delete params?.adUnitTypeList
  53. }
  54. getUserAccountList.run(params).then(res => {
  55. if (isReturnFirstValue && !isFirstReturn) {
  56. setIsFirstReturn(() => true)
  57. if (res?.records?.length) {
  58. onChange?.(res.records[0].accountId, res.records[0])
  59. }
  60. }
  61. })
  62. }
  63. }, [queryForm, visible, isFirstReturn])
  64. useEffect(() => {
  65. return () => {
  66. document.body.style.overflow = 'auto';
  67. }
  68. }, [])
  69. const handleCancel = () => {
  70. document.body.style.overflow = 'auto';
  71. setSelectedRows([])
  72. setVisible(false)
  73. }
  74. return <div className={style.selectAccount}>
  75. <div className={style.selectAccount_row} style={{ zIndex: visible ? 1000 : 1 }}>
  76. <Selector
  77. label={visible ? '选择账户' : '媒体账户'}
  78. style={visible ? { borderColor: '#1890ff' } : {}}
  79. titleStyle={visible ? { borderColor: '#1890ff', color: '#1890ff' } : {}}
  80. >
  81. <div
  82. className={style.selectAccount_select}
  83. onClick={() => {
  84. document.body.style.overflow = 'hidden';
  85. setVisible(true)
  86. }}
  87. >
  88. <div className={style.selectAccount_select_content}>
  89. {(visible && selectedRows.length > 0) ? <>
  90. <Tag
  91. closable={type === 'checkbox'}
  92. color="#F5F5F5"
  93. key={selectedRows[0].accountId}
  94. className={style.content_tag}
  95. onClose={() => {
  96. setSelectedRows(selectedRows.slice(1))
  97. }}
  98. >{selectedRows[0].accountId}</Tag>
  99. {selectedRows?.length > 1 && <Tooltip
  100. color="#FFF"
  101. title={<span style={{ color: '#000' }}>
  102. {selectedRows?.filter((_, index) => index !== 0)?.map((item) => <Tag
  103. color="#F5F5F5"
  104. className={style.content_tag}
  105. key={item.accountId}
  106. closable
  107. onClose={() => {
  108. setSelectedRows(selectedRows?.filter(item1 => item1.accountId !== item.accountId))
  109. }}
  110. >{item.accountId}</Tag>)}</span>
  111. }
  112. >
  113. <Tag color="#F5F5F5" className={style.content_tag}>+{selectedRows.length - 1}</Tag>
  114. </Tooltip>}
  115. </> : (!visible && value && value?.length > 0) ? <>
  116. <Tag
  117. closable={type === 'checkbox'}
  118. color="#F5F5F5"
  119. className={style.content_tag}
  120. key={value[0]}
  121. onClose={() => {
  122. onChange?.(value.slice(1))
  123. }}
  124. >{value[0]}</Tag>
  125. {value?.length > 1 && <Tooltip
  126. color="#FFF"
  127. title={<span style={{ color: '#000' }}>
  128. {value?.filter((_, index) => index !== 0)?.map((accountId) => <Tag
  129. className={style.content_tag}
  130. color="#F5F5F5"
  131. key={accountId}
  132. closable
  133. onClose={() => {
  134. onChange?.(value?.filter(accountId1 => accountId1 !== accountId))
  135. }}
  136. >{accountId}</Tag>)}</span>
  137. }
  138. >
  139. <Tag color="#F5F5F5" className={style.content_tag}>+{value.length - 1}</Tag>
  140. </Tooltip>}
  141. </> : <Text type="secondary">请选择媒体账户</Text>}
  142. </div>
  143. {visible}
  144. {((visible && selectedRows.length > 0) || (!visible && value && value?.length > 0)) && allowClear && <a className={style.clear} onClick={(e) => {
  145. e.stopPropagation()
  146. if (visible) {
  147. setSelectedRows([])
  148. } else {
  149. onChange?.(type === 'checkbox' ? [] : undefined, type === 'checkbox' ? [] : undefined)
  150. }
  151. }}><CloseCircleFilled /></a>}
  152. </div>
  153. </Selector>
  154. {visible && <div className={style.selectAccount_list}>
  155. <div className={style.selectAccount_list_header}>
  156. <Form
  157. layout="inline"
  158. className='queryForm'
  159. name="basicSelectAcc"
  160. form={form}
  161. onFinish={onFinish}
  162. initialValues={initialValues}
  163. >
  164. <Row gutter={[0, 6]}>
  165. <Col><Form.Item name={'putInType'}>
  166. <Select
  167. style={{ width: 160 }}
  168. placeholder="选择账户类型"
  169. allowClear
  170. filterOption={(input: any, option: any) => {
  171. return option!.children?.toString().toLowerCase().includes(input.toLowerCase())
  172. }}
  173. >
  174. <Select.Option value='NOVEL'>小说/短剧</Select.Option>
  175. <Select.Option value='GAME'>游戏</Select.Option>
  176. </Select>
  177. </Form.Item></Col>
  178. <Col><Form.Item name='accountIdList'>
  179. <Input.TextArea
  180. rows={1}
  181. autoSize={{ minRows: 1, maxRows: 1 }}
  182. placeholder="账户(多个,,空格换行)"
  183. style={{ width: 180 }}
  184. allowClear
  185. />
  186. </Form.Item></Col>
  187. <Col><Form.Item name='remark'>
  188. <Input
  189. placeholder="备注"
  190. style={{ width: 120 }}
  191. allowClear
  192. />
  193. </Form.Item></Col>
  194. <Col><Form.Item name='adUnitAccount'>
  195. <Select
  196. style={{ width: 130 }}
  197. placeholder="是否业务单元"
  198. allowClear
  199. filterOption={(input: any, option: any) => {
  200. return option!.children?.toString().toLowerCase().includes(input.toLowerCase())
  201. }}
  202. >
  203. <Select.Option value={1}>是</Select.Option>
  204. <Select.Option value={0}>否</Select.Option>
  205. </Select>
  206. </Form.Item></Col>
  207. <Col>
  208. <Space>
  209. <Button type="primary" htmlType="submit">搜索</Button>
  210. <Button onClick={() => form.resetFields()}>重置</Button>
  211. </Space>
  212. </Col>
  213. </Row>
  214. </Form>
  215. </div>
  216. <div className={style.selectAccount_list_table}>
  217. <Table
  218. size={'small'}
  219. bordered
  220. dataSource={getUserAccountList?.data?.records}
  221. rowKey={'accountId'}
  222. scroll={{ y: 220 }}
  223. pagination={{
  224. pageSize: getUserAccountList?.data?.size || 50,
  225. current: getUserAccountList?.data?.current || 1,
  226. showTotal: total => `总共 ${total} 账户`,
  227. total: getUserAccountList?.data?.total,
  228. showSizeChanger: true,
  229. showLessItems: true,
  230. defaultCurrent: 1,
  231. defaultPageSize: 50,//默认初始的每页条数
  232. onChange: (page, pageSize) => {
  233. setQueryForm({ ...queryForm, pageNum: page, pageSize })
  234. }
  235. }}
  236. loading={getUserAccountList.loading}
  237. columns={[
  238. {
  239. title: '账号',
  240. dataIndex: 'accountId',
  241. key: 'accountId',
  242. width: 80,
  243. align: 'center',
  244. render(value) {
  245. return <span style={{ fontSize: 12 }}>{value}</span>
  246. }
  247. },
  248. {
  249. title: '企业',
  250. dataIndex: 'corporationName',
  251. key: 'corporationName',
  252. width: 160,
  253. ellipsis: true,
  254. render(value) {
  255. return <span style={{ fontSize: 12 }}>{value || '--'}</span>
  256. }
  257. },
  258. {
  259. title: '企业标识',
  260. dataIndex: 'corporationLicence',
  261. key: 'corporationLicence',
  262. width: 150,
  263. ellipsis: true,
  264. render(value) {
  265. return <span style={{ fontSize: 12 }}>{value || '--'}</span>
  266. }
  267. },
  268. {
  269. title: '业务单元账号',
  270. dataIndex: 'adUnitAccountId',
  271. key: 'adUnitAccountId',
  272. width: 100,
  273. align: 'center',
  274. render(value) {
  275. return <span style={{ fontSize: 12 }}>{value || '--'}</span>
  276. }
  277. },
  278. {
  279. title: '业务单元号?',
  280. dataIndex: 'adUnitAccount',
  281. key: 'adUnitAccount',
  282. width: 90,
  283. align: 'center',
  284. render(value) {
  285. return <span style={{ fontSize: 12 }}>{value ? '是' : '否'}</span>
  286. }
  287. },
  288. {
  289. title: '备注',
  290. dataIndex: 'remark',
  291. key: 'remark',
  292. ellipsis: true,
  293. render(value) {
  294. return <span style={{ fontSize: 12 }}>{value || '--'}</span>
  295. }
  296. },
  297. ]}
  298. rowSelection={type === 'checkbox' ? {
  299. selectedRowKeys: selectedRows.map(item => item.accountId),
  300. type,
  301. onSelect: (record: { accountId: number }, selected: boolean) => {
  302. if (selected) {
  303. selectedRows.push({ ...record })
  304. setSelectedRows([...selectedRows])
  305. } else {
  306. let newSelectAccData = selectedRows.filter((item: { accountId: number }) => item.accountId !== record.accountId)
  307. setSelectedRows([...newSelectAccData])
  308. }
  309. },
  310. onSelectAll: (selected: boolean, selectedRowss: { accountId: number }[], changeRows: { accountId: number }[]) => {
  311. if (selected) {
  312. let newSelectAccData = [...selectedRows]
  313. changeRows.forEach((item: { accountId: number }) => {
  314. let index = newSelectAccData.findIndex((ite: { accountId: number }) => ite.accountId === item.accountId)
  315. if (index === -1) {
  316. let data: any = { ...item }
  317. newSelectAccData.push(data)
  318. }
  319. })
  320. setSelectedRows([...newSelectAccData])
  321. } else {
  322. let newSelectAccData = selectedRows.filter((item: { accountId: number }) => {
  323. let index = changeRows.findIndex((ite: { accountId: number }) => ite.accountId === item.accountId)
  324. if (index !== -1) {
  325. return false
  326. } else {
  327. return true
  328. }
  329. })
  330. setSelectedRows([...newSelectAccData])
  331. }
  332. }
  333. } : {
  334. selectedRowKeys: selectedRows.map(item => item.accountId),
  335. type,
  336. onChange(selectedRowKeys, selectedRows, info) {
  337. setSelectedRows(selectedRows)
  338. },
  339. }}
  340. />
  341. </div>
  342. <div className={style.selectAccount_list_footer}>
  343. <Button className={style.resetCss} onClick={handleCancel}>取消</Button>
  344. <Button
  345. className={style.resetCss}
  346. type="primary"
  347. style={{ marginLeft: 8 }}
  348. onClick={() => {
  349. if (value?.length && arraysHaveSameValues(value, selectedRows.map(item => item.accountId))) {
  350. handleCancel()
  351. return
  352. }
  353. document.body.style.overflow = 'auto';
  354. onChange?.(type === 'checkbox' ? selectedRows.map(item => item.accountId) : selectedRows?.[0]?.accountId, type === 'checkbox' ? selectedRows : selectedRows?.[0])
  355. setSelectedRows([])
  356. setVisible(false)
  357. }}
  358. >确定</Button>
  359. </div>
  360. </div>}
  361. </div>
  362. {visible && <div className={style.selectAccount_mask}></div>}
  363. </div>
  364. }
  365. export default React.memo(SelectAdAccount)