SingleSearch.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div style="height: 525px" v-loading="containerLoading">
  3. <el-input v-model="searchInput" @change="handleChange" placeholder="按ASIN搜索"></el-input>
  4. <hr style="margin-top: 5px" />
  5. <el-table :data="commodityData" :show-header="false" @selection-change="handleSelectionChange" height="450" style="width: 100%">
  6. <el-table-column prop="date" label="商品">
  7. <template #default="scope">
  8. <div style="display: flex; align-items: center">
  9. <div style="margin-right: 8px; line-height: normal">
  10. <el-image class="img-box" :src="scope.row.image_link" />
  11. </div>
  12. <div>
  13. <el-tooltip class="box-item" effect="dark" :content="scope.row.title" placement="top">
  14. <div class="double-line">{{ scope.row.title ? scope.row.title : '--' }}</div>
  15. </el-tooltip>
  16. <span
  17. >ASIN:
  18. <span class="data-color" style="margin-right: 8px">{{ scope.row.asin ? scope.row.asin : '--' }}</span>
  19. </span>
  20. </div>
  21. </div>
  22. </template>
  23. </el-table-column>
  24. <el-table-column prop="name" label="Name" width="80">
  25. <template #default="scope"> </template>
  26. </el-table-column>
  27. <el-table-column type="selection" width="55" />
  28. </el-table>
  29. </div>
  30. </template>
  31. <script setup lang="ts">
  32. import { storeToRefs } from 'pinia'
  33. import { defineEmits, ref } from 'vue'
  34. import { getCommodityCard } from '../api/index'
  35. import { useShopInfo } from '/@/stores/shopInfo'
  36. const shopInfo = useShopInfo()
  37. const { profile } = storeToRefs(shopInfo)
  38. const containerLoading = ref(false)
  39. const searchInput = ref('')
  40. const commodityData: any = ref('')
  41. function handleChange() {
  42. searchAsin()
  43. }
  44. async function searchAsin() {
  45. containerLoading.value = true
  46. try {
  47. const query = {
  48. profile_id: profile.value.profile_id,
  49. asin: searchInput.value,
  50. }
  51. const response = await getCommodityCard(query)
  52. commodityData.value = response.data
  53. } catch (error) {
  54. console.log('error:', error)
  55. } finally {
  56. containerLoading.value = false
  57. }
  58. }
  59. // 暴露数据给父组件
  60. const emit = defineEmits(['updateSelected'])
  61. function handleSelectionChange(selection) {
  62. // selection 是所有被选中的行数据
  63. emit('updateSelected', selection)
  64. }
  65. </script>
  66. <style scoped>
  67. .custom-tree-node {
  68. /* el-tree自定义样式 */
  69. flex: 1;
  70. display: flex;
  71. align-items: center;
  72. justify-content: space-between;
  73. font-size: 14px;
  74. padding-right: 8px;
  75. }
  76. .double-line {
  77. color: #1e2128;
  78. font-weight: 500;
  79. overflow: hidden;
  80. display: -webkit-box;
  81. -webkit-box-orient: vertical;
  82. -webkit-line-clamp: 2;
  83. white-space: pre-wrap;
  84. word-break: break-word;
  85. }
  86. .data-color {
  87. color: rgb(30, 33, 41);
  88. }
  89. .img-box {
  90. width: 60px;
  91. height: 60px;
  92. margin-top: 5px;
  93. border: 1px solid rgb(194, 199, 207);
  94. border-radius: 4px;
  95. }
  96. </style>