modal.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import React, { useCallback } from 'react'
  2. import { Modal, Form, Input, Divider, Select, Radio, DatePicker, Switch } from 'antd'
  3. import { SiteSetEnum, BidModeEnum, OptimizationGoalEnum, BidStrategyEnum } from '@/services/launchAdq/enum'
  4. import { ModalConfig } from '.'
  5. import moment from 'moment';
  6. const { RangePicker }: { RangePicker: any } = DatePicker;
  7. let DatePickers: any = DatePicker
  8. interface Props {
  9. title?: string,
  10. visible: boolean,
  11. PupFn: (arg: ModalConfig) => void,
  12. callback: (params: any) => void
  13. }
  14. function AdModal(props: Props) {
  15. let { visible, title, PupFn ,callback} = props
  16. const [form] = Form.useForm();
  17. let dateType = Form.useWatch('dateType', form)
  18. let bidMode = Form.useWatch('bidMode', form)
  19. let smartBidType = Form.useWatch('smartBidType', form)
  20. let autoAcquisitionEnabled = Form.useWatch('autoAcquisitionEnabled', form)
  21. // let siteSet = Form.useWatch('siteSet', form)
  22. // 确定事件
  23. const handleOk = useCallback(() => {
  24. form.validateFields().then(values => {
  25. let newValues = JSON.parse(JSON.stringify(values))
  26. if (newValues.dateType === '2') {
  27. newValues['beginDate'] = moment(newValues.date).format('YYYY-MM-DD')
  28. } else {
  29. newValues['beginDate'] = moment(newValues.date[0]).format('YYYY-MM-DD')
  30. newValues['endDate'] = moment(newValues.date[1]).format('YYYY-MM-DD')
  31. }
  32. delete newValues['dateType']
  33. delete newValues['date']
  34. newValues['timeSeries'] = Array(336).fill(1).join('')
  35. callback(newValues)
  36. })
  37. // PupFn({ visible: false })
  38. }, [form])
  39. return <Modal
  40. visible={visible}
  41. title={title + '广告'}
  42. onCancel={() => { PupFn({ visible: false }) }}
  43. onOk={handleOk}
  44. width={900}
  45. >
  46. <Form
  47. form={form}
  48. labelCol={{ span: 3 }}
  49. initialValues={
  50. {
  51. bidMode: 'BID_MODE_OCPM',
  52. dateType: '2',
  53. bidStrategy: 'BID_STRATEGY_AVERAGE_COST',
  54. timeSeries: '1',
  55. smartBidType: 'SMART_BID_TYPE_CUSTOM',
  56. autoAcquisitionEnabled: false,
  57. }
  58. }
  59. >
  60. {/* ============================================================基本信息============================================================= */}
  61. <Divider orientation='center'>基本信息</Divider>
  62. <Form.Item label={<strong>广告名称</strong>} name='adgroupName' rules={[{ required: true, message: '请输入广告名称!' }]}>
  63. <Input placeholder='广告名称' style={{ width: 300 }} />
  64. </Form.Item>
  65. <Form.Item label={<strong>广告版位</strong>} name='siteSet' rules={[{ required: true, message: '请输入选择广告版位!' }]}>
  66. <Select mode='multiple' style={{ width: 300 }}>
  67. {
  68. Object.keys(SiteSetEnum).map(key => {
  69. return <Select.Option value={key} key={key}>{SiteSetEnum[key]}</Select.Option>
  70. })
  71. }
  72. </Select>
  73. </Form.Item>
  74. {/* ============================================================排期与出价============================================================= */}
  75. <Divider orientation='center'>排期与出价</Divider>
  76. <Form.Item label={<strong>投放日期</strong>} name='dateType'>
  77. <Radio.Group >
  78. <Radio.Button value="1">选择开始与结束日期</Radio.Button>
  79. <Radio.Button value="2">长期投放</Radio.Button>
  80. </Radio.Group>
  81. </Form.Item>
  82. {/* 投放日期的不同展示不同的日期选择 */}
  83. {
  84. dateType === '1' ? <Form.Item name='date' rules={[{ required: true, message: '请选择日期' }]}>
  85. <RangePicker style={{ marginLeft: 107 }}></RangePicker>
  86. </Form.Item> : <Form.Item name='date' style={{ marginLeft: 107 }} rules={[{ required: true, message: '请选择日期' }]}>
  87. <DatePickers />
  88. </Form.Item>
  89. }
  90. <Form.Item label={<strong>投放时段</strong>}>
  91. <Radio.Group name='timeSeries' defaultValue='1'>
  92. <Radio.Button value={'1'}>全天投放</Radio.Button>
  93. </Radio.Group>
  94. </Form.Item>
  95. <Form.Item label={<strong>出价方式</strong>} name='bidMode'>
  96. <Radio.Group >
  97. {
  98. Object.keys(BidModeEnum).map(key => {
  99. return <Radio.Button value={key} key={key} disabled={!key.includes('CPM')}>{BidModeEnum[key]}</Radio.Button>
  100. })
  101. }
  102. </Radio.Group>
  103. </Form.Item>
  104. {/* 出价方式为OCPM才展示 */}
  105. {
  106. bidMode === 'BID_MODE_OCPM' && <>
  107. <Form.Item label={<strong>优化目标</strong>} name='optimizationGoal' rules={[{ required: true, message: '请选择优化目标' }]}>
  108. <Select style={{ width: 300 }} showSearch filterOption={(input, option) =>
  109. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  110. }>
  111. {
  112. Object.keys(OptimizationGoalEnum).map(key => {
  113. return <Select.Option value={key} key={key}>{OptimizationGoalEnum[key]}</Select.Option>
  114. })
  115. }
  116. </Select>
  117. </Form.Item>
  118. <Form.Item label={<strong>出价类型</strong>} name='smartBidType'>
  119. <Radio.Group >
  120. <Radio.Button value="SMART_BID_TYPE_CUSTOM">手动出价</Radio.Button>
  121. <Radio.Button value="SMART_BID_TYPE_SYSTEMATIC">自动出价</Radio.Button>
  122. </Radio.Group>
  123. </Form.Item>
  124. <Form.Item label={<strong>出价策略</strong>} name='bidStrategy'>
  125. <Radio.Group >
  126. {
  127. Object.keys(BidStrategyEnum).map(key => {
  128. return <Radio.Button value={key} key={key} disabled={smartBidType === 'SMART_BID_TYPE_SYSTEMATIC' && key === 'BID_STRATEGY_PRIORITY_CAP_COST'}> {BidStrategyEnum[key]}</Radio.Button>
  129. })
  130. }
  131. </Radio.Group>
  132. </Form.Item>
  133. </>
  134. }
  135. {/* 出价类型为手动出价才展示 */}
  136. {
  137. smartBidType !== 'SMART_BID_TYPE_SYSTEMATIC' && <>
  138. <Form.Item label={<strong>出价</strong>} name='bidAmount' rules={[{ required: true, message: '请输入价格' }]}>
  139. <Input placeholder='输入价格 元/千次曝光' style={{ width: 300 }} />
  140. </Form.Item>
  141. {/* 当版位选择大于1时才出现 */}
  142. {/* {siteSet?.length > 1 &&<Form.Item label={<strong>分版位出价</strong>} name='bidAdjustment'>
  143. <Switch checkedChildren="开启" unCheckedChildren="关闭" />
  144. </Form.Item>} */}
  145. <Form.Item label={<strong>一键起量</strong>} name='autoAcquisitionEnabled' valuePropName="checked">
  146. <Switch checkedChildren="开启" unCheckedChildren="关闭" />
  147. </Form.Item>
  148. {/* 一键起量开启时才出现 */}
  149. {autoAcquisitionEnabled && <Form.Item label={<strong>起量预算</strong>} name='autoAcquisitionBudget' rules={[{ required: true, message: '请输入起量预算' }]}>
  150. <Input placeholder='起量预算' style={{ width: 300 }} />
  151. </Form.Item>}
  152. </>
  153. }
  154. <Form.Item label={<strong>广告日预算</strong>} name='dailyBudget'>
  155. <Input placeholder='不填默认为不限' style={{ width: 300 }} />
  156. </Form.Item>
  157. </Form>
  158. </Modal >
  159. }
  160. export default AdModal