selectComponentsUnitSearch.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { Button, Card, Col, DatePicker, Form, Input, Row, Select, Space } from "antd"
  2. import React, { useState } from "react"
  3. import { PlusCircleOutlined, SearchOutlined } from "@ant-design/icons";
  4. import moment from "moment";
  5. import { COMMON_POTENTIAL_STATUS_ENUM, COMPONENT_GENERATION_TYPE_ENUM, DEFAULT_COMPONENT_SUB_IMAGE_TYPE, DEFAULT_COMPONENT_SUB_VIDEO_TYPE } from "../../tencenTasset/manageComponent/const";
  6. import { DefaultOptionType } from "antd/lib/select";
  7. import SelectCloudComponent from "./selectCloudComponent";
  8. interface Props {
  9. type: 'image' | 'video'
  10. defaultParams: CLOUDNEW.DefaultParams
  11. accountId: number,
  12. componentSubType?: string[]
  13. onSearch?: (value: Partial<CLOUDNEW.GetMaterialListProps>) => void
  14. putInType?: 'NOVEL' | 'GAME'
  15. }
  16. // 选择素材搜索
  17. const SelectComponentsUnitSearch: React.FC<Props> = ({ type, defaultParams, accountId, onSearch, componentSubType, putInType }) => {
  18. /**********************************/
  19. const [form] = Form.useForm();
  20. // const idList = Form.useWatch('idList', form)
  21. const [selectCloudData, setSelectCloudData] = useState<{
  22. defaultParams: {
  23. sizeQueries?: {
  24. width: number,
  25. height: number,
  26. relation: string
  27. }[],
  28. materialType: 'image' | 'video'
  29. fileSize: number
  30. }
  31. num: number
  32. }>()
  33. const [materialConfig, setMaterialConfig] = useState<{
  34. adcreativeTemplateId?: number,
  35. type: string,
  36. cloudSize: { relation: string, width: number, height: number }[],
  37. list: any[],
  38. index: number,
  39. max: number,
  40. sliderImgContent: any,
  41. isGroup?: boolean
  42. }>({
  43. type: '',//类型
  44. cloudSize: [],//素材搜索条件
  45. list: [],//素材
  46. index: 0, // 素材组下标
  47. max: 1,//素材数量
  48. sliderImgContent: undefined
  49. })//图片素材配置
  50. const [selectVideoVisible, setSelectVideoVisible] = useState(false)
  51. /**********************************/
  52. const handleOk = (values: any) => {
  53. console.log(values)
  54. let params: any = []
  55. Object.keys(values).forEach(key => {
  56. let value = values[key]
  57. if (['idList'].includes(key) && value !== undefined && value !== null) {
  58. let value1 = value.replace(/[,,\s]/g, ',')
  59. params[type === 'image' ? 'imageId' : 'videoId'] = value1.split(',').filter((a: any) => a)
  60. } else if (['componentIdSting'].includes(key) && value !== undefined && value !== null) {
  61. let value1 = value.replace(/[,,\s]/g, ',')
  62. params['componentId'] = value1.split(',').filter((a: any) => a)
  63. }
  64. if ('createTime' === key && value?.length === 2) {
  65. params.createTimeMin = moment(value?.[0]).format('YYYY-MM-DD')
  66. params.createTimeMax = moment(value?.[1]).format('YYYY-MM-DD')
  67. } else {
  68. params[key] = value
  69. }
  70. })
  71. onSearch?.(params)
  72. }
  73. return <Card
  74. bodyStyle={{ padding: '5px 10px', overflow: 'auto hidden', display: 'flex', gap: 6, flexWrap: 'wrap' }}
  75. className="cardResetCss buttonResetCss"
  76. bordered
  77. >
  78. <Form
  79. layout="inline"
  80. name="basicSelectSearch"
  81. colon={false}
  82. form={form}
  83. onFinish={handleOk}
  84. >
  85. <Row gutter={[0, 6]}>
  86. <Col><Form.Item name={'componentCustomName'}>
  87. <Input style={{ width: 100 }} allowClear placeholder="组件名称" />
  88. </Form.Item></Col>
  89. <Col><Form.Item name={'idList'}>
  90. <Input
  91. style={{ width: 220 }}
  92. allowClear
  93. placeholder="素材ID(多个空格or换行隔开)"
  94. addonAfter={<PlusCircleOutlined
  95. style={{ cursor: 'pointer' }}
  96. onClick={() => {
  97. setSelectCloudData({
  98. num: 100,
  99. defaultParams: defaultParams as any
  100. })
  101. setMaterialConfig({
  102. ...materialConfig,
  103. type: type,
  104. max: 100,
  105. index: 1,
  106. isGroup: false
  107. })
  108. setTimeout(() => {
  109. setSelectVideoVisible(true)
  110. }, 100)
  111. }}
  112. />}
  113. />
  114. </Form.Item></Col>
  115. <Col><Form.Item name={'componentIdSting'}>
  116. <Input.TextArea rows={1} style={{ width: 190 }} allowClear placeholder="组件ID(多个空格or换行隔开)" />
  117. </Form.Item></Col>
  118. <Col><Form.Item name={'componentSubType'}>
  119. <Select
  120. showSearch
  121. placeholder="二级组件类型"
  122. filterOption={(input, option) =>
  123. ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
  124. }
  125. style={{ minWidth: 120 }}
  126. maxTagCount={1}
  127. mode="multiple"
  128. allowClear
  129. options={(type === 'image' ? DEFAULT_COMPONENT_SUB_IMAGE_TYPE : DEFAULT_COMPONENT_SUB_VIDEO_TYPE).filter(item => componentSubType?.includes(item.value)) as DefaultOptionType[]}
  130. />
  131. </Form.Item></Col>
  132. <Col><Form.Item name={'potentialStatus'}>
  133. <Select
  134. showSearch
  135. placeholder="组件潜力"
  136. filterOption={(input, option) =>
  137. ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
  138. }
  139. style={{ minWidth: 100 }}
  140. maxTagCount={1}
  141. mode="multiple"
  142. options={Object.keys(COMMON_POTENTIAL_STATUS_ENUM).map(key => ({ label: COMMON_POTENTIAL_STATUS_ENUM[key as keyof typeof COMMON_POTENTIAL_STATUS_ENUM], value: key }))}
  143. />
  144. </Form.Item></Col>
  145. <Col><Form.Item name={'generationType'}>
  146. <Select
  147. showSearch
  148. placeholder="来源"
  149. filterOption={(input, option) =>
  150. ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
  151. }
  152. style={{ minWidth: 100 }}
  153. maxTagCount={1}
  154. mode="multiple"
  155. options={Object.keys(COMPONENT_GENERATION_TYPE_ENUM).map(key => ({ label: COMPONENT_GENERATION_TYPE_ENUM[key as keyof typeof COMPONENT_GENERATION_TYPE_ENUM], value: key }))}
  156. />
  157. </Form.Item></Col>
  158. <Col><Form.Item name={'createTime'}>
  159. <DatePicker.RangePicker style={{ width: 260 }} placeholder={['创建时间开始', '创建时间结束']} />
  160. </Form.Item></Col>
  161. <Col><Form.Item>
  162. <Space>
  163. <Button onClick={() => form.resetFields()}>重置</Button>
  164. <Button type="primary" htmlType="submit" icon={<SearchOutlined />} className="modalResetCss">搜索</Button>
  165. </Space>
  166. </Form.Item></Col>
  167. </Row>
  168. </Form>
  169. {/* 选择素材 */}
  170. {(selectVideoVisible && selectCloudData) && <SelectCloudComponent
  171. {...selectCloudData}
  172. accountCreateLogs={[{ accountId: accountId }]}
  173. visible={selectVideoVisible}
  174. isGroup={materialConfig?.isGroup}
  175. onClose={() => {
  176. setSelectVideoVisible(false)
  177. setSelectCloudData(undefined)
  178. }}
  179. putInType={putInType}
  180. title="选择素材查找"
  181. onChange={(content: any) => {
  182. if (content?.length > 0) {
  183. const idList = content?.map((item: any) => item.id)?.toString()
  184. form.setFieldsValue({ idList })
  185. }
  186. setSelectVideoVisible(false)
  187. setSelectCloudData(undefined)
  188. }}
  189. />}
  190. </Card>
  191. }
  192. export default React.memo(SelectComponentsUnitSearch)