NegativeGood.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <script setup lang="ts">
  2. import { Ref, inject, reactive, ref } from 'vue'
  3. import { useShopInfo } from '/@/stores/shopInfo'
  4. import { storeToRefs } from 'pinia'
  5. import { ElMessage } from 'element-plus'
  6. import { request } from '/@/utils/service'
  7. let selections = [] // 添加选中的项
  8. let addedSels = [] // 删除选中的项
  9. const currentPage = ref() // 当前页
  10. const pageSize = ref(20) // 每页显示条目数
  11. const totalItems = ref() // 数据总量
  12. const negativeTabs = ref('first')
  13. const topTabs = ref('first')
  14. const loading = ref(false)
  15. const respCampaignId = inject<Ref>('respCampaignId')
  16. const respAdGroupId = inject<Ref>('respAdGroupId')
  17. const shopInfo = useShopInfo()
  18. const { profile } = storeToRefs(shopInfo)
  19. const negativeTableData = ref([])
  20. const addedNegetiveTableData = ref([])
  21. let negativeGoodsLoading = ref(false)
  22. let negativeList = reactive([])
  23. const tableData = negativeList
  24. let inputAddedNegGoods = ref([])
  25. const negativeInput = ref('')
  26. function setNegativeTableData(asin = '') {
  27. negativeGoodsLoading.value = true
  28. return request({
  29. url: '/api/sellers/listings/all/',
  30. method: 'GET',
  31. params: {
  32. page: currentPage.value,
  33. limit: pageSize.value,
  34. profile_id: profile.value.profile_id,
  35. asin,
  36. },
  37. })
  38. .then((resp) => {
  39. negativeTableData.value = resp.data
  40. inputAddedNegGoods.value = resp.data
  41. negativeGoodsLoading.value = false
  42. })
  43. .catch((error) => {
  44. console.error('Error fetching data:', error)
  45. negativeGoodsLoading.value = false
  46. })
  47. }
  48. const negativeGoodsTextarea = ref('')
  49. // 输入tab的textarea
  50. function addNegativeGoods() {
  51. console.log('negativeGoodsTextarea', negativeGoodsTextarea.value)
  52. loading.value = true
  53. setNegativeTableData(negativeGoodsTextarea.value)
  54. .then(() => {
  55. addedNegetiveTableData.value = [...addedNegetiveTableData.value, ...inputAddedNegGoods.value]
  56. })
  57. .catch((error) => {
  58. console.error('Error fetching data:', error)
  59. })
  60. .finally(() => {
  61. loading.value = false
  62. })
  63. }
  64. function addSingleNegativeGoods(scope) {
  65. const isAlreadyAdded = addedNegetiveTableData.value.some((item) => item.asin === scope.row.asin)
  66. if (!isAlreadyAdded) {
  67. addedNegetiveTableData.value.push(scope.row)
  68. } else {
  69. console.log('Item is already added.')
  70. }
  71. }
  72. function delAllNegativeGoods() {
  73. addedNegetiveTableData.value = []
  74. }
  75. function delSingleNegativeGoods(scope) {
  76. const index = addedNegetiveTableData.value.findIndex((item) => item.asin === scope.row.asin)
  77. if (index !== -1) {
  78. addedNegetiveTableData.value.splice(index, 1)
  79. console.log('Item removed successfully.')
  80. } else {
  81. console.log('Item not found.')
  82. }
  83. }
  84. function searchNegativeGoods(e) {
  85. console.log(e)
  86. if (e === '') {
  87. negativeTableData.value = []
  88. } else {
  89. setNegativeTableData(e)
  90. }
  91. }
  92. function handleAddedNegGoods(selection) {
  93. addedSels = selection
  94. }
  95. async function negativeGoodsSave() {
  96. console.log(addedNegetiveTableData.value)
  97. const asinList = addedNegetiveTableData.value.map((item) => item.asin)
  98. console.log('🚀 ~ negativeGoodsSave ~ asinList-->>', asinList)
  99. negativeGoodsLoading.value = true
  100. console.log('addedNegetiveTableData', addedNegetiveTableData.value)
  101. try {
  102. const requestData = {
  103. profile_id: profile.value.profile_id,
  104. campaignId: respCampaignId.value,
  105. adGroupId: respAdGroupId.value,
  106. asinList: asinList,
  107. matchType: 'ASIN_SAME_AS',
  108. state: 'PAUSED',
  109. }
  110. const filteredRequestData = Object.fromEntries(Object.entries(requestData).filter(([_, v]) => v != null))
  111. const resp = await request({
  112. url: '/api/ad_manage/sptargets/add/negative/targets/',
  113. method: 'POST',
  114. data: filteredRequestData,
  115. })
  116. console.log('🚀 ~ negativeWordsSave ~ resp-->>', resp)
  117. negativeGoodsLoading.value = false
  118. if (resp.data.success.length !== 0) {
  119. ElMessage({
  120. message: '否定商品创建成功',
  121. type: 'success',
  122. })
  123. delAllNegative()
  124. } else {
  125. ElMessage.error('否定商品创建失败!')
  126. }
  127. } catch (error) {
  128. console.error('请求失败:', error)
  129. }
  130. }
  131. function delAllNegative() {
  132. negativeList.length = 0
  133. }
  134. const headerCellStyle = (args) => {
  135. if (args.rowIndex === 0) {
  136. return {
  137. backgroundColor: 'rgba(245, 245, 245, 0.9)',
  138. }
  139. }
  140. }
  141. </script>
  142. <template>
  143. <div prop="matchType" style="width: 100%; margin-top: 20px">
  144. <el-divider content-position="left">
  145. <span style="font-size: 18px; font-weight: 700">否定商品</span>
  146. </el-divider>
  147. <div style="width: 100%; height: 600px; display: flex; border: 1px solid #e5e7ec; border-radius: 6px" v-loading="negativeGoodsLoading">
  148. <div style="width: 50%; border-right: 1px solid #e5e7ec">
  149. <el-tabs v-model="topTabs" stretch>
  150. <el-tab-pane label="排除商品" name="first">
  151. <el-tabs v-model="negativeTabs" class="demo-tabs">
  152. <el-tab-pane label="搜索" name="first">
  153. <div style="margin-bottom: 10px">
  154. <el-input placeholder="按ASIN搜索" v-model="negativeInput" @change="searchNegativeGoods" clearable />
  155. </div>
  156. <el-table
  157. height="495"
  158. style="width: 100%"
  159. v-loading="loading"
  160. :data="negativeTableData"
  161. :header-cell-style="headerCellStyle"
  162. :show-header="false">
  163. <el-table-column prop="asin" label="商品">
  164. <template #default="scope">
  165. <div style="display: flex; align-items: center">
  166. <div style="margin-right: 8px; line-height: normal">
  167. <el-image class="img-box" :src="scope.row.image_link" />
  168. </div>
  169. <div>
  170. <el-tooltip class="box-item" effect="dark" :content="scope.row.title" placement="top">
  171. <div class="single-line">{{ scope.row.title ? scope.row.title : '--' }}</div>
  172. </el-tooltip>
  173. <span>
  174. ASIN: <span class="data-color" style="margin-right: 8px">{{ scope.row.asin ? scope.row.asin : '--' }}</span>
  175. </span>
  176. </div>
  177. </div>
  178. </template>
  179. </el-table-column>
  180. <el-table-column prop="name" label="Name" width="120" align="right">
  181. <template #header> </template>
  182. <template #default="scope">
  183. <el-button type="primary" size="small" @click="addSingleNegativeGoods(scope)" text>添加</el-button>
  184. </template>
  185. </el-table-column>
  186. </el-table>
  187. </el-tab-pane>
  188. <el-tab-pane label="输入" name="second">
  189. <el-input
  190. v-model="negativeGoodsTextarea"
  191. :rows="17"
  192. type="textarea"
  193. disabled="true"
  194. maxlength="11000"
  195. style="padding: 10px 10px" />
  196. <div style="display: flex; flex-direction: row-reverse; margin-top: 10px">
  197. <el-button style="margin-right: 10px" type="primary" text bg @click="addNegativeGoods">添加</el-button>
  198. </div>
  199. </el-tab-pane>
  200. </el-tabs>
  201. </el-tab-pane>
  202. <el-tab-pane label="排除品牌" name="second">
  203. </el-tab-pane>
  204. </el-tabs>
  205. </div>
  206. <div style="width: 50%">
  207. <el-card class="box-card" shadow="never" style="border: none">
  208. <template #header>
  209. <div class="card-header">
  210. <span style="font-weight: 550; font-size: 15px; color: #1f2128">已添加: {{ addedNegetiveTableData.length }}</span>
  211. <el-button class="button" type="danger" text bg @click="delAllNegativeGoods">全部删除</el-button>
  212. </div>
  213. </template>
  214. <div class="card-body"></div>
  215. </el-card>
  216. <div style="padding: 0 10px 0 10px; margin-top: -30px">
  217. <el-table
  218. :data="addedNegetiveTableData"
  219. height="473"
  220. style="width: 100%"
  221. :header-cell-style="headerCellStyle"
  222. @selection-change="handleAddedNegGoods">
  223. <el-table-column prop="asin" label="商品">
  224. <template #default="scope">
  225. <div style="display: flex; align-items: center">
  226. <div style="margin-right: 8px; line-height: normal">
  227. <el-image class="img-box" :src="scope.row.image_link" />
  228. </div>
  229. <div>
  230. <el-tooltip class="box-item" effect="dark" :content="scope.row.title" placement="top">
  231. <div class="single-line">{{ scope.row.title ? scope.row.title : '--' }}</div>
  232. </el-tooltip>
  233. <span
  234. >ASIN:
  235. <span class="data-color" style="margin-right: 8px">{{ scope.row.asin ? scope.row.asin : '--' }}</span>
  236. </span>
  237. </div>
  238. </div>
  239. </template>
  240. </el-table-column>
  241. <el-table-column label="操作" width="120" align="right">
  242. <template #default="scope">
  243. <el-button type="primary" size="small" @click="delSingleNegativeGoods(scope)" text>删除</el-button>
  244. </template>
  245. </el-table-column>
  246. </el-table>
  247. </div>
  248. <div style="display: flex; justify-content: space-around; padding-top: 10px">
  249. <el-button plain type="primary" @click="negativeGoodsSave" :disabled="!addedNegetiveTableData.length">保存</el-button>
  250. </div>
  251. </div>
  252. </div>
  253. </div>
  254. </template>
  255. <style lang="scss" scoped>
  256. ::v-deep(.el-form--default.el-form--label-top .el-form-item .el-form-item__label) {
  257. font-weight: 500;
  258. }
  259. .column-margin-bottom label.el-radio.is-bordered {
  260. margin-bottom: 10px;
  261. padding: 35px;
  262. }
  263. ::v-deep(.column-margin-bottom label.el-radio.is-bordered span.el-radio__inner) {
  264. margin-top: -18px;
  265. margin-left: -15px;
  266. }
  267. .demo-tabs > .el-tabs__content {
  268. padding: 52px;
  269. color: #6b778c;
  270. font-size: 32px;
  271. font-weight: 600;
  272. }
  273. /* 广告组商品Tab栏 */
  274. ::v-deep(.demo-tabs .el-tabs__nav-scroll) {
  275. overflow: hidden;
  276. margin-left: 20px;
  277. }
  278. ::v-deep(.el-tabs__nav-wrap::after) {
  279. height: 2px !important;
  280. }
  281. ::v-deep(.el-table__inner-wrapper::before) {
  282. background-color: white;
  283. }
  284. // 表格内容边距
  285. div {
  286. & #pane-first,
  287. & #pane-second {
  288. margin: 10px;
  289. }
  290. }
  291. // 输入底部样式
  292. ::v-deep(.card-box .el-card__body) {
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. padding: 12px;
  297. }
  298. .card-header {
  299. display: flex;
  300. justify-content: space-between;
  301. align-items: center;
  302. }
  303. .box-card {
  304. width: 100%;
  305. // margin: 10px 0 10px 10px;
  306. margin-right: 10px;
  307. }
  308. .single-line {
  309. color: rgb(30, 33, 41);
  310. overflow: hidden;
  311. display: -webkit-box;
  312. -webkit-box-orient: vertical;
  313. -webkit-line-clamp: 1;
  314. white-space: pre-wrap;
  315. word-break: break-word;
  316. }
  317. .data-color {
  318. color: rgb(30, 33, 41);
  319. }
  320. .img-box {
  321. width: 60px;
  322. height: 60px;
  323. margin-top: 5px;
  324. border: 1px solid rgb(194, 199, 207);
  325. border-radius: 4px;
  326. }
  327. ::v-deep(.goods-orientation-tabs .el-tabs__nav-scroll) {
  328. margin-left: -20px !important;
  329. }
  330. ::v-deep(.category-tabs .el-tabs__nav) {
  331. margin-left: 20px;
  332. }
  333. ::v-deep(.goods-orientation-tabs #tab-1) {
  334. /* 商品定向Tab栏 */
  335. border-right: 0;
  336. }
  337. </style>