selectGroupCloudNew.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. import React, { useEffect, useState } from "react"
  2. import style from './index.less'
  3. import { Button, Card, Checkbox, Divider, Empty, Form, message, Pagination, Popover, Radio, Result, Select, Space, Spin, Typography, Image } from "antd"
  4. import { useAjax } from "@/Hook/useAjax"
  5. import { getPageRemoteImageDataListApi } from "@/services/adqV3/cloudNew"
  6. import { formatBytes, formatSecondsToTime, groupBy } from "@/utils/utils"
  7. import SelectGroupSearch from "./selectGroupSearch"
  8. import './global.less'
  9. import '../../tencentAdPutIn/index.less'
  10. import { showField1List } from "./const"
  11. import { EyeOutlined, SortAscendingOutlined } from "@ant-design/icons"
  12. import PlayVideo from "./playVideo"
  13. import Lazyimg from "react-lazyimg-component"
  14. import { useLocalStorageState } from "ahooks"
  15. import SyncCloudSc from "./syncCloudSc"
  16. import { getUserAccountListApi } from "@/services/launchAdq/adAuthorize"
  17. const { Text, Paragraph } = Typography;
  18. /**
  19. * 选择账户组媒体素材
  20. * @param param0
  21. * @returns
  22. */
  23. const SelectGroupCloudNew: React.FC<CLOUDNEW.SelectGroupCloudNewProps> = ({ num, defaultParams, checkedFolderList, setCheckedFolderList, accountCreateLogs, putInType }) => {
  24. /*****************************************/
  25. const [rowNum, setRowNum] = useState<number>(0)
  26. const [checkFolderAll, setCheckFolderAll] = useState<boolean>(false);
  27. const [indeterminateFolder, setIndeterminateFolder] = useState<boolean>(false);
  28. const [queryParams, setQueryParams] = useState<Omit<CLOUDNEW.GetPageRemoteImageDataListProps, 'materialType'>>({ pageNum: 1, pageSize: 20 })
  29. const [searchParams, setSearchParams] = useState<Partial<Omit<CLOUDNEW.GetPageRemoteImageDataListProps, 'materialType'>>>({})
  30. const [ownerAccountId, setOwnerAccountId] = useState<number>()
  31. const [previewData, setPreviewData] = useState<{ visible: boolean, url?: string }>({ visible: false })
  32. const [sortData, setSortData] = useLocalStorageState<{ sortField: string | undefined, sortType: boolean }>('sort-data-group', { sortField: undefined, sortType: false });
  33. const [showField, setShowField] = useLocalStorageState<string[]>('show-field-group', ['material.create_time', 'material_data_day.cost', 'material_data_day.ctr', 'material_data_day.conversions_rate', 'material_data_day.dynamic_creative_count']);
  34. const getPageRemoteImageDataList = useAjax((params) => getPageRemoteImageDataListApi(params))
  35. const getUserAccountList = useAjax((params) => getUserAccountListApi(params))
  36. /*****************************************/
  37. // 根据内容宽度计算列数
  38. useEffect(() => {
  39. let rowNum = Math.floor(1350 / 220)
  40. setRowNum(rowNum || 1)
  41. }, [])
  42. // 处理全选按钮状态
  43. useEffect(() => {
  44. let data: any[] = getPageRemoteImageDataList?.data?.records || []
  45. let dataIds = data.map(item => item.image_id || item.video_id)
  46. let selectIds = checkedFolderList.map(item => item.id)
  47. if (selectIds.length === 0 || dataIds.length === 0) {
  48. setCheckFolderAll(false)
  49. setIndeterminateFolder(false);
  50. } else if (dataIds.every((element) => selectIds.includes(element))) {
  51. setCheckFolderAll(true)
  52. setIndeterminateFolder(false);
  53. } else if (dataIds.some((element) => selectIds.includes(element))) {
  54. setCheckFolderAll(false)
  55. setIndeterminateFolder(true);
  56. } else {
  57. setCheckFolderAll(false)
  58. setIndeterminateFolder(false);
  59. }
  60. }, [checkedFolderList, getPageRemoteImageDataList?.data?.records])
  61. useEffect(() => {
  62. if (accountCreateLogs?.length) {
  63. getUserAccountList.run({ adUnitTypeList: putInType === 'NOVEL' ? ['NOVEL', 'NOVEL_IAA', 'SKIT_IAA'] : ['GAME', 'GAME_IAA'], pageNum: 1, pageSize: 20000, accountIdList: accountCreateLogs.map(item => item.accountId) }).then(res => {
  64. if (res?.records?.length) {
  65. const list = accountCreateLogs.map(item => item.accountId)
  66. const selectAccountList = res.records.filter((item: { accountId: any }) => list.includes(item.accountId))
  67. const groupAccount = groupBy(selectAccountList, (item) => item.groupId, true)
  68. const GrounpArray = Object.keys(groupAccount).map(function (group) {
  69. return groupAccount[group];
  70. })
  71. if (GrounpArray.length === 1 && !groupAccount['undefined']) {
  72. setOwnerAccountId(GrounpArray?.[0]?.[0]?.authMainAccountId || GrounpArray?.[0]?.[0]?.accountId)
  73. } else if (GrounpArray.length === 2 && groupAccount?.['undefined']?.length === 1) {
  74. const undefinedAccount = groupAccount?.['undefined'][0].accountId
  75. let authMainAccountId: any
  76. Object.keys(groupAccount).forEach(key => {
  77. if (key !== 'undefined') {
  78. authMainAccountId = groupAccount[key][0].authMainAccountId
  79. }
  80. })
  81. if (undefinedAccount === authMainAccountId) {
  82. setOwnerAccountId(authMainAccountId)
  83. } else {
  84. setOwnerAccountId(-1)
  85. }
  86. } else if (groupAccount?.['undefined']?.length === 1 && groupAccount?.['undefined']?.[0]?.isGroupMainAccount) {
  87. setOwnerAccountId(groupAccount?.['undefined']?.[0]?.accountId)
  88. } else {
  89. setOwnerAccountId(-1)
  90. }
  91. }
  92. })
  93. }
  94. }, [accountCreateLogs])
  95. useEffect(() => {
  96. if (ownerAccountId) {
  97. let params = { ...searchParams, ...defaultParams, ...queryParams, ownerAccountId }
  98. if (sortData?.sortField) {
  99. params = { ...params, ...sortData }
  100. }
  101. getPageRemoteImageDataList.run(params)
  102. }
  103. }, [queryParams, defaultParams, searchParams, sortData, showField, ownerAccountId])
  104. // 选择
  105. const onCheckboxChange = (checked: boolean, item: any) => {
  106. let newCheckedFolderList: any[] = JSON.parse(JSON.stringify(checkedFolderList))
  107. if (checked) { // 选中
  108. newCheckedFolderList.push({ ...item, id: item.image_id || item.video_id, material_type: defaultParams.materialType, oss_url: item.preview_url, materialType: 1 })
  109. } else { // 取消
  110. let id = item.image_id || item.video_id
  111. newCheckedFolderList = newCheckedFolderList.filter(i => i.id !== id)
  112. }
  113. setCheckedFolderList(newCheckedFolderList)
  114. };
  115. return <Spin spinning={getUserAccountList.loading} wrapperClassName={'select_group_spin'}>
  116. <div className={style.select_cloudNew_layout}>
  117. {ownerAccountId && ownerAccountId !== -1 ? <>
  118. {/* 搜索 */}
  119. <SelectGroupSearch
  120. type={defaultParams.materialType}
  121. onSearch={(value) => { setSearchParams(value) }}
  122. />
  123. <Card
  124. style={{ height: '100%', flex: '1 0', overflow: 'hidden' }}
  125. bodyStyle={{ padding: 0, overflow: 'auto hidden', height: '100%' }}
  126. className="cardResetCss buttonResetCss"
  127. bordered
  128. >
  129. <div className={style.cloudNew}>
  130. <div className={style.material} style={{ height: '100%' }}>
  131. <div className={style.operates}>
  132. <div className={style.left_bts}>
  133. <Checkbox
  134. onChange={(e) => {
  135. let newCheckedFolderList: any[] = JSON.parse(JSON.stringify(checkedFolderList))
  136. const data: any[] = getPageRemoteImageDataList?.data?.records
  137. if (e.target.checked) { // 全选
  138. const selectIds = newCheckedFolderList.map(item => item.id)
  139. const remainData = data.filter(item => {
  140. const id = item.image_id || item.video_id
  141. return !selectIds.includes(id)
  142. })
  143. const remainDataLength = remainData.length
  144. const remainNum = num - newCheckedFolderList.length
  145. if (remainNum > remainDataLength) {
  146. newCheckedFolderList.push(...remainData.map(i => ({ ...i, material_type: defaultParams.materialType, id: i.image_id || i.video_id, oss_url: i.preview_url, materialType: 1 })))
  147. } else {
  148. newCheckedFolderList.push(...remainData.splice(0, remainNum).map(i => ({ ...i, material_type: defaultParams.materialType, id: i.image_id || i.video_id, oss_url: i.preview_url, materialType: 1 })))
  149. }
  150. newCheckedFolderList = Array.from(new Set(newCheckedFolderList.map(item => JSON.stringify(item)))).map(item => JSON.parse(item));
  151. } else { // 取消全选
  152. const dataIds = data.map(item => item.image_id || item.video_id)
  153. newCheckedFolderList = newCheckedFolderList.filter(i => !dataIds.includes(i.id))
  154. }
  155. setCheckedFolderList(newCheckedFolderList)
  156. }}
  157. disabled={checkedFolderList?.length >= num}
  158. indeterminate={indeterminateFolder}
  159. checked={checkFolderAll}
  160. >全选</Checkbox>
  161. <span>已选 <span style={{ color: '#1890FF' }}>{checkedFolderList?.length || 0}</span>/{num} 个素材</span>
  162. {checkedFolderList.length > 0 && <a style={{ color: 'red' }} onClick={() => setCheckedFolderList([])}>清除所有</a>}
  163. {sortData?.sortField && <Text>「排序-{showField1List.find(item => item.value === sortData.sortField)?.label}-{sortData.sortType ? '正序' : '倒序'}」</Text>}
  164. {/* 同步素材 */}
  165. <SyncCloudSc
  166. accountId={ownerAccountId}
  167. />
  168. </div>
  169. <div className={style.left_bts}>
  170. <Popover
  171. content={<div style={{ width: 320 }}>
  172. <Form
  173. labelCol={{ span: 5 }}
  174. labelAlign="left"
  175. colon={false}
  176. >
  177. <Form.Item label={<strong>展示指标</strong>}>
  178. <Select
  179. placeholder="选择展示指标"
  180. showSearch
  181. filterOption={(input, option) =>
  182. (option?.label as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0
  183. }
  184. mode="multiple"
  185. options={showField1List}
  186. value={showField}
  187. onChange={(value) => {
  188. if (value.length > 6) {
  189. message.warn('最多只能选择6个指标')
  190. return
  191. }
  192. if (value.length < 1) {
  193. message.warn('最少选择1个指标')
  194. return
  195. }
  196. setSortData({ ...sortData, sortField: undefined })
  197. setShowField(value as any)
  198. }}
  199. />
  200. </Form.Item>
  201. <Form.Item label={<strong>排序</strong>}>
  202. <Space>
  203. <Select
  204. style={{ width: 125 }}
  205. placeholder="选择排序指标"
  206. showSearch
  207. filterOption={(input, option) =>
  208. (option?.label as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0
  209. }
  210. options={showField1List.filter(item => showField.includes(item.value) && item.value !== 'description')}
  211. value={sortData.sortField}
  212. allowClear
  213. onChange={(value) => {
  214. setSortData({ ...sortData, sortField: value as any })
  215. }}
  216. />
  217. <Radio.Group value={sortData.sortType} onChange={(e) => setSortData({ ...sortData, sortType: e.target.value })} buttonStyle="solid">
  218. <Radio.Button value={true}>正序</Radio.Button>
  219. <Radio.Button value={false}>倒序</Radio.Button>
  220. </Radio.Group>
  221. </Space>
  222. </Form.Item>
  223. </Form>
  224. </div>}
  225. trigger={['click']}
  226. title={<strong>自定义展示指标与排序</strong>}
  227. placement="bottomRight"
  228. >
  229. <Button icon={<SortAscendingOutlined />}>自定义展示指标与排序</Button>
  230. </Popover>
  231. </div>
  232. </div>
  233. <div className={`${style.content} content_global`}>
  234. <Spin spinning={getPageRemoteImageDataList.loading}>
  235. <div className={`${style.content_scroll} scroll`}>
  236. {getPageRemoteImageDataList?.data?.records?.length > 0 ? <Checkbox.Group value={checkedFolderList?.map(item => item.id)} style={{ width: '100%' }}>
  237. <div className={style.content_scroll_div}>
  238. {getPageRemoteImageDataList?.data?.records.map((item: any) => {
  239. let id = defaultParams.materialType === 'image' ? item.image_id : item.video_id
  240. const isSelect = checkedFolderList?.map(item => item.id).includes(id)
  241. const disabled = checkedFolderList.length >= num && !isSelect
  242. return <div key={id} className={style.content_row} style={{ width: rowNum ? (1 / rowNum * 100) + '%' : 220 }}>
  243. <Card
  244. hoverable
  245. bodyStyle={{ padding: 0 }}
  246. style={{ cursor: disabled ? 'not-allowed' : 'pointer' }}
  247. className={`${style.content_col}`}
  248. cover={<div style={{ height: 120, padding: 0 }} className={style.content_cover}>
  249. <div className={style.checkbox}><Checkbox disabled={disabled} value={id} onChange={(e) => onCheckboxChange(e.target.checked, item)} /></div>
  250. {defaultParams.materialType === 'video' ? <div className={style.playr}>
  251. <PlayVideo videoUrl={item.preview_url}>{(onPlay) => <img onClick={(e) => {
  252. e.stopPropagation(); e.preventDefault()
  253. onPlay()
  254. }} src={require('../../../../../public/image/play.png')} alt="" />}</PlayVideo>
  255. </div> : <div className={style.imgPreview} onClick={(e) => {
  256. e.stopPropagation()
  257. setPreviewData({ visible: true, url: item.preview_url })
  258. }}>
  259. <Space><EyeOutlined /><span>预览</span></Space>
  260. </div>}
  261. <div className={style.file_info}>
  262. <div>{item.width}*{item.height}</div>
  263. {defaultParams.materialType === 'video' && item.image_duration_millisecond && <div>{formatSecondsToTime(Math.floor(item.image_duration_millisecond / 1000))}</div>}
  264. </div>
  265. <Lazyimg
  266. animateType="transition"
  267. src={defaultParams.materialType === 'image' ? item.preview_url : item?.key_frame_image_url}
  268. className={`${style.coverImg} lazy`}
  269. animateClassName={['transition-enter', 'transition-enter-active']}
  270. />
  271. </div>}
  272. onClick={() => !disabled && onCheckboxChange(!isSelect, item)}
  273. >
  274. <div className={style.body}>
  275. <Text ellipsis strong style={{ flex: '1 0' }}>{item?.material_name}</Text>
  276. <Text style={{ fontSize: 12 }}>{formatBytes(item?.file_size)}</Text>
  277. </div>
  278. <Divider style={{ margin: '0 0 4px 0' }} />
  279. <div style={{ padding: '0 10px 6px' }}>
  280. {showField.map(field => {
  281. switch (field) {
  282. case 'material.created_time':
  283. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>创建时间:{item?.created_time}</Paragraph>
  284. case 'material_data_day.cost':
  285. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>消耗:{(item?.cost === null || item?.cost === undefined) ? '--' : item?.cost}</Paragraph>
  286. case 'material_data_day.order_pv':
  287. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>下单次数:{(item?.order_pv === null || item?.order_pv === undefined) ? '--' : item?.order_pv}</Paragraph>
  288. case 'material_data_day.order_cost':
  289. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>下单成本:{(item?.order_cost === null || item?.order_cost === undefined) ? '--' : item?.order_cost}</Paragraph>
  290. case 'material_data_day.ctr':
  291. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>点击率:{(item?.ctr === null || item?.ctr === undefined) ? '--' : (item?.ctr * 100).toFixed(2) + '%'}</Paragraph>
  292. case 'material_data_day.conversions_rate':
  293. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>目标转化率:{(item?.conversions_rate === null || item?.conversions_rate === undefined) ? '--' : (item?.conversions_rate * 100).toFixed(2) + '%'}</Paragraph>
  294. case 'material_data_day.adgroup_count':
  295. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>广告关联数:{(item?.adgroup_count === null || item?.adgroup_count === undefined) ? '--' : item?.adgroup_count}</Paragraph>
  296. case 'material_data_day.dynamic_creative_count':
  297. return <Paragraph key={field} style={{ fontSize: 12, marginBottom: 1 }}>创意关联数:{(item?.dynamic_creative_count === null || item?.dynamic_creative_count === undefined) ? '--' : item?.dynamic_creative_count}</Paragraph>
  298. default:
  299. return null
  300. }
  301. })}
  302. {showField.includes('description') && <Paragraph style={{ fontSize: 12, marginBottom: 1 }} ellipsis={{ tooltip: true }}>备注:{item.description || '--'}</Paragraph>}
  303. </div>
  304. </Card>
  305. </div>
  306. })}
  307. </div>
  308. </Checkbox.Group> : <div style={{ height: '100%', width: '100%', alignContent: 'center' }}><Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /></div>}
  309. </div>
  310. </Spin>
  311. </div>
  312. <div className={style.fotter}>
  313. <Pagination
  314. size="small"
  315. total={getPageRemoteImageDataList?.data?.total || 0}
  316. showSizeChanger
  317. showQuickJumper
  318. pageSize={getPageRemoteImageDataList?.data?.size || 20}
  319. current={getPageRemoteImageDataList?.data?.current || 1}
  320. onChange={(page: number, pageSize: number) => {
  321. setQueryParams({ ...queryParams, pageNum: page, pageSize })
  322. }}
  323. pageSizeOptions={[10, 15, 20, 50, 100]}
  324. />
  325. </div>
  326. </div>
  327. </div>
  328. </Card>
  329. </> : ownerAccountId === -1 ? <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100%' }}>
  330. <Result
  331. title="警告"
  332. status="500"
  333. subTitle="选择的账户不在一个账户分组中."
  334. />
  335. </div> : undefined}
  336. </div>
  337. {/* 预览 */}
  338. {previewData.visible && <Image
  339. width={200}
  340. style={{ display: 'none' }}
  341. preview={{
  342. visible: previewData.visible,
  343. src: previewData.url,
  344. onVisibleChange: value => {
  345. setPreviewData({ visible: false })
  346. },
  347. }}
  348. />}
  349. </Spin>
  350. }
  351. export default React.memo(SelectGroupCloudNew)