zhengyiming
昨天 1d472eb06970c85b0edfb58871956bc2c8d69916
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
  <nut-sku
    v-model:visible="visible"
    :sku="sku"
    :goods="goods"
    @selectSku="selectSku"
    class="pro-sku"
  >
    <template #sku-header-price>
      <div class="pro-sku-header">
        <div class="pro-sku-header-title">{{ goods.name }}</div>
        <div class="pro-sku-header-spec">{{ currentSpecName }}</div>
        <nut-price :price="goods.price" size="large" />
      </div>
    </template>
    <template #sku-header-extra>
      <div></div>
    </template>
  </nut-sku>
</template>
 
<script setup lang="ts">
import { toThousand } from '@12333/utils';
import { Goods, SkuItem, SkuUtils } from './sku';
import { computed } from 'vue';
 
defineOptions({
  name: 'Sku',
});
 
type Props = {
  sku: SkuItem[];
};
 
const props = withDefaults(defineProps<Props>(), {});
 
const visible = defineModel<boolean>('visible');
const goods = defineModel<Goods>('goods');
 
const selectSku = (ss) => {
  const { sku, skuIndex, parentSku, parentIndex } = ss;
  console.log('sku: ', sku);
  if (sku.disable) return false;
  props.sku[parentIndex].list.forEach((s) => {
    s.active = s.id == sku.id;
  });
  goods.value = {
    ...goods.value,
    skuId: sku.id,
    price: sku.price,
  };
};
 
const currentSpecName = computed(() => {
  const spec = SkuUtils.getCurrentActiveSpec(props.sku);
  if (spec) {
    return spec.name ?? '';
  }
  return '';
});
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.pro-sku {
  .pro-sku-header {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
 
    .pro-sku-header-title {
      color: boleGetCssVar('text-color', 'primary');
    }
 
    .pro-sku-header-spec {
      color: boleGetCssVar('text-color', 'secondary');
      font-size: 26px;
    }
  }
 
  .nut-sku-content {
    width: 100%;
    box-sizing: border-box;
  }
}
</style>