newCreateAd.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import { Button, Form, Modal, Space, message } from "antd"
  2. import React, { useEffect, useState } from "react"
  3. import '../../index.less'
  4. import { defaultMarketingGoal, defaultSiteSet } from "../../const"
  5. import AdgroupsMarketingContent from "./adgroupsMarketingContent"
  6. import AdgroupsSitSet from "./adgroupsSitSet"
  7. import AdgroupsPrice from "./adgroupsPrice"
  8. import AdgroupsAdSetting from "./adgroupsAdSetting"
  9. import moment from "moment"
  10. import { getTimeSeriesList } from "@/pages/launchSystemNew/adq/ad/const"
  11. export const DispatchAd = React.createContext<PULLIN.AdReactContent | null>(null);
  12. interface Props {
  13. value?: any,
  14. visible?: boolean
  15. onClose?: () => void
  16. onChange?: (value: any) => void
  17. }
  18. /**
  19. * 广告
  20. * @param param0
  21. * @returns
  22. */
  23. const NewCreateAd: React.FC<Props> = ({ value, visible, onChange, onClose }) => {
  24. /***********************************/
  25. const [form] = Form.useForm();
  26. // 深度优化副作用参数
  27. const [OGPParams, setOGPparams] = useState<PULLIN.OGPParamsProps>({ bidMode: 'BID_MODE_OCPM', siteSet: defaultSiteSet, automaticSiteEnabled: false, marketingGoal: defaultMarketingGoal })
  28. /***********************************/
  29. const handleOk = (values: any) => {
  30. const {
  31. wechatPositionType, // 微信公众号与小程序定投
  32. wechatChannelsSceneType, // 微信视频号定投
  33. wechatSceneType, // 微信公众号与小程序场景
  34. marketingTargetType, // 推广产品
  35. tencentNewsType,
  36. displaySceneType,
  37. date, // 开始时间 结束时间
  38. timeSeriesType, // 选择时段类型
  39. timeSeries, // 时段
  40. isSetfirstDayBeginTime, // 首日开始时间是否开启
  41. ...surplusValues
  42. } = values
  43. let adgroupsValues: any = {
  44. ...surplusValues,
  45. beginDate: moment(date?.[0]).format('YYYY-MM-DD'),
  46. endDate: moment(date?.[1]).format('YYYY-MM-DD'),
  47. }
  48. if (marketingTargetType) {
  49. adgroupsValues.marketingAssetOuterSpec = {
  50. marketingTargetType
  51. }
  52. }
  53. // 投放时段处理
  54. if (timeSeriesType === '0') {
  55. adgroupsValues.timeSeries = Array(336).fill(1).join('');
  56. } else {
  57. adgroupsValues.timeSeries = timeSeries.join('');
  58. }
  59. Object.keys(adgroupsValues).forEach(key => {
  60. if (adgroupsValues[key] === undefined || adgroupsValues === null) {
  61. delete adgroupsValues[key]
  62. }
  63. })
  64. onChange?.(adgroupsValues)
  65. }
  66. // 数据回填
  67. useEffect(() => {
  68. if (value && Object.keys(value).length > 0) {
  69. const {
  70. firstDayBeginTime,
  71. timeSeries,
  72. beginDate,
  73. endDate,
  74. sceneSpec,
  75. marketingAssetOuterSpec,
  76. autoDerivedCreativeEnabled,
  77. ...surplusValues
  78. } = JSON.parse(JSON.stringify(value))
  79. let adgroupsValues: any = {
  80. ...surplusValues,
  81. sceneSpec,
  82. marketingTargetType: marketingAssetOuterSpec?.marketingTargetType,
  83. autoDerivedCreativeEnabled: autoDerivedCreativeEnabled ? true : false
  84. }
  85. // 首日开始时间
  86. if (firstDayBeginTime) {
  87. adgroupsValues.firstDayBeginTime = firstDayBeginTime
  88. adgroupsValues.isSetfirstDayBeginTime = true
  89. } else {
  90. adgroupsValues.isSetfirstDayBeginTime = false
  91. }
  92. // 时段
  93. if (timeSeries && timeSeries.includes('0')) {
  94. adgroupsValues.timeSeriesType = '2'
  95. } else {
  96. adgroupsValues.timeSeriesType = '0'
  97. }
  98. adgroupsValues.timeSeries = timeSeries?.split('') || getTimeSeriesList()
  99. // 投放时间
  100. adgroupsValues.date = [moment(beginDate), moment(endDate)]
  101. // 微信公众号与小程序定投
  102. if (sceneSpec?.wechatPosition?.length > 0) {
  103. adgroupsValues.wechatPositionType = '1'
  104. } else {
  105. adgroupsValues.wechatPositionType = '0'
  106. }
  107. // 微信视频号定投
  108. if (sceneSpec?.wechatChannelsScene?.length > 0) {
  109. adgroupsValues.wechatChannelsSceneType = '1'
  110. } else {
  111. adgroupsValues.wechatChannelsSceneType = '0'
  112. }
  113. // 微信公众号与小程序场景
  114. if (sceneSpec?.wechatScene && Object.keys(sceneSpec.wechatScene).length > 0) {
  115. adgroupsValues.wechatSceneType = '1'
  116. } else {
  117. adgroupsValues.wechatSceneType = '0'
  118. }
  119. // 腾讯新闻流量场景
  120. if (sceneSpec?.tencentNews && sceneSpec.tencentNews?.length > 0) {
  121. adgroupsValues.tencentNewsType = '1'
  122. } else {
  123. adgroupsValues.tencentNewsType = '0'
  124. }
  125. // 优量汇广告展示场景
  126. if (sceneSpec?.displayScene && sceneSpec.displayScene?.length > 0) {
  127. adgroupsValues.displaySceneType = '1'
  128. } else {
  129. adgroupsValues.displaySceneType = '0'
  130. }
  131. setOGPparams({
  132. bidMode: adgroupsValues.bidMode,
  133. siteSet: adgroupsValues.siteSet,
  134. automaticSiteEnabled: adgroupsValues.automaticSiteEnabled,
  135. marketingGoal: adgroupsValues.marketingGoal,
  136. marketingCarrierType: adgroupsValues?.marketingCarrierType,
  137. marketingTargetType: adgroupsValues?.marketingTargetType
  138. })
  139. form.setFieldsValue({ ...adgroupsValues })
  140. }
  141. }, [value])
  142. return <Modal
  143. title={<strong style={{ fontSize: 20 }}>广告的基本信息</strong>}
  144. visible={visible}
  145. onCancel={onClose}
  146. footer={null}
  147. width={900}
  148. className={`modalResetCss`}
  149. bodyStyle={{ padding: '0 0 40px', position: 'relative', borderRadius: '0 0 8px 8px' }}
  150. maskClosable={false}
  151. >
  152. <Form
  153. form={form}
  154. name="newAd"
  155. labelAlign='left'
  156. layout="vertical"
  157. colon={false}
  158. style={{ backgroundColor: '#f1f4fc', maxHeight: 650, overflow: 'hidden', overflowY: 'auto', padding: '0 10px 10px', borderRadius: '0 0 8px 8px' }}
  159. scrollToFirstError={{
  160. behavior: 'smooth',
  161. block: 'center'
  162. }}
  163. onFinishFailed={({ errorFields }) => {
  164. message.error(errorFields?.[0]?.errors?.[0])
  165. }}
  166. onFinish={handleOk}
  167. initialValues={{
  168. marketingGoal: defaultMarketingGoal,
  169. automaticSiteEnabled: false,
  170. siteSet: defaultSiteSet,
  171. searchExpandTargetingSwitch: 'SEARCH_EXPAND_TARGETING_SWITCH_OPEN',
  172. bidMode: 'BID_MODE_OCPM',
  173. smartBidType: 'SMART_BID_TYPE_CUSTOM',
  174. optimizationGoal: 'OPTIMIZATIONGOAL_ECOMMERCE_ORDER',
  175. depthConversionEnabled: true,
  176. deepConversionSpec: {
  177. deepConversionType: 'DEEP_CONVERSION_WORTH'
  178. },
  179. // bidAmount: 1000,
  180. timeSeries: getTimeSeriesList(),
  181. autoAcquisitionEnabled: false,
  182. configuredStatus: 'AD_STATUS_SUSPEND',
  183. // adgroupName: '<营销目的>-<推广产品>-<日期>-<时分秒>',
  184. // marketingTargetType: 'MARKETING_TARGET_TYPE_FICTION'
  185. // 自定义字段
  186. date: [moment().startOf('day').add(7, 'day'), moment().startOf('day').add(20, 'day')],
  187. wechatPositionType: '0',
  188. wechatSceneType: '0',
  189. displaySceneType: '0',
  190. tencentNewsType: '0',
  191. wechatChannelsSceneType: '0',
  192. timeSeriesType: '0',
  193. isSetfirstDayBeginTime: false,
  194. autoDerivedCreativeEnabled: false
  195. }}
  196. >
  197. <DispatchAd.Provider value={{ form, OGPParams, setOGPparams }}>
  198. <Space direction="vertical" style={{ width: '100%' }}>
  199. {/* 营销内容 */}
  200. <AdgroupsMarketingContent value={value} />
  201. {/* 广告版位 */}
  202. <AdgroupsSitSet />
  203. {/* 出价与预算 */}
  204. <AdgroupsPrice />
  205. {/* 广告设置 */}
  206. <AdgroupsAdSetting value={value} />
  207. </Space>
  208. </DispatchAd.Provider>
  209. <Form.Item className="submit_pull">
  210. <Space>
  211. <Button onClick={onClose}>取消</Button>
  212. <Button type="primary" htmlType="submit" className="modalResetCss">
  213. 确定
  214. </Button>
  215. </Space>
  216. </Form.Item>
  217. </Form>
  218. </Modal>
  219. }
  220. export default React.memo(NewCreateAd)