CustomTarget.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <div class="customize-container">
  3. <el-card body-style="padding: 20px 80px 0 80px;">
  4. <div class="custom-card-title">
  5. <span class="custom-card-icon">|</span>
  6. <span class="custom-card-Text">自定义定向</span>
  7. </div>
  8. <div class="main-container">
  9. <div class="left-container">
  10. <el-tabs v-model="topTabName" class="demo-tabs" @tab-click="handleClick">
  11. <div class="tab-container-fixed-top">
  12. <span class="tab-top-label">添加定向时的竞价设置: </span>
  13. <el-select v-model="bidType">
  14. <el-option v-for="item in bidTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
  15. </el-select>
  16. <el-input v-model="bid" :disabled="bidType == '1'" style="width: 200px">
  17. <template #prepend>$</template>
  18. </el-input>
  19. </div>
  20. <el-tab-pane label="亚马逊受众" name="audience">
  21. <div>
  22. <div style="display: flex">
  23. <el-select v-model="audienceType" @change="handleSearchChange" style="width: 140px; margin-right: 10px">
  24. <el-option v-for="item in audienceTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
  25. </el-select>
  26. <el-input v-model="keywordInput" @change="handleSearchChange" placeholder="请输入关键词进行过滤"></el-input>
  27. </div>
  28. <hr style="margin-top: 5px" />
  29. <el-table
  30. :data="searchData"
  31. :row-key="(item) => item.audienceId"
  32. :show-header="false"
  33. v-loading="searchLoading"
  34. height="550"
  35. style="width: 100%">
  36. <el-table-column prop="date" label="Date">
  37. <template #default="{ row }">
  38. <div style="font-weight: 500; color: #000">{{ row.category }}</div>
  39. <div style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden">{{ row.audienceName }}</div>
  40. <div style="color: rgba(0, 0, 0, 0.45)">预估人数: {{ row.lowerBoundInclusive }} - {{ row.upperBoundExclusive }}</div>
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="opotion" label="option" width="80">
  44. <template #default="{ row }">
  45. <el-button type="primary" size="small" link @click="handleAddButtonClick(row)">添加</el-button>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. </div>
  50. </el-tab-pane>
  51. <el-tab-pane label="浏览再营销" name="views">
  52. <div class="tab-title">触达浏览过您推广的商品或其他类似商品、商品品类、品牌以及其他商品功能的顾客</div>
  53. <el-tabs v-model="viewsTabName" type="border-card">
  54. <div class="el-row align-center-bottom">
  55. <span class="select-label">回溯期: </span>
  56. <el-select v-model="viewsLookBack">
  57. <el-option v-for="item in viewsLookBackOptions" :key="item.value" :label="item.label" :value="item.value" />
  58. </el-select>
  59. </div>
  60. <el-tab-pane label="建议" name="advice">
  61. <div style="height: 450px">
  62. <div>动态细分</div>
  63. <hr style="margin: 5px 0" />
  64. <div>
  65. <div style="display: flex; justify-content: space-between">
  66. <div>推广商品</div>
  67. <el-button type="primary" size="small" link @click="addPromoteProduct">添加</el-button>
  68. </div>
  69. <div style="display: flex; justify-content: space-between">
  70. <div>与推广商品类似的商品</div>
  71. <el-button type="primary" size="small" link @click="addPromoteSimilar">添加</el-button>
  72. </div>
  73. </div>
  74. </div>
  75. </el-tab-pane>
  76. <el-tab-pane label="搜索" name="search">
  77. <BrowseSearch @add-to-table="browseOrientation" @form-submitted="browseRefine"></BrowseSearch>
  78. </el-tab-pane>
  79. </el-tabs>
  80. </el-tab-pane>
  81. <el-tab-pane label="购买再营销" name="purchases">
  82. <div class="tab-title">向购买过广告商品或其他相关商品、商品类别、品牌及其他商品功能的购买者传递信息</div>
  83. <el-tabs v-model="purchasesTabName" type="border-card">
  84. <div class="el-row align-center-bottom">
  85. <span class="select-label">回溯期: </span>
  86. <el-select v-model="purchasesLookBack">
  87. <el-option v-for="item in purchasesLookBackOptions" :key="item.value" :label="item.label" :value="item.value" />
  88. </el-select>
  89. </div>
  90. <el-tab-pane label="建议" name="advice">
  91. <div style="height: 450px"></div>
  92. </el-tab-pane>
  93. <el-tab-pane label="搜索" name="search">
  94. <BuySearch @add-to-table="buyOrientation" @form-submitted="buyRefine"></BuySearch>
  95. </el-tab-pane>
  96. </el-tabs>
  97. </el-tab-pane>
  98. </el-tabs>
  99. </div>
  100. <!-- 右侧内容区 -->
  101. <div class="right-container">
  102. <div class="right-container-top">
  103. <div style="padding-left: 15px; font-size: 15px">
  104. <span style="color: #8e9095">已添加: </span> <span style="font-weight: 500">{{ addedTableData.length }}</span>
  105. </div>
  106. <el-button link type="danger" @click="handleDeleteAll" style="margin-right: 15px">删除所有</el-button>
  107. </div>
  108. <el-table :data="addedTableData" :header-cell-style="changeTableHeader" height="600" style="width: 100%">
  109. <el-table-column prop="date" label="商品">
  110. <template #default="{ row }">
  111. <div v-if="row.cna || row.dialogTitle">浏览再营销</div>
  112. <div v-if="row.cna || row.dialogTitle">
  113. 分类: <span style="color: black">{{ row.cna ? row.cna : row.dialogTitle }}</span>
  114. </div>
  115. <div v-if="row.low_prices || row.high_prices">
  116. 商品价格: <span style="color: black">{{ row.low_prices ? row.low_prices : '--' }}</span>
  117. <span style="color: black">{{ row.high_prices ? row.high_prices : '--' }}</span>
  118. </div>
  119. <div v-if="row.delivery">
  120. 配送:
  121. <span style="color: black">{{ row.delivery ? row.delivery: '--' }}</span>
  122. </div>
  123. <div v-if="row.lookback">
  124. 回溯期: <span style="color: black">{{ row.lookback ? row.lookback : '--' }}</span>
  125. </div>
  126. <div v-if="row.audienceName">
  127. <div style="font-weight: 500; color: #000">{{ row.category }}</div>
  128. <el-tooltip class="box-item" effect="dark" :content="row.audienceName" placement="top">
  129. <div style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden">{{ row.audienceName }}</div>
  130. </el-tooltip>
  131. <div style="color: rgba(0, 0, 0, 0.45)">预估人数: {{ row.lowerBoundInclusive }} - {{ row.upperBoundExclusive }}</div>
  132. </div>
  133. </template>
  134. </el-table-column>
  135. <el-table-column prop="name" label="竞价" width="160">
  136. <template #default="{ row }">
  137. <el-input v-model.number="row.bid">
  138. <template #prepend>$</template>
  139. </el-input>
  140. </template>
  141. </el-table-column>
  142. <el-table-column prop="address" label="当前建议竞价" width="160">
  143. <template #default="{ row }">
  144. <div>$</div>
  145. <div>$</div>
  146. </template>
  147. </el-table-column>
  148. <el-table-column label="操作" width="60">
  149. <template #default="{ row }">
  150. <el-button link type="danger" size="small" @click="handleButtonClick(row)">删除</el-button>
  151. </template>
  152. </el-table-column>
  153. </el-table>
  154. <div style="display: flex; justify-content: space-around; padding-top: 15px">
  155. <el-button type="primary" plain :disabled="!addedTableData.length" @click="handleSave">保存</el-button>
  156. </div>
  157. </div>
  158. </div>
  159. </el-card>
  160. </div>
  161. </template>
  162. <script setup lang="ts">
  163. import { onMounted, ref, watch, reactive, CSSProperties } from 'vue'
  164. import { request } from '/@/utils/service'
  165. import BrowseSearch from './BrowseSearch.vue'
  166. import BuySearch from './BuySearch.vue'
  167. import { ElMessage, type FormInstance, type FormRules, type TabsPaneContext } from 'element-plus'
  168. import { getAudiencesList } from '../api/index'
  169. import { useShopInfo } from '/@/stores/shopInfo'
  170. import { storeToRefs } from 'pinia'
  171. const shopInfo = useShopInfo()
  172. const { profile } = storeToRefs(shopInfo)
  173. // tab栏
  174. const topTabName = ref('audience')
  175. function handleClick(tab: TabsPaneContext, event: Event) {
  176. // console.log(tab, event)
  177. }
  178. // tab栏顶部固定部分功能
  179. const bidType = ref('2')
  180. const bidTypeOptions = [
  181. {
  182. value: '1',
  183. label: '建议竞价',
  184. },
  185. {
  186. value: '2',
  187. label: '自定义竞价',
  188. },
  189. ]
  190. const bid = ref('0.75')
  191. watch(
  192. bidType,
  193. () => {
  194. if (bidType.value == '1') {
  195. bid.value = ''
  196. } else {
  197. bid.value = '0.75'
  198. }
  199. },
  200. { immediate: true }
  201. )
  202. // 亚马逊受众tab的 下拉框和输入框
  203. const audienceType = ref('')
  204. const audienceTypeOptions = [
  205. {
  206. value: '',
  207. label: '所有受众',
  208. },
  209. {
  210. value: 'Lifestyle',
  211. label: '生活方式',
  212. },
  213. {
  214. value: 'Interest',
  215. label: '兴趣',
  216. },
  217. {
  218. value: 'Life event',
  219. label: '生活事件',
  220. },
  221. {
  222. value: 'In-market',
  223. label: '场内客群',
  224. },
  225. ]
  226. const keywordInput = ref('') // 关键词过滤输入框
  227. // 浏览再营销下的tab栏
  228. const viewsTabName = ref('advice')
  229. const viewsLookBack = ref('7')
  230. const viewsLookBackOptions = [
  231. {
  232. value: '7',
  233. label: '7天',
  234. },
  235. {
  236. value: '14',
  237. label: '14天',
  238. },
  239. {
  240. value: '30',
  241. label: '30天',
  242. },
  243. {
  244. value: '60',
  245. label: '60天',
  246. },
  247. {
  248. value: '90',
  249. label: '90天',
  250. },
  251. ]
  252. // 购买再营销下的tab栏
  253. const purchasesTabName = ref('advice')
  254. const purchasesLookBack = ref('7')
  255. const purchasesLookBackOptions = [
  256. {
  257. value: '7',
  258. label: '7天',
  259. },
  260. {
  261. value: '14',
  262. label: '14天',
  263. },
  264. {
  265. value: '30',
  266. label: '30天',
  267. },
  268. {
  269. value: '60',
  270. label: '60天',
  271. },
  272. {
  273. value: '90',
  274. label: '90天',
  275. },
  276. ]
  277. // 已添加的表格数据
  278. const addedTableData = ref([])
  279. function browseOrientation(data) {
  280. const exists = addedTableData.value.some((item) => item.cid === data.cid)
  281. if (!exists) {
  282. const dataWithLookback = {
  283. type: 'c',
  284. tactictype: 'views',
  285. lookback: viewsLookBack.value,
  286. bid: bid.value,
  287. classificationId: data.cid
  288. }
  289. console.log('dataWithLookback', dataWithLookback)
  290. addedTableData.value.push(dataWithLookback)
  291. } else {
  292. ElMessage({
  293. message: '请勿重复添加',
  294. type: 'warning',
  295. })
  296. }
  297. }
  298. function buyOrientation(data) {
  299. const exists = addedTableData.value.some((item) => item.cid === data.cid)
  300. if (!exists) {
  301. const dataWithLookback = {
  302. ...data,
  303. lookback: viewsLookBack.value,
  304. }
  305. console.log('dataWithLookback', dataWithLookback)
  306. addedTableData.value.push(dataWithLookback)
  307. } else {
  308. ElMessage({
  309. message: '请勿重复添加',
  310. type: 'warning',
  311. })
  312. }
  313. }
  314. // 点击细化后弹窗确认触发
  315. const deliveryMap = {
  316. eligible: '具备Prime资格',
  317. diseligible: '不具备Prime资格',
  318. all: '所有',
  319. }
  320. function browseRefine(data) {
  321. const exists = addedTableData.value.some((item) => item.cid === data.cid)
  322. if (!exists) {
  323. console.log('data', data)
  324. const tableRow = {
  325. type: 'c',
  326. tactictype: 'views',
  327. lookback: viewsLookBack.value,
  328. bid: bid.value,
  329. brandId: data.selectedBrands,
  330. classificationId: data.cid,
  331. delivery: data.delivery,
  332. // categoryId: data.categoryId,
  333. dialogTitle: data.dialogTitle, // 分类名称
  334. low_prices: data.prices.lowest,
  335. high_prices: data.prices.highest,
  336. low_rating: data.starRating[0],
  337. high_rating: data.starRating[1],
  338. }
  339. addedTableData.value.push(tableRow) // 添加到表格数据
  340. console.log('tableRow', tableRow)
  341. } else {
  342. ElMessage({
  343. message: '请勿重复添加',
  344. type: 'warning',
  345. })
  346. }
  347. }
  348. function buyRefine(data) {
  349. const exists = addedTableData.value.some((item) => item.cid === data.cid)
  350. if (!exists) {
  351. // addedTableData.value.push(data)
  352. const deliveryText = deliveryMap[data.delivery]
  353. const tableRow = {
  354. type: 'c',
  355. tactictype: 'views',
  356. lookback: viewsLookBack.value,
  357. bid: bid.value,
  358. brandId: data.brandId,
  359. classificationId: data.cid,
  360. delivery: data.delivery,
  361. categoryId: data.categoryId,
  362. dialogTitle: data.dialogTitle, // 分类名称
  363. prices: `\$${data.prices.lowest} ~ \$${data.prices.highest}`, // 价格范围
  364. // 其他需要的字段...
  365. }
  366. addedTableData.value.push(tableRow) // 添加到表格数据
  367. } else {
  368. ElMessage({
  369. message: '请勿重复添加',
  370. type: 'warning',
  371. })
  372. }
  373. }
  374. // 获取搜索的数据
  375. const searchLoading = ref(false)
  376. const searchData = ref([])
  377. const categoryMap = {
  378. Lifestyle: '生活方式',
  379. 'In-market': '场内客群',
  380. Interest: '兴趣',
  381. 'Life event': '生活事件',
  382. }
  383. function handleSearchChange() {
  384. getCustomData()
  385. }
  386. async function getCustomData() {
  387. searchLoading.value = true
  388. const query = {
  389. profile_id: profile.value.profile_id,
  390. categoryvalues: audienceType.value,
  391. values: keywordInput.value,
  392. }
  393. try {
  394. const response = await getAudiencesList(query)
  395. searchData.value = response.data.audiences.map((audience) => ({
  396. ...audience,
  397. category: categoryMap[audience.category] || audience.category,
  398. }))
  399. } catch (error) {
  400. console.error('error: ', error)
  401. } finally {
  402. searchLoading.value = false
  403. }
  404. }
  405. function handleAddButtonClick(row) {
  406. // 检查该行数据是否已经存在于 addedTableData 中
  407. const exists = addedTableData.value.some((item) => item.audienceId === row.audienceId)
  408. if (!exists) {
  409. // 如果不存在,则添加它到 addedTableData
  410. addedTableData.value.push(row)
  411. } else {
  412. // 如果已存在,显示一个警告消息
  413. ElMessage({
  414. message: `选项 ${row.audienceName} 已经添加,不能重复添加`,
  415. type: 'warning',
  416. })
  417. }
  418. }
  419. // 删除所有Table数据
  420. function handleDeleteAll() {
  421. addedTableData.value = []
  422. }
  423. // 单独删除功能
  424. function handleButtonClick(row) {
  425. if ('cid' in row) {
  426. // 如果行数据包含 cid 属性,使用 cid 来过滤
  427. addedTableData.value = addedTableData.value.filter((item) => item.cid !== row.cid)
  428. } else if ('audienceId' in row) {
  429. addedTableData.value = addedTableData.value.filter((item) => item.audienceId !== row.audienceId)
  430. } else if ('categoryId' in row) {
  431. addedTableData.value = addedTableData.value.filter((item) => item.cid !== row.cid)
  432. }
  433. }
  434. function addPromoteProduct() {
  435. const newProduct = {
  436. type: 'p',
  437. tactictype: 'purchases',
  438. lookback: viewsLookBack.value,
  439. asin: '',
  440. bid: 0.2,
  441. productType: 'relatedProduct',
  442. }
  443. // 例如 type, tactictype, productType 等字段来判断
  444. const exists = addedTableData.value.some(
  445. (item) => item.type === newProduct.type && item.tactictype === newProduct.tactictype && item.productType === newProduct.productType
  446. )
  447. if (!exists) {
  448. // 如果不存在,则添加它到 addedTableData
  449. addedTableData.value.push(newProduct)
  450. } else {
  451. // 如果已存在,显示一个警告消息
  452. ElMessage({
  453. message: '已经添加了相关商品,不能重复添加',
  454. type: 'warning',
  455. })
  456. }
  457. }
  458. function addPromoteSimilar() {}
  459. // 点击保存触发
  460. function handleSave() {
  461. // createCustom()
  462. console.log('addedTableData:', addedTableData.value)
  463. }
  464. function changeTableHeader(row) {
  465. if (row) {
  466. return {
  467. background: '#f5f7fa',
  468. }
  469. }
  470. }
  471. </script>
  472. <style scoped>
  473. .customize-container {
  474. margin-top: 10px;
  475. }
  476. .custom-card-title {
  477. font-weight: 700;
  478. padding-bottom: 18px;
  479. }
  480. .custom-card-Text {
  481. font-size: 18px;
  482. padding-left: 5px;
  483. }
  484. .custom-card-icon {
  485. color: #306cd7;
  486. font-size: 26px;
  487. }
  488. .main-container {
  489. display: flex;
  490. border: 1px solid #e5e7eb;
  491. height: 700px;
  492. margin-bottom: 20px;
  493. }
  494. .left-container {
  495. width: 50%;
  496. height: 699px;
  497. border-right: 1px solid #e5e7eb;
  498. }
  499. .right-container {
  500. width: 50%;
  501. height: 699px;
  502. border-bottom: 0;
  503. }
  504. .right-container-top {
  505. height: 40px;
  506. display: flex;
  507. justify-content: space-between;
  508. align-items: center;
  509. }
  510. .demo-tabs {
  511. padding: 0 10px;
  512. }
  513. .demo-tabs > .el-tabs__content {
  514. padding: 32px;
  515. color: #6b778c;
  516. font-size: 32px;
  517. font-weight: 600;
  518. }
  519. /* 选中时的字体颜色 */
  520. ::v-deep(.demo-tabs .el-tabs__item.is-top.is-active) {
  521. color: #3569d6;
  522. }
  523. /* 选中时的下划线颜色 */
  524. ::v-deep(.demo-tabs .el-tabs__active-bar.is-top) {
  525. background-color: #3569d6;
  526. }
  527. .tab-container-fixed-top {
  528. display: flex;
  529. align-items: center;
  530. margin-bottom: 4px;
  531. gap: 8px;
  532. font-size: 13px;
  533. margin: 10px 0;
  534. }
  535. .tab-top-label {
  536. color: #4e5969;
  537. font-weight: 700;
  538. margin-right: 10px;
  539. }
  540. .align-center-bottom {
  541. align-items: center;
  542. margin-bottom: 12px;
  543. }
  544. .tab-title {
  545. line-height: 20px;
  546. padding-bottom: 10px;
  547. color: #8e9095;
  548. }
  549. .select-label {
  550. padding-right: 5px;
  551. color: #606266;
  552. }
  553. /* 修改隐藏table底部border */
  554. ::v-deep(.el-table__inner-wrapper::before) {
  555. background-color: #ffffff;
  556. }
  557. </style>