autoAcquisitionSet.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { InputNumber, message, Modal, Radio, Space, Switch, Table, Tooltip } from "antd"
  2. import React, { useEffect, useState } from "react"
  3. import '../../tencentAdPutIn/index.less'
  4. import style from './index.less'
  5. import { InfoCircleFilled, QuestionCircleOutlined } from "@ant-design/icons"
  6. import { updateBatchAdgroupInfoApi } from "@/services/launchAdq/adqv3"
  7. import { useAjax } from "@/Hook/useAjax"
  8. interface Props {
  9. selectAdList: any[]
  10. visible?: boolean
  11. onClose?: () => void
  12. onChange?: () => void
  13. }
  14. /**
  15. * 批量一键起量
  16. * @param param0
  17. * @returns
  18. */
  19. const AutoAcquisitionSet: React.FC<Props> = ({ selectAdList, visible, onChange, onClose }) => {
  20. /****************************************/
  21. const [autoAcquisitionData, setAutoAcquisitionData] = useState<{ autoAcquisitionEnabled: boolean, autoAcquisitionBudget?: number, autoAcquisitionBudgetPercent?: number }>({ autoAcquisitionEnabled: false })
  22. const [isPercent, setIsPercent] = useState<boolean>(false)
  23. const [addType, setAddType] = useState<'fixed' | 'percent'>('fixed')
  24. const updateBatchAdgroupInfo = useAjax((params) => updateBatchAdgroupInfoApi(params)) // 名称
  25. const [failIdList, setFailIdList] = useState<{ adgroupId: number, code: number, message: string, messageCn: string }[]>([])
  26. const [failVisible, setFailVisible] = useState<boolean>(false)
  27. /****************************************/
  28. useEffect(() => {
  29. if (selectAdList.every(item => item.autoAcquisitionEnabled)) {
  30. setIsPercent(true)
  31. } else {
  32. setIsPercent(false)
  33. }
  34. }, [selectAdList])
  35. const handleOk = () => {
  36. let params = { ...autoAcquisitionData }
  37. if (params?.autoAcquisitionEnabled) {
  38. if (addType === 'fixed' && !params?.autoAcquisitionBudget) {
  39. message.error('请填写起量预算')
  40. return
  41. }
  42. if (addType === 'percent' && !params?.autoAcquisitionBudgetPercent) {
  43. message.error('请填写起量预算百分比')
  44. return
  45. }
  46. }
  47. if (params?.autoAcquisitionBudgetPercent !== null && params?.autoAcquisitionBudgetPercent !== undefined) params.autoAcquisitionBudgetPercent = params?.autoAcquisitionBudgetPercent / 100
  48. let accountAdgroupMaps = [...new Set(selectAdList?.map(item => item.accountId + ',' + item.adgroupId))]
  49. updateBatchAdgroupInfo.run({ accountAdgroupMaps, ...params }).then(res => {
  50. if (res?.failIdList?.length === 0) {
  51. message.success(`修改操作完成!`)
  52. onChange?.()
  53. } else {
  54. setFailIdList(res?.list || [])
  55. setFailVisible(true)
  56. }
  57. })
  58. console.log(params)
  59. }
  60. return <Modal
  61. title={<strong>批量修改一键起量</strong>}
  62. open={visible}
  63. onCancel={onClose}
  64. onOk={handleOk}
  65. className='modalResetCss'
  66. width={750}
  67. confirmLoading={updateBatchAdgroupInfo.loading}
  68. >
  69. <div className={style.autoAcquisitionSet}>
  70. <div className={style.left}>
  71. <Table
  72. dataSource={selectAdList}
  73. size="small"
  74. scroll={{ x: 400, y: 450 }}
  75. bordered
  76. rowKey={'adgroupId'}
  77. pagination={false}
  78. columns={[
  79. {
  80. title: '广告名称',
  81. dataIndex: 'adgroupName',
  82. key: 'adgroupName',
  83. width: 200,
  84. render(value) {
  85. return <span style={{ wordBreak: 'break-all' }}>{value}</span>
  86. },
  87. },
  88. {
  89. title: '原设置',
  90. dataIndex: 'beforeSet',
  91. key: 'beforeSet',
  92. width: 120,
  93. render(value, record) {
  94. if (!record?.autoAcquisitionEnabled) {
  95. return '未开启'
  96. }
  97. return `一键起量中,起量预算:${record?.autoAcquisitionBudget} 元`
  98. },
  99. }
  100. ]}
  101. />
  102. </div>
  103. <div className={style.right}>
  104. <div className={style.header}>
  105. <Space>
  106. <span>修改一键起量</span>
  107. <Tooltip title={<div>
  108. <p>1. 一键起量期间产生的消耗不赔付,但转化计入赔付门槛判断;</p>
  109. <p>2. 一键起量可能导致转化成本高于预期,且起量结束后不一定能持续消耗。</p>
  110. </div>}>
  111. <QuestionCircleOutlined />
  112. </Tooltip>
  113. </Space>
  114. </div>
  115. <div className={style.edit}>
  116. <div>
  117. <div className={style.tips}>
  118. <InfoCircleFilled style={{ color: '#296BEF', marginTop: 2 }} />
  119. {
  120. autoAcquisitionData?.autoAcquisitionEnabled ?
  121. // '对于状态为“一键起量中”、“一键起量完成”、“一键起量中止”的广告,将会自动关闭一键起量,同时按照新的起量预算重新开启一键起量'
  122. '开启一键起量'
  123. :
  124. '当前开关为关闭状态,点击「确定」将默认关闭已选广告的一键起量功能'
  125. }
  126. </div>
  127. <div>
  128. <Switch
  129. checkedChildren="开启"
  130. unCheckedChildren="未开启"
  131. onChange={(e) => {
  132. setAutoAcquisitionData({ ...autoAcquisitionData, autoAcquisitionEnabled: e })
  133. }}
  134. checked={autoAcquisitionData?.autoAcquisitionEnabled}
  135. />
  136. </div>
  137. {autoAcquisitionData?.autoAcquisitionEnabled && <>
  138. <Radio.Group buttonStyle="solid" value={addType} onChange={(e) => setAddType(e.target.value)}>
  139. <Radio.Button value="fixed">固定值</Radio.Button>
  140. <Radio.Button value="percent" disabled={!isPercent}>百分比上下浮动修改</Radio.Button>
  141. </Radio.Group>
  142. {addType === 'fixed' ?
  143. <InputNumber placeholder="起量预算,建议设置为出价的10倍" min={200} max={100000} style={{ width: '100%' }} value={autoAcquisitionData?.autoAcquisitionBudget} onChange={(e) => setAutoAcquisitionData({ autoAcquisitionEnabled: true, autoAcquisitionBudget: e || 0 })} />
  144. :
  145. <InputNumber placeholder="起量预算,原有基础上下调百分比" style={{ width: '100%' }} addonAfter="%" value={autoAcquisitionData?.autoAcquisitionBudgetPercent} onChange={(e) => setAutoAcquisitionData({ autoAcquisitionEnabled: true, autoAcquisitionBudgetPercent: e || 0 })} />
  146. }
  147. </>}
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. {failVisible && <Modal
  153. title={<strong>报错信息</strong>}
  154. open={failVisible}
  155. className='modalResetCss'
  156. width={650}
  157. onCancel={() => { setFailVisible(false); setFailIdList([]) }}
  158. footer={null}
  159. >
  160. <Table
  161. size="small"
  162. bordered
  163. rowKey={'adgroupId'}
  164. columns={[{
  165. title: '广告ID',
  166. dataIndex: 'adgroupId',
  167. key: 'adgroupId',
  168. width: 110,
  169. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  170. }, {
  171. title: 'code',
  172. dataIndex: 'code',
  173. key: 'code',
  174. width: 70,
  175. align: 'center',
  176. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  177. }, {
  178. title: '错误信息',
  179. dataIndex: 'messageCn',
  180. key: 'messageCn',
  181. render: (value) => <span style={{ fontSize: 12 }}>{value}</span>,
  182. }]}
  183. dataSource={failIdList}
  184. />
  185. </Modal>}
  186. </Modal>
  187. }
  188. export default React.memo(AutoAcquisitionSet)