group-select.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div class="group-select">
  3. <a-form
  4. ref="formCheck"
  5. :label-col="{ span: 2 }"
  6. :wrapper-col="{ span: 8 }"
  7. :rules="rules"
  8. :model="form"
  9. >
  10. <a-form-item label="创建方式">
  11. <a-radio-group v-model:value="form.build_mode">
  12. <a-radio value="1">新建广告组</a-radio>
  13. <a-radio value="2">已有广告组</a-radio>
  14. </a-radio-group>
  15. </a-form-item>
  16. <div v-if="form.build_mode === '1'">
  17. <a-form-item label="营销链路" name="marketing_purpose">
  18. <a-radio-group
  19. v-model:value="form.marketing_purpose"
  20. @change="makeGroupName"
  21. >
  22. <a-radio-button value="CONVERSION">行动转化</a-radio-button>
  23. <a-radio-button value="INTENTION">用户意向</a-radio-button>
  24. <a-radio-button value="ACKNOWLEDGE">品牌认知</a-radio-button>
  25. </a-radio-group>
  26. </a-form-item>
  27. <a-form-item name="landing_type" style="margin-left: 100px">
  28. <a-radio-group
  29. v-model:value="form.landing_type"
  30. @change="makeGroupName"
  31. >
  32. <a-radio-button value="LINK">销售线索收集</a-radio-button>
  33. <a-radio-button value="APP">应用推广</a-radio-button>
  34. </a-radio-group></a-form-item
  35. >
  36. <a-form-item label="广告类型" name="campaign_type">
  37. <a-select v-model:value="form.campaign_type" placeholder="请选择">
  38. <a-select-option value="FEED">所有广告</a-select-option>
  39. <a-select-option value="SEARCH">搜索广告</a-select-option>
  40. </a-select>
  41. </a-form-item>
  42. <a-form-item label="广告组预算">
  43. <a-radio-group v-model:value="form.budget_mode">
  44. <a-radio value="BUDGET_MODE_INFINITE">不限</a-radio>
  45. <a-radio value="BUDGET_MODE_DAY">指定预算</a-radio>
  46. </a-radio-group>
  47. </a-form-item>
  48. <a-form-item
  49. label="日预算"
  50. name="budget"
  51. v-if="form.budget_mode === 'BUDGET_MODE_DAY'"
  52. >
  53. <a-input addon-after="元" type="number" v-model:value="form.budget" />
  54. </a-form-item>
  55. <a-form-item label="广告组名称" name="campaign_name">
  56. <a-input v-model:value="form.campaign_name" :maxlength="50" />
  57. </a-form-item>
  58. </div>
  59. <div v-else class="ad-group-box">
  60. <div class="title-box"><h3>选择广告组</h3></div>
  61. <div class="main-box">
  62. <div class="search-box">
  63. <a-input-search
  64. v-model:value="groupNameSearch"
  65. placeholder="请输入广告组名称"
  66. style="width: 200px"
  67. @search="onSearch"
  68. />
  69. </div>
  70. <div class="table-title"><h3>广告组名称</h3></div>
  71. <div class="list-box">
  72. <a-radio-group v-model:value="form.campaign_id">
  73. <a-radio :style="radioStyle" :value="1"
  74. >广告组1 <span class="desc">测试广告组</span></a-radio
  75. >
  76. <a-radio :style="radioStyle" :value="2"
  77. >广告组2 <span class="desc">测试广告组</span></a-radio
  78. >
  79. </a-radio-group>
  80. </div>
  81. </div>
  82. </div>
  83. </a-form>
  84. </div>
  85. </template>
  86. <script lang="ts">
  87. import { defineComponent, reactive, toRefs, ref, createVNode } from "vue";
  88. import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
  89. import { getAdCampaigns, createAdCampaign } from "@/api";
  90. import { message, Modal } from "ant-design-vue";
  91. import Bus from "@/utils/bus";
  92. const GroupSelect = defineComponent({
  93. setup() {
  94. const formCheck = ref();
  95. const state = reactive({
  96. form: {
  97. build_mode: "1", // 创建方式
  98. landing_type: "", // 广告链路 广告组推广目的
  99. marketing_purpose: "", // 营销目的
  100. campaign_type: undefined, // 广告类型
  101. budget_mode: "BUDGET_MODE_INFINITE", // 广告组预算
  102. budget: "", // 日预算
  103. campaign_name: "", // 广告组名称
  104. campaign_id: 0, // 选择的已有广告组
  105. },
  106. groupNameSearch: "", // 搜索广告组名称
  107. groupList: ref<any[]>([]),
  108. groupListOrigin: ref<any[]>([]),
  109. });
  110. const radioStyle = reactive({
  111. display: "block",
  112. height: "40px",
  113. lineHeight: "40px",
  114. width: "580px",
  115. padding: "0 10px",
  116. borderBottom: "1px solid rgb(230, 230, 230)",
  117. });
  118. const rules = {
  119. build_mode: [
  120. {
  121. required: false,
  122. message: "请选择",
  123. trigger: "change",
  124. },
  125. ],
  126. landing_type: [
  127. {
  128. required: true,
  129. message: "请选择",
  130. trigger: "change",
  131. },
  132. ],
  133. marketing_purpose: [
  134. {
  135. required: true,
  136. message: "请选择",
  137. trigger: "change",
  138. },
  139. ],
  140. campaign_type: [
  141. {
  142. required: true,
  143. message: "请选择广告类型",
  144. trigger: "change",
  145. },
  146. ],
  147. campaign_name: [
  148. {
  149. required: true,
  150. message: "请输入广告组名称",
  151. trigger: "blur",
  152. },
  153. ],
  154. budget: [
  155. {
  156. required: true,
  157. message: "请输入广告组预算",
  158. trigger: "blur",
  159. },
  160. ],
  161. };
  162. // const check = () => {
  163. // // formCheck.value
  164. // // .validate()
  165. // // .then(() => {
  166. // // console.log("values");
  167. // // })
  168. // // .catch((error: any) => {
  169. // // console.log("error", error);
  170. // // });
  171. // console.log("Form", state.form);
  172. // if (state.form.build_mode === "1") {
  173. // // 请求创建广告主接口
  174. // let param: any = { ...state.form,advertiser_id: };
  175. // delete param.build_mode;
  176. // if (param.budget_mode === "BUDGET_MODE_INFINITE") delete param.budget;
  177. // }
  178. // // 返回处理
  179. // let data = { flag: false, campaign_id: 0 };
  180. // return data;
  181. // };
  182. return { ...toRefs(state), radioStyle, rules, formCheck };
  183. },
  184. beforeRouteLeave(to: any, from, next) {
  185. console.log("离开", to);
  186. if (
  187. to.href.indexOf("plan-create/account-select") > -1 ||
  188. to.href.indexOf("plan-create/plan-edit") > -1
  189. ) {
  190. window.localStorage.setItem(
  191. "plan-create-campaign",
  192. JSON.stringify(this.form)
  193. );
  194. return next();
  195. }
  196. Modal.confirm({
  197. title: "确认离开当前页面吗?",
  198. icon: createVNode(ExclamationCircleOutlined),
  199. content: createVNode(
  200. "div",
  201. { style: "color:gray;" },
  202. "未保存内容将会丢失"
  203. ),
  204. onOk() {
  205. next();
  206. },
  207. onCancel() {
  208. next(false);
  209. },
  210. class: "test",
  211. });
  212. },
  213. mounted() {
  214. if (window.localStorage.getItem("plan-create-campaign"))
  215. this.form = JSON.parse(
  216. String(window.localStorage.getItem("plan-create-campaign"))
  217. );
  218. console.log("REF", this.formCheck);
  219. // this.getGroups();
  220. Bus.$on("stepTwoCheck", () => {
  221. let data = this.check();
  222. console.log(data);
  223. if (data.flag) {
  224. window.localStorage.setItem(
  225. "plan-create-campaign",
  226. JSON.stringify(this.form)
  227. );
  228. Bus.$emit("stepTwoBack", data.campaign_id);
  229. }
  230. });
  231. },
  232. methods: {
  233. // 搜索广告组名称
  234. onSearch() {
  235. console.log("搜索广告组", this.groupNameSearch);
  236. },
  237. // step2创建广告组页面校验
  238. check() {
  239. let campaign_id = 0;
  240. console.log("Form", this.form);
  241. if (this.form.build_mode === "1") {
  242. // 校验表单
  243. let formV: any = this.$refs.formCheck;
  244. console.log("你们", this.$refs.formCheck);
  245. formV
  246. .validate()
  247. .then(() => {
  248. // 请求创建广告主接口
  249. let param: any = {
  250. ...this.form,
  251. advertiser_id: this.$route.query.account_id,
  252. };
  253. delete param.build_mode;
  254. delete param.campaign_id;
  255. if (param.budget_mode === "BUDGET_MODE_INFINITE")
  256. delete param.budget;
  257. console.log(param);
  258. // 接口
  259. createAdCampaign(param)
  260. .then(({ data }) => {
  261. console.log("创建广告组返回", data);
  262. campaign_id = data.campaign_id;
  263. message.success("广告组创建成功");
  264. })
  265. .catch((error: any) => {
  266. console.log("error", error);
  267. });
  268. })
  269. .catch((error: any) => {
  270. console.log("error", error);
  271. });
  272. } else {
  273. console.log("逸轩广告组", this.form.campaign_id);
  274. if (!this.form.campaign_id) {
  275. message.warning("请选择广告组");
  276. } else {
  277. campaign_id = this.form.campaign_id;
  278. }
  279. }
  280. // 返回处理
  281. let data = { flag: campaign_id ? true : false, campaign_id: campaign_id };
  282. return data;
  283. },
  284. async getGroups() {
  285. let { data } = await getAdCampaigns({
  286. advertiser_id: String(this.$route.query.account_id),
  287. page: 999,
  288. });
  289. },
  290. // 生成广告组名称
  291. makeGroupName() {
  292. if (!this.form.landing_type || !this.form.marketing_purpose) return;
  293. let langdingTypeName = "",
  294. marketingPurposeName = "";
  295. let nameArr: any = [
  296. { name: "销售线索收集", value: "LINK" },
  297. { name: "应用推广", value: "APP" },
  298. { name: "行动转化", value: "CONVERSION" },
  299. { name: "用户意向", value: "INTENTION" },
  300. { name: "品牌认知", value: "ACKNOWLEDGE" },
  301. ];
  302. nameArr.forEach((item: any) => {
  303. if (this.form.landing_type === item.value) langdingTypeName = item.name;
  304. if (this.form.marketing_purpose === item.value)
  305. marketingPurposeName = item.name;
  306. });
  307. let time = this.getNowFormatDate();
  308. this.form.campaign_name = `${marketingPurposeName}_${langdingTypeName}_${time}`;
  309. console.log(this.form.campaign_name);
  310. },
  311. // 获取当前时间
  312. getNowFormatDate() {
  313. var date = new Date();
  314. var seperator1 = "-";
  315. var seperator2 = ":";
  316. var month: any = date.getMonth() + 1;
  317. var strDate: any = date.getDate();
  318. var strHours: any = date.getHours();
  319. var strMinutes: any = date.getMinutes();
  320. var strSeconds: any = date.getSeconds();
  321. if (month >= 1 && month <= 9) {
  322. month = "0" + month;
  323. }
  324. if (strDate >= 0 && strDate <= 9) {
  325. strDate = "0" + strDate;
  326. }
  327. if (strHours >= 0 && strHours <= 9) {
  328. strHours = "0" + strHours;
  329. }
  330. if (strMinutes >= 0 && strMinutes <= 9) {
  331. strMinutes = "0" + strMinutes;
  332. }
  333. if (strSeconds >= 0 && strSeconds <= 9) {
  334. strSeconds = "0" + strSeconds;
  335. }
  336. var currentdate =
  337. date.getFullYear() +
  338. seperator1 +
  339. month +
  340. seperator1 +
  341. strDate +
  342. " " +
  343. strHours +
  344. seperator2 +
  345. strMinutes +
  346. seperator2 +
  347. strSeconds;
  348. currentdate = currentdate.replace(/-/g, "_").replace(/ /g, "_");
  349. currentdate = currentdate.slice(5, 19);
  350. return currentdate;
  351. },
  352. },
  353. });
  354. export default GroupSelect;
  355. </script>
  356. <style lang="scss" scoped>
  357. @import "@/assets/common-style/scroll-bar.scss";
  358. .group-select {
  359. .ad-group-box {
  360. width: 600px;
  361. height: 350px;
  362. border: 1px solid rgb(230, 230, 230);
  363. margin-left: 100px;
  364. .title-box {
  365. height: 40px;
  366. line-height: 40px;
  367. border-bottom: 1px solid rgb(230, 230, 230);
  368. padding-left: 10px;
  369. }
  370. .main-box {
  371. padding: 10px;
  372. .table-title {
  373. border: 1px solid rgb(230, 230, 230);
  374. background: rgba(241, 241, 241, 0.548);
  375. height: 40px;
  376. line-height: 40px;
  377. padding-left: 10px;
  378. margin: 10px 0;
  379. }
  380. .list-box {
  381. height: 200px;
  382. overflow: auto;
  383. .desc {
  384. float: right;
  385. margin-right: 10px;
  386. display: block;
  387. width: 200px;
  388. color: rgb(167, 163, 163);
  389. }
  390. }
  391. }
  392. }
  393. }
  394. </style>