adgroupsAdSetting.tsx 8.7 KB

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