DataTableSlot.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: DataTableSlot.vue
  4. * @Description: 商品监控-表格插槽
  5. * @Author: Cheney
  6. */
  7. import { useCountryInfoStore } from '/@/stores/countryInfo';
  8. import { Delete, InfoFilled, Operation } from '@element-plus/icons-vue';
  9. import { getTagType } from '/@/utils/useTagColor';
  10. import PermissionButton from '/@/components/PermissionButton/index.vue';
  11. import ProductInfo from '/@/views/product-manage/product-list/component/ProductInfo.vue';
  12. import ProgressBar from '/@/views/product-manage/product-monitor/component/ProgressBar.vue';
  13. const props = defineProps<{
  14. row: any,
  15. field: any
  16. }>();
  17. const { row, field } = props;
  18. const emit = defineEmits([ 'edit-row', 'handle-delete' ]);
  19. const countryInfoStore = useCountryInfoStore();
  20. const country = countryInfoStore.countries.find(c => c.code == row.country_code);
  21. const color = country ? country.color : '#3875F6';
  22. const statusText = row.status === 1 ? '在售' : '停售';
  23. const statusType = row.status === 1 ? 'success' : 'info';
  24. function handleEdit() {
  25. emit('edit-row', row);
  26. }
  27. function onConfirm() {
  28. emit('handle-delete', row);
  29. }
  30. </script>
  31. <template>
  32. <div class="font-medium">
  33. <div v-if="field === 'product_info'">
  34. <ProductInfo :img-width="50" :item="row.goods" />
  35. </div>
  36. <div v-else-if="field === 'country_code'">
  37. <el-tag :disable-transitions="true" :style="{ color: color, borderColor: color }" effect="plain" round>
  38. {{ country ? country.name : '-' }}
  39. </el-tag>
  40. </div>
  41. <div v-else-if="field === 'shop_name'">
  42. <el-tag v-if="row.goods.shop_name" :disable-transitions="true" :type=getTagType(row.shop_name)>
  43. {{ row.shop_name }}
  44. </el-tag>
  45. <div v-else>-</div>
  46. </div>
  47. <div v-else-if="field === 'tag'">
  48. <el-tag v-if="row.goods.tag" :disable-transitions="true" :type=getTagType(row.goods.tag)>
  49. {{ row.goods.tag }}
  50. </el-tag>
  51. <div v-else>-</div>
  52. </div>
  53. <div v-else-if="field === 'brand'">
  54. <el-tag v-if="row.goods.brand" :disable-transitions="true" :type=getTagType(row.goods.brand) effect="plain" round>
  55. {{ row.goods.brand }}
  56. </el-tag>
  57. <div v-else>-</div>
  58. </div>
  59. <div v-else-if="field === 'price_info'">
  60. <div v-if="row.goods.price > 0" class="font-medium">
  61. <p>现 价:{{ row.goods.currency_code + '‎' + row.goods.price }}</p>
  62. <p>折 扣:{{ row.goods.discount > 0 ? row.goods.discount + '%' : '-' }}</p>
  63. <p>优惠劵:{{ !row || row.goods.coupon <= 0 ? '-' : row.goods.currency_code + '‎' + row.goods.coupon }}</p>
  64. </div>
  65. </div>
  66. <div v-else-if="field === 'show_price'">
  67. <div class="font-medium">
  68. {{ row.goods.show_price ? row.goods.currency_code + row.goods.show_price : '-' }}
  69. </div>
  70. </div>
  71. <div v-else-if="field === 'activity_price'">
  72. <div class="font-medium">
  73. {{ row.goods.activity_price ? row.goods.currency_code + row.goods.activity_price : '-' }}
  74. </div>
  75. </div>
  76. <div v-else-if="field === 'minimum_price'">
  77. <div class="font-medium">
  78. {{ row.goods.minimum_price ? row.goods.currency_code + row.goods.minimum_price : '-' }}
  79. </div>
  80. </div>
  81. <div v-else-if="field === 'score'">
  82. <template v-if="row.goods.score !== null && row.goods.score !== undefined && row.goods.score !== ''">
  83. <el-rate
  84. v-if="row.goods.score > 0"
  85. v-model="row.goods.score"
  86. :colors="['#FF0000', '#FF9900', '#67C23A']"
  87. disabled
  88. show-score
  89. text-color="#1e293b"
  90. />
  91. <span v-else>{{ row.goods.score }}</span> <!-- 值为0时显示0 -->
  92. </template>
  93. <template v-else>
  94. <span>-</span> <!-- 无值时显示'--' -->
  95. </template>
  96. </div>
  97. <div v-else-if="field === 'all_score'">
  98. <template v-if="row.goods.all_score !== null && row.goods.all_score !== undefined && row.goods.all_score !== ''">
  99. <el-rate
  100. v-if="row.goods.all_score > 0"
  101. v-model="row.goods.all_score"
  102. :colors="['#FF0000', '#FF9900', '#67C23A']"
  103. disabled
  104. show-score
  105. text-color="#1e293b"
  106. />
  107. <span v-else>{{ row.goods.all_score }}</span>
  108. </template>
  109. <template v-else>
  110. <span>-</span>
  111. </template>
  112. </div>
  113. <div v-else-if="field === 'stars'" class="flex flex-col font-normal" style="min-width: 170px">
  114. <ProgressBar :row="row" percentage="ratings" />
  115. </div>
  116. <div v-else-if="field === 'all_stars'" class="flex flex-col font-normal" style="min-width: 170px">
  117. <ProgressBar :row="row" percentage="all_rate" />
  118. </div>
  119. <div v-else-if="field === 'status'">
  120. <el-tag :disable-transitions="true" :type=statusType>
  121. {{ statusText }}
  122. </el-tag>
  123. </div>
  124. <div v-else-if="field === 'operate'">
  125. <div class="flex justify-center gap-2">
  126. <PermissionButton circle plain type="warning" @click="handleEdit">
  127. <el-icon>
  128. <Operation />
  129. </el-icon>
  130. </PermissionButton>
  131. <el-popconfirm
  132. :icon="InfoFilled"
  133. icon-color="#626AEF"
  134. title="你确定要删除此项吗?"
  135. width="220"
  136. @confirm="onConfirm"
  137. >
  138. <template #reference>
  139. <PermissionButton circle plain type="danger">
  140. <el-icon>
  141. <Delete />
  142. </el-icon>
  143. </PermissionButton>
  144. </template>
  145. <template #actions="{ confirm, cancel }">
  146. <el-button size="small" @click="cancel">No!</el-button>
  147. <el-button
  148. size="small"
  149. type="danger"
  150. @click="confirm"
  151. >
  152. Yes?
  153. </el-button>
  154. </template>
  155. </el-popconfirm>
  156. </div>
  157. </div>
  158. <div v-else>
  159. {{ row.goods[field] }}
  160. </div>
  161. </div>
  162. </template>
  163. <style scoped>
  164. :deep(.flex-1 .el-progress__text) {
  165. font-size: 14px !important;
  166. }
  167. </style>