adgroupsAdSetting.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { Card, DatePicker, Form, Radio, Select, Space, Switch, Tooltip } from "antd"
  2. import React, { useContext, useEffect } from "react"
  3. import { DispatchAd } from "./newCreateAd";
  4. import { RangePickerProps } from "antd/lib/date-picker";
  5. import moment from "moment";
  6. import style from '../index.less'
  7. import TimeInSelect from "@/pages/launchSystemNew/components/timeInSelect";
  8. import { QuestionCircleFilled } from "@ant-design/icons";
  9. import { AD_STATUS_ENUM, MARKETING_TARGET_TYPE_ENUM, MARKETING_TARGET_TYPE_GAME_ENUM, SelectTimeList, marketingGoalList } from "../../const";
  10. import New1Radio from "@/pages/launchSystemV3/components/New1Radio";
  11. import { txtLength } from "@/utils/utils";
  12. import InputName from "@/components/InputName";
  13. /**
  14. * 广告设置
  15. * @returns
  16. */
  17. const AdgroupsAdSetting: React.FC<{ value?: any }> = ({ value }) => {
  18. /****************************************/
  19. const { form } = useContext(DispatchAd)!;
  20. const timeSeriesType = Form.useWatch('timeSeriesType', form)
  21. const isSetfirstDayBeginTime = Form.useWatch('isSetfirstDayBeginTime', form)
  22. const marketingGoal = Form.useWatch('marketingGoal', form)
  23. const marketingTargetType = Form.useWatch('marketingTargetType', form)
  24. const dateType = Form.useWatch('dateType', form)
  25. /****************************************/
  26. useEffect(() => {
  27. if (!(value && Object.keys(value).length)) {
  28. form.setFieldsValue({
  29. adgroupName: marketingGoalList.find(item => item.value === marketingGoal)?.label + '_' + (MARKETING_TARGET_TYPE_ENUM[marketingTargetType as keyof typeof MARKETING_TARGET_TYPE_ENUM] || MARKETING_TARGET_TYPE_GAME_ENUM[marketingTargetType as keyof typeof MARKETING_TARGET_TYPE_GAME_ENUM]) + '_' + localStorage.getItem('userId')// + '_' + moment().format('MM_DD_HH:mm:ss')
  30. })
  31. }
  32. }, [marketingGoal, marketingTargetType])
  33. /** 禁止选择以前时间 */
  34. const disabledDate: RangePickerProps['disabledDate'] = current => {
  35. // Can not select days before today and today
  36. return current && current < moment().startOf('day');
  37. };
  38. return <Card
  39. title={<strong style={{ fontSize: 18 }}>广告设置</strong>}
  40. className="cardResetCss"
  41. >
  42. <Form.Item label={<strong>投放日期</strong>} required>
  43. <Space direction="vertical">
  44. <Form.Item name='dateType' noStyle>
  45. <Radio.Group
  46. onChange={e => {
  47. if (e.target.value === '0') {
  48. form.setFieldsValue({
  49. date: [moment().startOf('day').add(7, 'day'), moment().startOf('day').add(20, 'day')],
  50. beginDate: undefined
  51. })
  52. } else {
  53. form.setFieldsValue({
  54. date: undefined,
  55. beginDate: moment().startOf('day').add(7, 'day')
  56. })
  57. }
  58. }}
  59. >
  60. <Radio value="0">指定开始及结束日期</Radio>
  61. <Radio value="1">长期投放</Radio>
  62. </Radio.Group>
  63. </Form.Item>
  64. {dateType === '0' ? <Form.Item name='date' rules={[{ required: true, message: '请选择投放日期' }]} noStyle>
  65. <DatePicker.RangePicker disabledDate={disabledDate} />
  66. </Form.Item> : <Form.Item label={<strong>投放日期</strong>} name='beginDate' rules={[{ required: true, message: '请选择开始投放日期' }]} noStyle>
  67. <DatePicker disabledDate={disabledDate} />
  68. </Form.Item>}
  69. </Space>
  70. </Form.Item>
  71. <Form.Item label={<strong>投放时间</strong>}>
  72. <Card bordered className="cardResetCss newCss" bodyStyle={{ padding: 0 }}>
  73. <div className={style.newSpace}>
  74. <div className={style.newSpace_top}>
  75. <div className={style.newSpace_title}>选择时段</div>
  76. <Form.Item name='timeSeriesType' style={{ marginBottom: 0 }}>
  77. <Radio.Group>
  78. <Radio value="0">全天</Radio>
  79. <Radio value="2">指定多个时段</Radio>
  80. </Radio.Group>
  81. </Form.Item>
  82. </div>
  83. {timeSeriesType === '2' && <div className={style.newSpace_bottom}>
  84. <Form.Item name='timeSeries' noStyle rules={[{ required: true, message: '请选择时段' }]}>
  85. <TimeInSelect />
  86. </Form.Item>
  87. </div>}
  88. </div>
  89. <div className={style.newSpace}>
  90. <div className={style.newSpace_top}>
  91. <div className={style.newSpace_title}><Space>
  92. <span>首日开始时间</span>
  93. <Tooltip title={`指定了多个时段需要注意星期一到星期天都没指定的时段开始时间不可选`}>
  94. <QuestionCircleFilled />
  95. </Tooltip>
  96. </Space>
  97. </div>
  98. <Form.Item name='isSetfirstDayBeginTime' style={{ marginBottom: 0 }} valuePropName="checked">
  99. <Switch checkedChildren="开启" unCheckedChildren="关闭" />
  100. </Form.Item>
  101. </div>
  102. {isSetfirstDayBeginTime && <div className={style.newSpace_bottom}>
  103. <Form.Item name='firstDayBeginTime' noStyle rules={[{ required: true, message: '请选择首日开始时间' }]}>
  104. <Select
  105. style={{ width: 180 }}
  106. allowClear
  107. placeholder='请选择首日开始时间'
  108. options={SelectTimeList}
  109. />
  110. </Form.Item>
  111. </div>}
  112. </div>
  113. </Card>
  114. </Form.Item>
  115. <Form.Item
  116. label={<Space>
  117. <strong>自动衍生创意</strong>
  118. <Tooltip title={<div>
  119. <p>1.使用自动衍生创意,系统将优选广告下多个创意的多个组件,自动衍生新的组件并组成新的创意。在创意列表中,可通过“自建创意”、“衍生创意”类型进行区分;</p>
  120. <p>
  121. 2.广告提交后不支持再次修改
  122. </p>
  123. </div>}>
  124. <QuestionCircleFilled />
  125. </Tooltip>
  126. </Space>}
  127. name="autoDerivedCreativeEnabled"
  128. >
  129. <New1Radio data={[{ label: '系统衍生', value: true }, { label: '关闭衍生', value: false }]} />
  130. </Form.Item>
  131. <Form.Item label={<strong>广告状态</strong>} name="configuredStatus" rules={[{ required: true, message: '请选择广告状态' }]}>
  132. <New1Radio data={Object.keys(AD_STATUS_ENUM).map(key => ({ label: AD_STATUS_ENUM[key as keyof typeof AD_STATUS_ENUM], value: key }))} />
  133. </Form.Item>
  134. <Form.Item
  135. label={<strong>广告名称</strong>}
  136. name='adgroupName'
  137. // tooltip="下标、日期时分秒、广告账户创建时默认自带"
  138. rules={[
  139. { required: true, message: '请输入广告名称!' },
  140. {
  141. required: true, message: '广告名称不能包含特殊字符:< > & ‘ ” / 以及TAB、换行、回车键,请修改', validator(_, value) {
  142. let reg = /[&‘’“”/\n\t\f]/ig
  143. if (value && reg.test(value)) {
  144. return Promise.reject()
  145. }
  146. return Promise.resolve()
  147. }
  148. },
  149. {
  150. required: true, message: '请确保广告名称长度不超过60个字(1个汉字等于2个字符)', validator(_, value) {
  151. if (value && txtLength(value) > 50) {
  152. return Promise.reject()
  153. }
  154. return Promise.resolve()
  155. }
  156. }
  157. ]}
  158. >
  159. <InputName placeholder='广告名称' style={{ width: 480 }} length={50} />
  160. </Form.Item>
  161. </Card>
  162. }
  163. export default React.memo(AdgroupsAdSetting)