updateAd.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import { Checkbox, DatePicker, Form, Input, message, Modal, notification, Radio, Space, TimePicker, Tooltip } from "antd"
  2. import React, { useEffect, useState } from "react"
  3. import TimeInSelect from "../../components/timeInSelect"
  4. import moment from "moment"
  5. import { getTimeSeriesList } from "./const";
  6. import { editAdqAdgroupsDataApi } from "@/services/launchAdq/adq";
  7. import { useAjax } from "@/Hook/useAjax";
  8. import { BidStrategyEnum } from "@/services/launchAdq/enum";
  9. import { QuestionCircleOutlined } from "@ant-design/icons";
  10. import { RangePickerProps } from "antd/lib/date-picker";
  11. const { RangePicker } = DatePicker;
  12. let DatePickers: any = DatePicker
  13. interface Props {
  14. title: string,
  15. visible?: boolean,
  16. onChange?: () => void,
  17. onClose?: () => void,
  18. selectedRows: any[]
  19. }
  20. /**
  21. * 修改广告
  22. * @returns
  23. */
  24. const UpdateAd: React.FC<Props> = ({ title = '修改广告', visible, onChange, onClose, selectedRows }) => {
  25. /***************************/
  26. const [form] = Form.useForm();
  27. let dateType = Form.useWatch('dateType', form)
  28. let field = Form.useWatch('field', form)
  29. const [state, setState] = useState<any>({ isShowTime: [] })
  30. const [isBidSType, setIsBidSType] = useState<boolean>(true)
  31. const [timeSeriesType, setTimeSeriesType] = useState<'allDayLong' | 'timeInterValS'>('allDayLong')
  32. const editAdqAdgroupsData = useAjax((params) => editAdqAdgroupsDataApi(params))
  33. /***************************/
  34. useEffect(() => {
  35. setIsBidSType(selectedRows.every((item: { smartBidType: string }) => item.smartBidType === 'SMART_BID_TYPE_CUSTOM'))
  36. }, [selectedRows])
  37. const handleOk = () => {
  38. form.validateFields().then(values => {
  39. // console.log(values);
  40. let newValues = JSON.parse(JSON.stringify(values))
  41. let field = newValues.field
  42. let adgroupsUpdateDatetimeDTO = {} // 排期
  43. let adgroupsUpdateBidAmountDTO = {} // 出价
  44. if (timeSeriesType === 'allDayLong') {
  45. newValues.timeSeries = getTimeSeriesList()
  46. }
  47. field.forEach((key: string) => {
  48. switch (key) {
  49. case 'dateType':
  50. if (newValues.dateType === '2') {
  51. adgroupsUpdateDatetimeDTO['beginDate'] = moment(newValues.date).format('YYYY-MM-DD')
  52. adgroupsUpdateDatetimeDTO['endDate'] = ''
  53. } else {
  54. adgroupsUpdateDatetimeDTO['beginDate'] = moment(newValues.date[0]).format('YYYY-MM-DD')
  55. adgroupsUpdateDatetimeDTO['endDate'] = moment(newValues.date[1]).format('YYYY-MM-DD')
  56. }
  57. break
  58. case 'timeType':
  59. // if (timeSeriesType === 'timeInterValS') {
  60. // if (newValues.firstDayBeginTime && moment(newValues.firstDayBeginTime).format('HH:mm:ss') !== '00:00:00') {
  61. // message.error('1111')
  62. // return
  63. // }
  64. // }
  65. if (newValues.timeSeries) {
  66. adgroupsUpdateDatetimeDTO['timeSeries'] = newValues.timeSeries.join('')
  67. }
  68. if (newValues.firstDayBeginTime) {
  69. adgroupsUpdateDatetimeDTO['firstDayBeginTime'] = moment(newValues.firstDayBeginTime).format('HH:mm:ss')
  70. }
  71. break
  72. case 'bidSType':
  73. adgroupsUpdateBidAmountDTO['bidStrategy'] = newValues.bidStrategy
  74. adgroupsUpdateBidAmountDTO['bidAmount'] = newValues.bidAmount * 100
  75. break
  76. }
  77. })
  78. // console.log('params--->', adgroupsUpdateDatetimeDTO);
  79. editAdqAdgroupsData.run({ adgroupIds: selectedRows.map((item: { adgroupId: number }) => item.adgroupId), adgroupsUpdateDatetimeDTO, adgroupsUpdateBidAmountDTO }).then(res => {
  80. if (res) {
  81. message.success(`修改完成.成功: ${res.success},失败: ${res.fail}`)
  82. if (res?.fail) {
  83. notification.error({
  84. message: `修改失败`,
  85. description: `成功: ${res.success},修改失败${res.fail}条,失败的请到任务列表查看`,
  86. duration: 0
  87. });
  88. }
  89. onChange?.()
  90. }
  91. })
  92. })
  93. }
  94. /** 禁止选择以前时间 */
  95. const disabledDate: RangePickerProps['disabledDate'] = current => {
  96. // Can not select days before today and today
  97. return current && current < moment().startOf('day');
  98. };
  99. return <Modal
  100. title={title}
  101. visible={visible}
  102. onOk={handleOk}
  103. width={800}
  104. onCancel={() => onClose && onClose()}
  105. confirmLoading={editAdqAdgroupsData.loading}
  106. >
  107. <Form
  108. form={form}
  109. labelCol={{ span: 4 }}
  110. className='ad_form_style'
  111. colon={false}
  112. initialValues={{
  113. dateType: '2',
  114. date: moment().startOf('day'),
  115. timeSeries: getTimeSeriesList(),
  116. firstDayBeginTime: moment('2023-02-24 00:00:00'),
  117. bidStrategy: 'BID_STRATEGY_TARGET_COST',
  118. bidAmount: 1000
  119. }}
  120. >
  121. {title === '批量修改' ? <>
  122. <Form.Item label={<strong>选择修改字段</strong>} name='field' rules={[{ required: true, message: '选择修改字段' }]}>
  123. <Checkbox.Group>
  124. <Checkbox value="dateType">投放日期</Checkbox>
  125. <Checkbox value="timeType">投放时段</Checkbox>
  126. <Checkbox value="bidSType" disabled={!isBidSType}>
  127. <Space size={5}>
  128. 出价
  129. {!isBidSType && <Tooltip title="选择的广告包含自动出价类型,不支持修改出价">
  130. <QuestionCircleOutlined />
  131. </Tooltip>}
  132. </Space>
  133. </Checkbox>
  134. </Checkbox.Group>
  135. </Form.Item>
  136. {field?.includes('dateType') && <>
  137. <Form.Item label={<strong>投放日期</strong>} name='dateType'>
  138. <Radio.Group onChange={(e) => {
  139. if (e.target.value === "1") {
  140. form.setFieldsValue({ date: [moment().startOf('day'), moment().startOf('day').add(1, 'M')] })
  141. }
  142. if (e.target.value === "2") {
  143. form.setFieldsValue({ date: moment().startOf('day') })
  144. }
  145. }}>
  146. <Radio.Button value="1">选择开始与结束日期</Radio.Button>
  147. <Radio.Button value="2">长期投放</Radio.Button>
  148. </Radio.Group>
  149. </Form.Item>
  150. {/* 投放日期的不同展示不同的日期选择 */}
  151. {dateType === '1' ? <Form.Item name='date' rules={[{ required: true, message: '请选择日期' }]}>
  152. <RangePicker style={{ marginLeft: 125 }} disabledDate={disabledDate}></RangePicker>
  153. </Form.Item> : <Form.Item name='date' style={{ marginLeft: 125 }} rules={[{ required: true, message: '请选择日期' }]}>
  154. <DatePickers disabledDate={disabledDate}/>
  155. </Form.Item>}
  156. </>}
  157. {field?.includes('timeType') && <>
  158. <Form.Item label={<strong>投放时段</strong>} style={{ marginBottom: 0 }}>
  159. <Space direction='vertical' style={{ width: '100%' }}>
  160. <Radio.Group
  161. name='timeSeriesType'
  162. value={timeSeriesType}
  163. onChange={(value) => {
  164. setTimeSeriesType(value.target.value)
  165. if (value.target.value === 'timeInterValS') {
  166. setState({ isShowTime: ['1'] })
  167. }
  168. }}>
  169. <Radio.Button value={'allDayLong'}>全天投放</Radio.Button>
  170. <Radio.Button value={'timeInterValS'}>指定多个时段</Radio.Button>
  171. </Radio.Group>
  172. {timeSeriesType === 'timeInterValS' && <Form.Item name='timeSeries' noStyle rules={[{ required: true, message: '请选择时段' }]}>
  173. <TimeInSelect />
  174. </Form.Item>}
  175. </Space>
  176. </Form.Item>
  177. <Form.Item label={<strong></strong>}>
  178. <Space>
  179. <Checkbox.Group options={[{ label: '指定首日开始投放时间', value: '1' }]} disabled={timeSeriesType === 'timeInterValS'} value={state.isShowTime} onChange={(checkedValue) => { setState({ ...state, isShowTime: checkedValue }) }} />
  180. {state?.isShowTime?.length > 0 && <Form.Item name='firstDayBeginTime' noStyle rules={[{ required: true, message: '请选择时间' }]}>
  181. <TimePicker />
  182. </Form.Item>}
  183. </Space>
  184. </Form.Item>
  185. </>}
  186. {field?.includes('bidSType') && <>
  187. <Form.Item label={<strong>出价策略</strong>} name='bidStrategy' rules={[{ required: true, message: '请选择出价策略' }]}>
  188. <Radio.Group>
  189. {Object.keys(BidStrategyEnum).map(key => {
  190. return <Radio.Button value={key} key={key} disabled={key === 'BID_STRATEGY_PRIORITY_CAP_COST'}>{BidStrategyEnum[key]}</Radio.Button>
  191. })}
  192. </Radio.Group>
  193. </Form.Item>
  194. <Form.Item label={<strong>出价</strong>} name='bidAmount' rules={[{ required: true, message: '请输入价格' }]}>
  195. <Input placeholder={`输入价格 元`} style={{ width: 300 }} />
  196. </Form.Item>
  197. </>}
  198. </> : <>
  199. </>}
  200. </Form>
  201. </Modal>
  202. }
  203. export default React.memo(UpdateAd)