NegativeGood.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div prop="matchType" style="width: 100%; margin-top: 20px">
  3. <el-divider content-position="left">
  4. <span style="font-size: 18px; font-weight: 700">否定商品</span>
  5. </el-divider>
  6. <div style="width: 100%; height: 600px; display: flex; border: 1px solid #e5e7ec; border-radius: 6px" v-loading="negativeGoodsLoading">
  7. <div style="width: 50%; border-right: 1px solid #e5e7ec">
  8. <el-tabs v-model="topTabs" stretch>
  9. <el-tab-pane label="排除商品" name="first">
  10. <el-tabs v-model="negativeTabs" class="demo-tabs">
  11. <el-tab-pane label="搜索" name="first">
  12. <div style="margin-bottom: 10px">
  13. <el-input placeholder="按ASIN搜索" v-model="negativeInput" @change="searchNegativeGoods" clearable />
  14. </div>
  15. <el-table
  16. height="495"
  17. style="width: 100%"
  18. v-loading="loading"
  19. :data="negativeTableData"
  20. :header-cell-style="headerCellStyle"
  21. :show-header="false">
  22. <el-table-column prop="asin" label="商品">
  23. <template #default="scope">
  24. <div style="display: flex; align-items: center">
  25. <div style="margin-right: 8px; line-height: normal">
  26. <el-image class="img-box" :src="scope.row.image_link" />
  27. </div>
  28. <div>
  29. <el-tooltip class="box-item" effect="dark" :content="scope.row.title" placement="top">
  30. <div class="single-line">{{ scope.row.title ? scope.row.title : '--' }}</div>
  31. </el-tooltip>
  32. <span>
  33. ASIN: <span class="data-color" style="margin-right: 8px">{{ scope.row.asin ? scope.row.asin : '--' }}</span>
  34. </span>
  35. </div>
  36. </div>
  37. </template>
  38. </el-table-column>
  39. <el-table-column prop="name" label="Name" width="120" align="right">
  40. <template #header> </template>
  41. <template #default="scope">
  42. <el-button type="primary" size="small" @click="addSingleNegativeGoods(scope)" text>添加</el-button>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </el-tab-pane>
  47. <el-tab-pane label="输入" name="second">
  48. <el-input
  49. v-model="negativeGoodsTextarea"
  50. :rows="17"
  51. type="textarea"
  52. disabled="true"
  53. maxlength="11000"
  54. style="padding: 10px 10px" />
  55. <div style="display: flex; flex-direction: row-reverse; margin-top: 10px">
  56. <el-button style="margin-right: 10px" type="primary" text bg @click="addNegativeGoods">添加</el-button>
  57. </div>
  58. </el-tab-pane>
  59. </el-tabs>
  60. </el-tab-pane>
  61. <el-tab-pane label="排除品牌" name="second">
  62. </el-tab-pane>
  63. </el-tabs>
  64. </div>
  65. <div style="width: 50%">
  66. <el-card class="box-card" shadow="never" style="border: none">
  67. <template #header>
  68. <div class="card-header">
  69. <span style="font-weight: 550; font-size: 15px; color: #1f2128">已添加: {{ addedNegetiveTableData.length }}</span>
  70. <el-button class="button" type="danger" text bg @click="delAllNegativeGoods">全部删除</el-button>
  71. </div>
  72. </template>
  73. <div class="card-body"></div>
  74. </el-card>
  75. <div style="padding: 0 10px 0 10px; margin-top: -30px">
  76. <el-table
  77. :data="addedNegetiveTableData"
  78. height="473"
  79. style="width: 100%"
  80. :header-cell-style="headerCellStyle"
  81. @selection-change="handleAddedNegGoods">
  82. <el-table-column prop="asin" label="商品">
  83. <template #default="scope">
  84. <div style="display: flex; align-items: center">
  85. <div style="margin-right: 8px; line-height: normal">
  86. <el-image class="img-box" :src="scope.row.image_link" />
  87. </div>
  88. <div>
  89. <el-tooltip class="box-item" effect="dark" :content="scope.row.title" placement="top">
  90. <div class="single-line">{{ scope.row.title ? scope.row.title : '--' }}</div>
  91. </el-tooltip>
  92. <span
  93. >ASIN:
  94. <span class="data-color" style="margin-right: 8px">{{ scope.row.asin ? scope.row.asin : '--' }}</span>
  95. </span>
  96. </div>
  97. </div>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="操作" width="120" align="right">
  101. <template #default="scope">
  102. <el-button type="primary" size="small" @click="delSingleNegativeGoods(scope)" text>删除</el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. </div>
  107. <div style="display: flex; justify-content: space-around; padding-top: 10px">
  108. <el-button plain type="primary" @click="negativeGoodsSave" :disabled="!addedNegetiveTableData.length">保存</el-button>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. </template>
  114. <script setup lang="ts">
  115. import { Ref, inject, reactive, ref } from 'vue'
  116. import { useShopInfo } from '/@/stores/shopInfo'
  117. import { storeToRefs } from 'pinia'
  118. import { ElMessage } from 'element-plus'
  119. import { request } from '/@/utils/service'
  120. let selections = [] // 添加选中的项
  121. let addedSels = [] // 删除选中的项
  122. const currentPage = ref() // 当前页
  123. const pageSize = ref(20) // 每页显示条目数
  124. const totalItems = ref() // 数据总量
  125. const negativeTabs = ref('first')
  126. const topTabs = ref('first')
  127. const loading = ref(false)
  128. const respCampaignId = inject<Ref>('respCampaignId')
  129. const respAdGroupId = inject<Ref>('respAdGroupId')
  130. const shopInfo = useShopInfo()
  131. const { profile } = storeToRefs(shopInfo)
  132. const negativeTableData = ref([])
  133. const addedNegetiveTableData = ref([])
  134. let negativeGoodsLoading = ref(false)
  135. let negativeList = reactive([])
  136. const tableData = negativeList
  137. let inputAddedNegGoods = ref([])
  138. const negativeInput = ref('')
  139. function setNegativeTableData(asin = '') {
  140. negativeGoodsLoading.value = true
  141. return request({
  142. url: '/api/sellers/listings/all/',
  143. method: 'GET',
  144. params: {
  145. page: currentPage.value,
  146. limit: pageSize.value,
  147. profile_id: profile.value.profile_id,
  148. asin,
  149. },
  150. })
  151. .then((resp) => {
  152. negativeTableData.value = resp.data
  153. inputAddedNegGoods.value = resp.data
  154. negativeGoodsLoading.value = false
  155. })
  156. .catch((error) => {
  157. console.error('Error fetching data:', error)
  158. negativeGoodsLoading.value = false
  159. })
  160. }
  161. const negativeGoodsTextarea = ref('')
  162. // 输入tab的textarea
  163. function addNegativeGoods() {
  164. console.log('negativeGoodsTextarea', negativeGoodsTextarea.value)
  165. loading.value = true
  166. setNegativeTableData(negativeGoodsTextarea.value)
  167. .then(() => {
  168. addedNegetiveTableData.value = [...addedNegetiveTableData.value, ...inputAddedNegGoods.value]
  169. })
  170. .catch((error) => {
  171. console.error('Error fetching data:', error)
  172. })
  173. .finally(() => {
  174. loading.value = false
  175. })
  176. }
  177. function addSingleNegativeGoods(scope) {
  178. const isAlreadyAdded = addedNegetiveTableData.value.some((item) => item.asin === scope.row.asin)
  179. if (!isAlreadyAdded) {
  180. addedNegetiveTableData.value.push(scope.row)
  181. } else {
  182. console.log('Item is already added.')
  183. }
  184. }
  185. function delAllNegativeGoods() {
  186. addedNegetiveTableData.value = []
  187. }
  188. function delSingleNegativeGoods(scope) {
  189. const index = addedNegetiveTableData.value.findIndex((item) => item.asin === scope.row.asin)
  190. if (index !== -1) {
  191. addedNegetiveTableData.value.splice(index, 1)
  192. console.log('Item removed successfully.')
  193. } else {
  194. console.log('Item not found.')
  195. }
  196. }
  197. function searchNegativeGoods(e) {
  198. console.log(e)
  199. if (e === '') {
  200. negativeTableData.value = []
  201. } else {
  202. setNegativeTableData(e)
  203. }
  204. }
  205. function handleAddedNegGoods(selection) {
  206. addedSels = selection
  207. }
  208. async function negativeGoodsSave() {
  209. console.log(addedNegetiveTableData.value)
  210. const asinList = addedNegetiveTableData.value.map((item) => item.asin)
  211. console.log('🚀 ~ negativeGoodsSave ~ asinList-->>', asinList)
  212. negativeGoodsLoading.value = true
  213. console.log('addedNegetiveTableData', addedNegetiveTableData.value)
  214. try {
  215. const requestData = {
  216. profile_id: profile.value.profile_id,
  217. campaignId: respCampaignId.value,
  218. adGroupId: respAdGroupId.value,
  219. asinList: asinList,
  220. matchType: 'ASIN_SAME_AS',
  221. state: 'PAUSED',
  222. }
  223. const filteredRequestData = Object.fromEntries(Object.entries(requestData).filter(([_, v]) => v != null))
  224. const resp = await request({
  225. url: '/api/ad_manage/sptargets/add/negative/targets/',
  226. method: 'POST',
  227. data: filteredRequestData,
  228. })
  229. console.log('🚀 ~ negativeWordsSave ~ resp-->>', resp)
  230. negativeGoodsLoading.value = false
  231. if (resp.data.success.length !== 0) {
  232. ElMessage({
  233. message: '否定商品创建成功',
  234. type: 'success',
  235. })
  236. delAllNegative()
  237. } else {
  238. ElMessage.error('否定商品创建失败!')
  239. }
  240. } catch (error) {
  241. console.error('请求失败:', error)
  242. }
  243. }
  244. function delAllNegative() {
  245. negativeList.length = 0
  246. }
  247. const headerCellStyle = (args) => {
  248. if (args.rowIndex === 0) {
  249. return {
  250. backgroundColor: 'rgba(245, 245, 245, 0.9)',
  251. }
  252. }
  253. }
  254. </script>
  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>