modal.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import React, { useCallback, useEffect } from 'react'
  2. import { Modal, Form, Input, Divider, Select, Radio, DatePicker, Switch, Checkbox, message } from 'antd'
  3. import { SiteSetEnum, BidModeEnum, OptimizationGoalEnum, BidStrategyEnum, PromotedObjectType, EducationEnum } from '@/services/launchAdq/enum'
  4. import { ModalConfig } from '.'
  5. import moment from 'moment';
  6. import { useAjax } from '@/Hook/useAjax';
  7. import { getSceneTagsList } from '@/services/launchAdq/global';
  8. const { RangePicker }: { RangePicker: any } = DatePicker;
  9. let DatePickers: any = DatePicker
  10. interface Props {
  11. visible: boolean,
  12. PupFn: (arg: ModalConfig) => void,
  13. callback: (params: any) => void,
  14. confirmLoading: boolean,
  15. type?: 'add' | 'look' | 'edit',//新增,查看,编辑
  16. dataInfo?: any
  17. }
  18. /**广告模板*/
  19. function AdModal(props: Props) {
  20. let { visible, confirmLoading, PupFn, callback, type, dataInfo } = props
  21. let arg = type === 'look' ? { footer: null } : {}
  22. const sceneTagsList = useAjax((params) => getSceneTagsList(params))
  23. const [form] = Form.useForm();
  24. let dateType = Form.useWatch('dateType', form)
  25. let bidMode = Form.useWatch('bidMode', form)
  26. let smartBidType = Form.useWatch('smartBidType', form)
  27. let autoAcquisitionEnabled = Form.useWatch('autoAcquisitionEnabled', form)
  28. let siteSet = Form.useWatch('siteSet', form)
  29. let wechatPositionType = Form.useWatch('wechatPositionType', form)
  30. let wechatSceneType = Form.useWatch('wechatSceneType', form)
  31. // 确定事件
  32. const handleOk = useCallback(() => {
  33. form.validateFields().then(values => {
  34. let newValues = JSON.parse(JSON.stringify(values))
  35. newValues.sceneSpec = {}
  36. if (newValues.dateType === '2') {
  37. newValues['beginDate'] = moment(newValues.date).format('YYYY-MM-DD')
  38. } else {
  39. newValues['beginDate'] = moment(newValues.date[0]).format('YYYY-MM-DD')
  40. newValues['endDate'] = moment(newValues.date[1]).format('YYYY-MM-DD')
  41. }
  42. Object.keys(newValues).forEach(key => {
  43. switch (key) {
  44. case 'wechatPositionType':
  45. if (newValues[key] === '1') {
  46. newValues.sceneSpec = { ...newValues.sceneSpec, wechatPosition: newValues.wechatPosition }
  47. }
  48. break;
  49. case 'wechatSceneType':
  50. if (newValues[key] === '1') {
  51. newValues.sceneSpec = {
  52. ...newValues.sceneSpec, wechatScene: {
  53. officialAccountMediaCategory: newValues.officialAccountMediaCategory,
  54. miniProgramAndMiniGame: newValues.miniProgramAndMiniGame,
  55. payScene: newValues.payScene
  56. }
  57. }
  58. }
  59. break;
  60. }
  61. })
  62. if (newValues.sceneSpec.wechatPosition?.length === 0) {
  63. delete newValues.sceneSpec.wechatPosition
  64. }
  65. if (newValues.sceneSpec.wechatScene) {
  66. newValues.sceneSpec.wechatScene.officialAccountMediaCategory?.length === 0 && (delete newValues.sceneSpec.wechatScene.officialAccountMediaCategory)
  67. newValues.sceneSpec.wechatScene.miniProgramAndMiniGame?.length === 0 && (delete newValues.sceneSpec.wechatScene.miniProgramAndMiniGame)
  68. newValues.sceneSpec.wechatScene.payScene?.length === 0 && (delete newValues.sceneSpec.wechatScene.payScene)
  69. }
  70. if (!newValues.sceneSpec.wechatPosition && !newValues.sceneSpec.wechatScene) {
  71. delete newValues.sceneSpec
  72. }
  73. delete newValues.officialAccountMediaCategory
  74. delete newValues.miniProgramAndMiniGame
  75. delete newValues.payScene
  76. delete newValues.wechatPositionType
  77. delete newValues.wechatPosition
  78. delete newValues.wechatScene
  79. delete newValues['dateType']
  80. delete newValues['date']
  81. newValues['timeSeries'] = Array(336).fill(1).join('')
  82. console.log(newValues)
  83. callback(newValues)
  84. })
  85. }, [form])
  86. // 场景定向
  87. useEffect(() => {
  88. sceneTagsList.run({ typeList: ['WECHAT_POSITION', 'OFFICIAL_ACCOUNT_MEDIA_CATEGORY', 'MINI_PROGRAM_AND_MINI_GAME', 'PAY_SCENE'] })
  89. }, [])
  90. // 数据回填
  91. useEffect(() => {
  92. if (dataInfo) {
  93. form.setFieldsValue({
  94. adgroupName: dataInfo?.adgroupName,//广告名称
  95. promotedObjectType: dataInfo?.promotedObjectType,//推广目标
  96. siteSet: dataInfo?.siteSet,//广告版位
  97. autoAcquisitionEnabled: dataInfo?.autoAcquisitionEnabled,//一键起量
  98. bidAmount: dataInfo?.bidAmount,//出价
  99. smartBidType: dataInfo?.smartBidType,//出价类型
  100. bidStrategy: dataInfo?.bidStrategy,//出价策略
  101. bidMode: dataInfo?.bidMode,//出价方式
  102. optimizationGoal: dataInfo?.optimizationGoal,//优化目标
  103. dateType: dataInfo?.endDate ? '1' : '2',//投放日期
  104. dailyBudget: dataInfo?.dailyBudget,//广告日预算
  105. date: dataInfo?.endDate ? [moment(dataInfo?.beginDate), moment(dataInfo?.endDate)] : moment(dataInfo?.beginDate),//日期
  106. autoAcquisitionBudget: dataInfo?.autoAcquisitionBudget,//起量预算
  107. wechatPositionType: dataInfo?.sceneSpec?.wechatPosition ? '1' : '0',//微信公众号与小程序定投
  108. wechatPosition: dataInfo?.sceneSpec?.wechatPosition,//微信公众号与小程序定投
  109. wechatSceneType: dataInfo?.sceneSpec?.wechatScene?.officialAccountMediaCategory || dataInfo?.sceneSpec?.wechatScene?.miniProgramAndMiniGame || dataInfo?.sceneSpec?.wechatScene?.payScene ? '1' : '0',//微信公众号与小程序场景
  110. officialAccountMediaCategory: dataInfo?.sceneSpec?.wechatScene?.officialAccountMediaCategory,//公众号媒体类型
  111. miniProgramAndMiniGame: dataInfo?.sceneSpec?.wechatScene?.miniProgramAndMiniGame,//小程序小游戏流量类型
  112. payScene: dataInfo?.sceneSpec?.wechatScene?.payScene,//订单详情页消费场景
  113. })
  114. }
  115. }, [dataInfo])
  116. return <Modal
  117. visible={visible}
  118. title={type === 'add' ? '新建广告' : type === 'look' ? '广告详情' : '编辑广告'}
  119. onCancel={() => { PupFn({ visible: false,dataInfo:null,type:'add' }) }}
  120. onOk={type === 'look' ? () => message.warning('详情无法改动内容') : handleOk}
  121. width={900}
  122. confirmLoading={confirmLoading}
  123. {...arg}
  124. >
  125. <Form
  126. form={form}
  127. labelCol={{ span: 5 }}
  128. initialValues={
  129. {
  130. promotedObjectType: 'PROMOTED_OBJECT_TYPE_WECHAT_OFFICIAL_ACCOUNT',
  131. siteSet: ['SITE_SET_MOMENTS', 'SITE_SET_WECHAT'],
  132. bidMode: 'BID_MODE_OCPM',
  133. dateType: '2',
  134. bidStrategy: 'BID_STRATEGY_AVERAGE_COST',
  135. timeSeries: '1',
  136. smartBidType: 'SMART_BID_TYPE_CUSTOM',
  137. autoAcquisitionEnabled: false,
  138. wechatSceneType: '0',
  139. wechatPositionType: '0',
  140. }
  141. }
  142. >
  143. {/* ============================================================基本信息============================================================= */}
  144. <Divider orientation='center'>基本信息</Divider>
  145. <Form.Item label={<strong>广告名称</strong>} name='adgroupName' rules={[{ required: true, message: '请输入广告名称!' }]}>
  146. <Input placeholder='广告名称' style={{ width: 300 }} />
  147. </Form.Item>
  148. <Form.Item label={<strong>推广目标类型</strong>} name='promotedObjectType' rules={[{ required: true, message: '请选择推广告推广目标类型!' }]}>
  149. <Select style={{ width: 300 }} showSearch filterOption={(input, option) =>
  150. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  151. } allowClear>
  152. {
  153. Object.keys(PromotedObjectType).map(key => {
  154. return <Select.Option value={key} key={key}>{PromotedObjectType[key]}</Select.Option>
  155. })
  156. }
  157. </Select>
  158. </Form.Item>
  159. <Form.Item label={<strong>广告版位</strong>} name='siteSet' rules={[{ required: true, message: '请输入选择广告版位!' }]}>
  160. <Select mode='multiple' style={{ width: 300 }} allowClear>
  161. {
  162. Object.keys(SiteSetEnum).map(key => {
  163. return <Select.Option value={key} key={key}>{SiteSetEnum[key]}</Select.Option>
  164. })
  165. }
  166. </Select>
  167. </Form.Item>
  168. {
  169. siteSet?.some((s: string) => s === 'SITE_SET_WECHAT') && <>
  170. <Form.Item label={<strong>微信公众号与小程序定投</strong>} name='wechatPositionType' style={wechatPositionType === '1' ? { marginBottom: 5 } : {}}>
  171. <Radio.Group >
  172. <Radio.Button value="0">不限</Radio.Button>
  173. <Radio.Button value="1">自定义</Radio.Button>
  174. </Radio.Group>
  175. </Form.Item>
  176. {wechatPositionType === '1' && <Form.Item style={{ marginLeft: 177 }} name='wechatPosition'>
  177. <Checkbox.Group options={sceneTagsList?.data?.WECHAT_POSITION?.map((item: { description: any; id: any; }) => ({ label: item.description, value: item.id }))} />
  178. </Form.Item>}
  179. <Form.Item label={<strong>微信公众号与小程序场景</strong>} name='wechatSceneType' style={wechatSceneType === '1' ? { marginBottom: 5 } : {}} >
  180. <Radio.Group >
  181. <Radio.Button value="0">不限</Radio.Button>
  182. <Radio.Button value="1">自定义</Radio.Button>
  183. </Radio.Group>
  184. </Form.Item>
  185. {wechatSceneType === '1' && <>
  186. <p style={{ marginBottom: 5, marginLeft: 177 }}><strong style={{ marginRight: 20 }}>公众号媒体类型</strong></p>
  187. <Form.Item style={{ marginLeft: 177 }} name='officialAccountMediaCategory'>
  188. <Checkbox.Group options={sceneTagsList?.data?.OFFICIAL_ACCOUNT_MEDIA_CATEGORY?.filter((i: { description: string; }) => i.description !== '不限')?.map((item: { description: any; id: any; }) => ({ label: item.description, value: item.id }))} />
  189. </Form.Item>
  190. <p style={{ marginBottom: 5, marginLeft: 177 }}><strong style={{ marginRight: 20 }}>小程序小游戏流量类型</strong></p>
  191. <Form.Item style={{ marginLeft: 177 }} name='miniProgramAndMiniGame'>
  192. <Checkbox.Group options={sceneTagsList?.data?.MINI_PROGRAM_AND_MINI_GAME?.filter((i: { description: string; }) => i.description !== '不限')?.map((item: { description: any; id: any; }) => ({ label: item.description, value: item.id }))} />
  193. </Form.Item>
  194. <p style={{ marginBottom: 5, marginLeft: 177 }}><strong style={{ marginRight: 20 }}>订单详情页消费场景</strong></p>
  195. <Form.Item style={{ marginLeft: 177 }} name='payScene'>
  196. <Checkbox.Group options={sceneTagsList?.data?.PAY_SCENE?.filter((i: { description: string; }) => i.description !== '不限')?.map((item: { description: any; id: any; }) => ({ label: item.description, value: item.id }))} />
  197. </Form.Item>
  198. </>}
  199. </>
  200. }
  201. {/* ============================================================排期与出价============================================================= */}
  202. <Divider orientation='center'>排期与出价</Divider>
  203. <Form.Item label={<strong>投放日期</strong>} name='dateType'>
  204. <Radio.Group >
  205. <Radio.Button value="1">选择开始与结束日期</Radio.Button>
  206. <Radio.Button value="2">长期投放</Radio.Button>
  207. </Radio.Group>
  208. </Form.Item>
  209. {/* 投放日期的不同展示不同的日期选择 */}
  210. {
  211. dateType === '1' ? <Form.Item name='date' rules={[{ required: true, message: '请选择日期' }]}>
  212. <RangePicker style={{ marginLeft: 177 }}></RangePicker>
  213. </Form.Item> : <Form.Item name='date' style={{ marginLeft: 177 }} rules={[{ required: true, message: '请选择日期' }]}>
  214. <DatePickers />
  215. </Form.Item>
  216. }
  217. <Form.Item label={<strong>投放时段</strong>}>
  218. <Radio.Group name='timeSeries' defaultValue='1'>
  219. <Radio.Button value={'1'}>全天投放</Radio.Button>
  220. </Radio.Group>
  221. </Form.Item>
  222. <Form.Item label={<strong>出价方式</strong>} name='bidMode'>
  223. <Radio.Group >
  224. {
  225. Object.keys(BidModeEnum).map(key => {
  226. return <Radio.Button value={key} key={key} disabled={!key.includes('CPM')}>{BidModeEnum[key]}</Radio.Button>
  227. })
  228. }
  229. </Radio.Group>
  230. </Form.Item>
  231. {/* 出价方式为OCPM才展示 */}
  232. {
  233. bidMode === 'BID_MODE_OCPM' && <>
  234. <Form.Item label={<strong>优化目标</strong>} name='optimizationGoal' rules={[{ required: true, message: '请选择优化目标' }]}>
  235. <Select style={{ width: 300 }} showSearch filterOption={(input, option) =>
  236. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  237. } allowClear>
  238. {
  239. Object.keys(OptimizationGoalEnum).map(key => {
  240. return <Select.Option value={key} key={key}>{OptimizationGoalEnum[key]}</Select.Option>
  241. })
  242. }
  243. </Select>
  244. </Form.Item>
  245. <Form.Item label={<strong>出价类型</strong>} name='smartBidType'>
  246. <Radio.Group >
  247. <Radio.Button value="SMART_BID_TYPE_CUSTOM">手动出价</Radio.Button>
  248. <Radio.Button value="SMART_BID_TYPE_SYSTEMATIC">自动出价</Radio.Button>
  249. </Radio.Group>
  250. </Form.Item>
  251. <Form.Item label={<strong>出价策略</strong>} name='bidStrategy'>
  252. <Radio.Group >
  253. {
  254. Object.keys(BidStrategyEnum).map(key => {
  255. return <Radio.Button value={key} key={key} disabled={smartBidType === 'SMART_BID_TYPE_SYSTEMATIC' && key === 'BID_STRATEGY_PRIORITY_CAP_COST'}> {BidStrategyEnum[key]}</Radio.Button>
  256. })
  257. }
  258. </Radio.Group>
  259. </Form.Item>
  260. </>
  261. }
  262. {/* 出价类型为手动出价才展示 */}
  263. {
  264. smartBidType !== 'SMART_BID_TYPE_SYSTEMATIC' && <>
  265. <Form.Item label={<strong>出价</strong>} name='bidAmount' rules={[{ required: true, message: '请输入价格' }]}>
  266. <Input placeholder='输入价格 元/千次曝光' style={{ width: 300 }} />
  267. </Form.Item>
  268. {/* 当版位选择大于1时才出现 */}
  269. {/* {siteSet?.length > 1 &&<Form.Item label={<strong>分版位出价</strong>} name='bidAdjustment'>
  270. <Switch checkedChildren="开启" unCheckedChildren="关闭" />
  271. </Form.Item>} */}
  272. <Form.Item label={<strong>一键起量</strong>} name='autoAcquisitionEnabled' valuePropName="checked">
  273. <Switch checkedChildren="开启" unCheckedChildren="关闭" />
  274. </Form.Item>
  275. {/* 一键起量开启时才出现 */}
  276. {autoAcquisitionEnabled && <Form.Item label={<strong>起量预算</strong>} name='autoAcquisitionBudget' rules={[{ required: true, message: '请输入起量预算' }]}>
  277. <Input placeholder='起量预算' style={{ width: 300 }} />
  278. </Form.Item>}
  279. </>
  280. }
  281. <Form.Item label={<strong>广告日预算</strong>} name='dailyBudget'>
  282. <Input placeholder='不填默认为不限' style={{ width: 300 }} />
  283. </Form.Item>
  284. </Form>
  285. </Modal >
  286. }
  287. export default AdModal