ShowSkuDrawer.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: ShowSkuDrawer.vue
  4. * @Description: SKU详情抽屉
  5. * @Author: xinyan
  6. */
  7. import * as api from '../api';
  8. import { useResponse } from '/@/utils/useResponse';
  9. import { ElMessage } from 'element-plus';
  10. import XEUtils from 'xe-utils';
  11. const showSkuDrawer = <Ref>useTemplateRef('showSkuDrawer');
  12. const showOpen = defineModel({ default: false });
  13. const props = defineProps({
  14. skuData: Object,
  15. rowData: Object,
  16. });
  17. const { skuData, rowData } = props;
  18. const attrList = ref({});
  19. const powerType = ref([]);
  20. async function initPower() {
  21. const resp = await useResponse(api.getSkuDetailByPower, { key: 'power' });
  22. if (!resp || resp.data.total === 0) {
  23. ElMessage({
  24. type: 'warning',
  25. message: '警告:未找到产品属性:power(电源规格)!请在产品属性中定义标识为power的电源规格属性!',
  26. });
  27. }
  28. const items = resp.data[0].attr_dict;
  29. items.unshift({
  30. label: '无',
  31. value: '',
  32. });
  33. powerType.value = items;
  34. }
  35. async function initData() {
  36. const ret = await useResponse(api.getSkuDetailByKind, rowData.kind.id);
  37. const info = XEUtils.groupBy(ret.data.RelatedAttrs, 'section');
  38. const sortedKey = XEUtils.sortBy(Object.keys(info), (key) => key);
  39. const relatedAttrs = []; // 用于存放解析后的 info
  40. for (const section of sortedKey) {
  41. const attrItems = XEUtils.sortBy(info[section], 'order');
  42. let selectedIds = [];
  43. if (skuData) {
  44. selectedIds = skuData[`section${section}`] || []; // 获取对应 section 的选中 ID
  45. }
  46. const tmpAttrs = [];
  47. for (const item of attrItems) {
  48. const v = item.attr_dict.find((dict) => selectedIds.includes(dict.id));
  49. if (v) {
  50. tmpAttrs.push({
  51. label: item.attr.name,
  52. value: v.label,
  53. description: item.description,
  54. });
  55. }
  56. }
  57. relatedAttrs.push({
  58. section: '第' + section + '部分',
  59. attrItems: tmpAttrs,
  60. });
  61. }
  62. if (skuData.optional) {
  63. const optionalAttrs = [];
  64. const value = skuData.optional.powerType;
  65. const matchedLabel = powerType.value.find((item) => item.value === value)?.label;
  66. optionalAttrs.push({
  67. label: '电源',
  68. value: matchedLabel,
  69. });
  70. const key = skuData.optional.version;
  71. const type = skuData.optional.versionType;
  72. optionalAttrs.push({
  73. label: '版本', // 属性名
  74. value: type == null ? '无' : `${type}${key}`,
  75. });
  76. optionalAttrs.push({
  77. label: '版本特征', // 属性名
  78. value: rowData.version_feature === '' ? '无' : rowData.version_feature, // 属性值
  79. });
  80. if (optionalAttrs.length > 0) {
  81. relatedAttrs.push({
  82. section: '可选部分',
  83. attrItems: optionalAttrs,
  84. });
  85. console.log('=>(ShowSkuDrawer.vue:100) optionalAttrs', optionalAttrs);
  86. }
  87. }
  88. attrList.value = relatedAttrs;
  89. }
  90. onMounted(() => {
  91. initPower();
  92. initData();
  93. });
  94. </script>
  95. <template>
  96. <div class="drawer-container">
  97. <el-drawer ref="showSkuDrawer" v-model="showOpen" style="width: 40%">
  98. <template #title>
  99. <div>
  100. <span style="font-size: 16px; font-weight: bold">当前SKU:</span>
  101. <!--<el-tag style="margin-left: 5px" type="primary">-->
  102. <!-- {{ rowData.sku }}-->
  103. <!--</el-tag>-->
  104. <el-check-tag checked style="margin-left: 5px">{{ rowData.sku }}</el-check-tag>
  105. </div>
  106. </template>
  107. <div class="m-4">
  108. <el-descriptions v-for="info of attrList" :title="info.section" border style="margin-bottom: 40px">
  109. <el-descriptions-item v-for="attr of info.attrItems" label-class-name="my-label">
  110. <template #label>
  111. <div style="white-space: nowrap">{{ attr.label }}</div>
  112. <el-tooltip v-if="Boolean(attr.description)" :content="attr.description" effect="dark" placement="top-start">
  113. <i class="el-icon-question"></i>
  114. </el-tooltip>
  115. </template>
  116. <div :style="{ whiteSpace: attr.label !== '版本特征' ? 'nowrap' : 'normal' }" class="my-value">{{ attr.value }}</div>
  117. </el-descriptions-item>
  118. </el-descriptions>
  119. </div>
  120. </el-drawer>
  121. </div>
  122. </template>
  123. <style scoped>
  124. .drawer-container :deep(.el-drawer__header) {
  125. border-bottom: none;
  126. /* font-weight: 500; */
  127. }
  128. :deep(.my-label) {
  129. background: #f5f5f5 !important;
  130. }
  131. .my-value {
  132. font-weight: 500;
  133. font-size: 13px;
  134. }
  135. </style>