猎羽广告

adBasic.ts 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import { reactive } from 'vue'
  2. import { getAdPresets } from '../basicInfo/ts/basicApi'
  3. import { FillBackData } from '../basicInfo/ts/fillBack'
  4. import _ from 'lodash'
  5. export interface IOuterConfigRule {
  6. type: string,
  7. val: any,
  8. other: any,
  9. }
  10. export function basicInfoDeclare() {
  11. //广告基本信息
  12. const basicInfoData = reactive<any>({
  13. visible: false,
  14. copywriting: [],
  15. fillBack: {},
  16. outerConfig: { //外层配置
  17. attributionOuter: {
  18. enabled: false,
  19. visible: false,
  20. optional: false,
  21. isComplete: false, // 是否完成填写
  22. name: '精准匹配归因',
  23. value: {},
  24. other: {}
  25. },
  26. unionPosition: {
  27. enabled: false,
  28. visible: false,
  29. optional: false,
  30. isComplete: false, // 是否完成填写
  31. infoSelect: [],//流量包type
  32. name: '优量汇流量包',
  33. value: {},
  34. other: {}
  35. },
  36. weChatVideoAccount: {
  37. enabled: false,
  38. visible: false,
  39. optional: false,
  40. isComplete: false, // 是否完成填写
  41. name: '配置视频号',
  42. value: {},
  43. other: {}
  44. },
  45. expandPopulation: { //已下线
  46. enabled: false, //是否需要配置
  47. visible: false, //对应弹框显隐
  48. optional: true, //选填
  49. isComplete: false, // 是否完成填写
  50. name: '扩量种子人群(选填)',
  51. value: {},
  52. other: {}
  53. },
  54. targetingPartyData: {
  55. enabled: false, //是否需要配置
  56. visible: false,
  57. optional: true,
  58. isComplete: false, // 是否完成填写
  59. name: '一方数据助攻(选填)',
  60. value: {},
  61. other: {}
  62. },
  63. }
  64. })
  65. return {
  66. basicInfoData
  67. }
  68. }
  69. interface IHandleAdBasic {
  70. updateHaveContent: (...args: any[]) => void,
  71. judgeEvent: (...args: any[]) => boolean,
  72. clearOriginalityInfo: (...args: any[]) => void,
  73. [propName: string]: any
  74. }
  75. //广告基本信息 - 广告外层配置
  76. export function handleAdBasic({
  77. clearOriginalityInfo,
  78. updateHaveContent,
  79. judgeEvent,
  80. basicInfoData,
  81. CreativeMaterialRef,
  82. CopywriterRef,
  83. LandPageRef,
  84. targetRef,
  85. pageInfo,CreativeMaterial_clear
  86. }: IHandleAdBasic) {
  87. /**广告基础信息回调 */
  88. const basicInfoClose = (obj) => {
  89. console.log('obj',obj);
  90. if (obj?.type == 'update') {
  91. //判断版位是否变化,版位变化则创意基本信息、创意文案、落地页 、素材 清空
  92. if (obj.params.automatic_site != basicInfoData.fillBack?.automatic_site || obj.params.site_ids != basicInfoData.fillBack?.site_ids) {
  93. clearOriginalityInfo()
  94. updateHaveContent(5, 0, false, true)
  95. CreativeMaterial_clear()
  96. if (CopywriterRef.value) {
  97. CopywriterRef.value[0]?.clearEvent()
  98. }
  99. updateHaveContent(7, 0, false, true)
  100. if (LandPageRef.value) {
  101. LandPageRef.value[0]?.clearEvent()
  102. }
  103. updateHaveContent(8, 0, false, true)
  104. }
  105. basicInfoData.copywriting = obj.copywriting
  106. basicInfoData.fillBack = obj.params
  107. updateHaveContent(2, -1, false)
  108. getButtonBasicOuter(obj.params)
  109. }
  110. basicInfoData.visible = false
  111. }
  112. /**广告预存信息获取 */
  113. const getAdPresetsInfo = (type?, info?) => {
  114. if(type == 'strategyGroups'){
  115. getAdBasicInfo(info)
  116. }else{
  117. getAdPresets({ 'promoted_object_type': targetRef.value?.value }).then((res) => {
  118. getAdBasicInfo(res)
  119. })
  120. }
  121. }
  122. const getAdBasicInfo = (res) => {
  123. getButtonBasicOuter(res)
  124. FillBackData({
  125. data: res,
  126. type: 'api',
  127. cb: (data: { params: any, copywriting: [] }) => {
  128. if (data.copywriting && Array.isArray(data.copywriting) && data.copywriting.length > 0) {
  129. basicInfoData.copywriting = data.copywriting
  130. for(let key in data.params) {
  131. if(data.params[key] === null) {
  132. data.params[key] = ''
  133. }
  134. }
  135. basicInfoData.fillBack = data.params
  136. updateHaveContent(2, -1, false)
  137. }
  138. }
  139. })
  140. }
  141. /**广告信息外部配置获取 */
  142. const getButtonBasicOuter = (res) => {
  143. for (let i in basicInfoData.outerConfig) {
  144. basicInfoData.outerConfig[i].enabled = false
  145. }
  146. // if (res?.expand_enabled == 1) { // 扩量种子人群
  147. // basicInfoData.outerConfig.expandPopulation.enabled = true;
  148. // }
  149. if (res?.smart_targeting_switch == 1) { // 智能定向外层配置
  150. basicInfoData.outerConfig.targetingPartyData.enabled = true;
  151. }
  152. if (res?.attribution_type == 2) { // 精准匹配归因
  153. basicInfoData.outerConfig.attributionOuter.enabled = true;
  154. }
  155. if(res?.site_ids?.indexOf('SITE_SET_CHANNELS') != -1){ //微信视频号
  156. basicInfoData.outerConfig.weChatVideoAccount.enabled = true;
  157. }
  158. if (res?.union_position_enabled == 1 || res?.exclude_union_position_enabled == 1) { //优量汇流量包 -- 需要定向包完成填写
  159. basicInfoData.outerConfig.unionPosition.enabled = true;
  160. basicInfoData.outerConfig.unionPosition.infoSelect = []
  161. res?.union_position_enabled == 1 && basicInfoData.outerConfig.unionPosition.infoSelect.push({ name: '定投流量包', id: 1 })
  162. res?.exclude_union_position_enabled == 1 && basicInfoData.outerConfig.unionPosition.infoSelect.push({ name: '屏蔽流量包', id: 2 })
  163. }
  164. }
  165. /**点击基础信息外层配置 */
  166. const basicOuterClick = (key) => {
  167. if (key == 'unionPosition') { //优量汇流量包 - 需要定向包完成填写
  168. if (!judgeEvent(-2)) return
  169. }
  170. if (key == 'weChatVideoAccount'){ // 微信视频号 - 完成创意文案之前的配置
  171. if (!judgeEvent(7)) return
  172. }
  173. basicInfoData.outerConfig[key].visible = true;
  174. }
  175. /** 外部配置回调 */
  176. interface IBasicOuterClose {
  177. 'type': string,
  178. 'key': string,
  179. 'val'?: string,
  180. 'other'?: string
  181. }
  182. const basicOuterClose = ({ key, val, type, other }: IBasicOuterClose) => {
  183. basicInfoData.outerConfig[key].visible = false;
  184. if (type == 'submit') {
  185. basicInfoData.outerConfig[key].value = val ? val : {};
  186. basicInfoData.outerConfig[key].isComplete = isCompleteEvent(basicInfoData.outerConfig[key]);
  187. if(other){
  188. basicInfoData.outerConfig[key].other = other
  189. }
  190. }
  191. }
  192. const isCompleteEvent = (data) => {
  193. for (let i = 0; i < pageInfo.accIdsList.length; i++) {
  194. let info = data.value[pageInfo.accIdsList[i].id]
  195. if (Array.isArray(info) && info.length == 0) {
  196. return false
  197. } else if (Object.prototype.toString.call(info) == '[object Object]' && Object.keys(info).length == 0) {
  198. return false
  199. } else if (!info || info == '') {
  200. return false
  201. }
  202. }
  203. return true
  204. }
  205. /**基础外部配置 - 获取对象公共数据 */
  206. const getCommonValue = (data) => {
  207. let obj = {}
  208. pageInfo.accIdsList.forEach((item) => {
  209. if (data[item.id] && data[item.id] != '') {
  210. obj[item.id] = data[item.id]
  211. }
  212. });
  213. return obj
  214. }
  215. return {
  216. basicInfoClose,
  217. getAdPresetsInfo,
  218. basicOuterClick,
  219. basicOuterClose,
  220. getCommonValue,
  221. isCompleteEvent
  222. }
  223. }