copy.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { copyAdAdApi } from "@/services/launchAdq/adq"
  3. import { Checkbox, DatePicker, Form, InputNumber, message, Modal, notification, Radio, Select, Space, Switch, TimePicker } from "antd"
  4. import React, { useState } from "react"
  5. import moment from "moment"
  6. import { getTimeSeriesList } from "./const"
  7. import TimeInSelect from "../../components/timeInSelect"
  8. import { RangePickerProps } from "antd/lib/date-picker"
  9. const { RangePicker } = DatePicker;
  10. let DatePickers: any = DatePicker
  11. interface Props {
  12. visible?: boolean,
  13. onChange?: () => void,
  14. onClose?: () => void,
  15. selectedRows: any[]
  16. }
  17. const Copy: React.FC<Props> = (props) => {
  18. /**********************************/
  19. const { visible, onChange, onClose, selectedRows } = props
  20. const [form] = Form.useForm();
  21. let dateType = Form.useWatch('dateType', form)
  22. const [state, setState] = useState<any>({ isShowTime: [] })
  23. const [timeSeriesType, setTimeSeriesType] = useState<'allDayLong' | 'timeInterValS'>('allDayLong')
  24. const copyAdAd = useAjax((params) => copyAdAdApi(params))
  25. /**********************************/
  26. const handleOk = () => {
  27. form.validateFields().then(values => {
  28. let newValues = JSON.parse(JSON.stringify(values))
  29. if (newValues?.date) {
  30. if (newValues.dateType === '2') {
  31. newValues['beginDate'] = moment(newValues.date).format('YYYY-MM-DD')
  32. newValues['endDate'] = ''
  33. } else {
  34. newValues['beginDate'] = moment(newValues.date[0]).format('YYYY-MM-DD')
  35. newValues['endDate'] = moment(newValues.date[1]).format('YYYY-MM-DD')
  36. }
  37. }
  38. if (newValues?.timeSeries) {
  39. newValues['timeSeries'] = newValues.timeSeries.join('')
  40. }
  41. if (timeSeriesType === 'allDayLong') {
  42. newValues.timeSeries = getTimeSeriesList().join('')
  43. }
  44. if (newValues.firstDayBeginTime) {
  45. newValues['firstDayBeginTime'] = moment(newValues.firstDayBeginTime).format('HH:mm:ss')
  46. }
  47. delete newValues?.date
  48. delete newValues?.dateType
  49. if (newValues?.bidAmount) {
  50. newValues.bidAmount = newValues.bidAmount * 100
  51. }
  52. console.log(newValues);
  53. copyAdAd.run({ ...newValues, adgroupIds: selectedRows.map((item: { adgroupId: number }) => item.adgroupId) }).then(res => {
  54. if (res) {
  55. message.success(`复制操作完成.结果请在操作记录查询!`)//成功: ${res.success},失败: ${res.fail}
  56. if (res?.fail) {
  57. notification.error({
  58. message: `复制失败`,
  59. description: `成功: ${res.success},复制失败${res.fail}条,失败的请到任务列表查看`,
  60. duration: 0
  61. });
  62. }
  63. onChange?.()
  64. }
  65. })
  66. })
  67. }
  68. /** 禁止选择以前时间 */
  69. const disabledDate: RangePickerProps['disabledDate'] = current => {
  70. // Can not select days before today and today
  71. return current && current < moment().startOf('day');
  72. };
  73. return <Modal
  74. title="复制广告"
  75. visible={visible}
  76. onOk={handleOk}
  77. width={800}
  78. onCancel={() => onClose?.()}
  79. confirmLoading={copyAdAd.loading}
  80. >
  81. <Form
  82. form={form}
  83. labelCol={{ span: 4 }}
  84. className='ad_form_style'
  85. colon={false}
  86. initialValues={{
  87. dateType: '2',
  88. date: moment().startOf('day'),
  89. timeSeries: getTimeSeriesList(),
  90. firstDayBeginTime: moment('2023-02-24 00:00:00'),
  91. copyCount: 1,
  92. configuredStatus: null,
  93. isCopyAdcreative: true
  94. }}
  95. >
  96. <Form.Item label={<strong>投放日期</strong>} name='dateType'>
  97. <Radio.Group onChange={(e) => {
  98. if (e.target.value === "1") {
  99. form.setFieldsValue({ date: [moment().startOf('day'), moment().startOf('day').add(1, 'M')] })
  100. }
  101. if (e.target.value === "2") {
  102. form.setFieldsValue({ date: moment().startOf('day') })
  103. }
  104. }}>
  105. <Radio.Button value="1">选择开始与结束日期</Radio.Button>
  106. <Radio.Button value="2">长期投放</Radio.Button>
  107. </Radio.Group>
  108. </Form.Item>
  109. {/* 投放日期的不同展示不同的日期选择 */}
  110. {dateType === '1' ? <Form.Item name='date' rules={[{ required: true, message: '请选择日期' }]}>
  111. <RangePicker style={{ marginLeft: 125 }} disabledDate={disabledDate}></RangePicker>
  112. </Form.Item> : <Form.Item name='date' style={{ marginLeft: 125 }} rules={[{ required: true, message: '请选择日期' }]}>
  113. <DatePickers disabledDate={disabledDate} />
  114. </Form.Item>}
  115. <Form.Item label={<strong>投放时段</strong>} style={{ marginBottom: 0 }}>
  116. <Space direction='vertical' style={{ width: '100%' }}>
  117. <Radio.Group
  118. name='timeSeriesType'
  119. value={timeSeriesType}
  120. onChange={(value) => {
  121. setTimeSeriesType(value.target.value)
  122. if (value.target.value === 'timeInterValS') {
  123. setState({ isShowTime: ['1'] })
  124. }
  125. }}>
  126. <Radio.Button value={'allDayLong'}>全天投放</Radio.Button>
  127. <Radio.Button value={'timeInterValS'}>指定多个时段</Radio.Button>
  128. </Radio.Group>
  129. {timeSeriesType === 'timeInterValS' && <Form.Item name='timeSeries' noStyle rules={[{ required: true, message: '请选择时段' }]}>
  130. <TimeInSelect />
  131. </Form.Item>}
  132. </Space>
  133. </Form.Item>
  134. <Form.Item label={<strong></strong>}>
  135. <Space>
  136. <Checkbox.Group options={[{ label: '指定首日开始投放时间', value: '1' }]} disabled={timeSeriesType === 'timeInterValS'} value={state.isShowTime} onChange={(checkedValue) => { setState({ ...state, isShowTime: checkedValue }) }} />
  137. {state?.isShowTime?.length > 0 && <Form.Item name='firstDayBeginTime' noStyle rules={[{ required: true, message: '请选择时间' }]}>
  138. <TimePicker />
  139. </Form.Item>}
  140. </Space>
  141. </Form.Item>
  142. <Form.Item label={<strong>广告出价</strong>} name={"bidAmount"}>
  143. <InputNumber min={0} placeholder="价格 元" />
  144. </Form.Item>
  145. <Form.Item label={<strong>广告启停</strong>} name={"configuredStatus"} tooltip="默认:沿用选择广告的启停状态,开启or关闭:复制的所有广告设置成开启or关闭">
  146. <Select style={{ width: 100 }}>
  147. <Select.Option key={null} value={null}>默认</Select.Option>
  148. <Select.Option key={"AD_STATUS_NORMAL"} value={"AD_STATUS_NORMAL"}>开启</Select.Option>
  149. <Select.Option key={"AD_STATUS_SUSPEND"} value={"AD_STATUS_SUSPEND"}>关闭</Select.Option>
  150. </Select>
  151. </Form.Item>
  152. <Form.Item label={<strong>是否复制创意</strong>} name={"isCopyAdcreative"} valuePropName="checked" tooltip="选择“是”,新建创意,复制条数不限制;选择”否“沿用旧创意,复制条数限制26条。">
  153. <Switch checkedChildren="是" unCheckedChildren="否" />
  154. </Form.Item>
  155. <Form.Item label={<strong>复制数量</strong>} name='copyCount' rules={[{ required: true, message: '请输入复制数量' }]}>
  156. <InputNumber min={1} />
  157. </Form.Item>
  158. </Form>
  159. </Modal>
  160. }
  161. export default React.memo(Copy)