Skip to content

Commit

Permalink
add sku-header-price slot (youzan#705)
Browse files Browse the repository at this point in the history
* [new feature] add sku-header-price slot
  • Loading branch information
w91 authored Mar 16, 2018
1 parent 4c195fd commit f9445ba
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
5 changes: 5 additions & 0 deletions docs/demos/views/sku.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
>
<template slot="sku-header-price" slot-scope="props">
<div class="van-sku__goods-price">
<span class="van-sku__price-symbol">¥</span><span class="van-sku__price-num">{{ props.price }}</span> only!!!
</div>
</template>
<template slot="sku-actions" slot-scope="props">
<div class="van-sku-actions">
<van-button bottom-action @click="onPointClicked">{{ $t('button1') }}</van-button>
Expand Down
7 changes: 7 additions & 0 deletions docs/markdown/en-US/sku.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Vue.use(Sku);
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
>
<!-- custom sku-header-price -->
<template slot="sku-header-price" slot-scope="props">
<div class="van-sku__goods-price">
<span class="van-sku__price-symbol">¥</span><span class="van-sku__price-num">{{ props.price }}</span> only!!!
</div>
</template>
<!-- custom sku actions -->
<template slot="sku-actions" slot-scope="props">
<div class="van-sku-actions">
Expand Down Expand Up @@ -114,6 +120,7 @@ Vue.use(Sku);
| Name | Description |
|-----------|-----------|
| sku-header | Custom header |
| sku-header-price | Custom header price area |
| sku-body-top | Custom content before sku-group |
| sku-group | Custom sku |
| extra-sku-group | Extra custom content |
Expand Down
7 changes: 7 additions & 0 deletions docs/markdown/zh-CN/sku.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Vue.use(Sku);
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
>
<!-- 自定义 sku-header-price -->
<template slot="sku-header-price" slot-scope="props">
<div class="van-sku__goods-price">
<span class="van-sku__price-symbol">¥</span><span class="van-sku__price-num">{{ props.price }}</span> only!!!
</div>
</template>
<!-- 自定义 sku actions -->
<template slot="sku-actions" slot-scope="props">
<div class="van-sku-actions">
Expand Down Expand Up @@ -116,6 +122,7 @@ Sku 组件默认划分好了若干区块,这些区块都定义成了 slot,
| 名称 | 说明 |
|-----------|-----------|
| sku-header | 商品信息展示区,包含商品图片、名称、价格等信息 |
| sku-header-price | 自定义sku头部价格展示 |
| sku-body-top | sku展示区上方的slot,无默认展示内容,按需使用 |
| sku-group | 商品sku展示区 |
| extra-sku-group | 额外商品sku展示区,一般用不到 |
Expand Down
21 changes: 19 additions & 2 deletions packages/sku/Sku.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@
<sku-header
:sku-event-bus="skuEventBus"
:selected-sku="selectedSku"
:selected-sku-comb="selectedSkuComb"
:goods="goods"
:sku="sku"
/>
>
<slot
name="sku-header-price"
:price="price"
:selected-sku-comb="selectedSkuComb"
>
<div class="van-sku__goods-price">
<span class="van-sku__price-symbol">¥</span><span class="van-sku__price-num">{{ price }}</span>
</div>
</slot>
</sku-header>
</slot>
<div class="van-sku-body" :style="bodyStyle">
<!-- sku-body-top -->
Expand Down Expand Up @@ -251,6 +260,14 @@ export default create({
return null;
},
price() {
if (this.selectedSkuComb) {
return (this.selectedSkuComb.price / 100).toFixed(2);
}
// sku.price是一个格式化好的价格区间
return this.sku.price;
},
skuTree() {
return this.sku.tree || [];
}
Expand Down
16 changes: 3 additions & 13 deletions packages/sku/components/SkuHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
</div>
<div class="van-sku-header__goods-info">
<div class="van-sku__goods-name van-ellipsis">{{ goods.title }}</div>
<div class="van-sku__goods-price">
<span class="van-sku__price-symbol">¥</span><span class="van-sku__price-num">{{ price }}</span>
</div>
<!-- price display area -->
<slot />
<icon name="close" class="van-sku__close-icon" @click="skuEventBus.$emit('sku:close')" />
</div>
</div>
Expand All @@ -23,8 +22,7 @@ export default create({
sku: Object,
goods: Object,
skuEventBus: Object,
selectedSku: Object,
selectedSkuComb: Object
selectedSku: Object
},
computed: {
Expand All @@ -33,14 +31,6 @@ export default create({
const skuImg = this.getSkuImg(s1Id);
// 优先使用选中sku的图片
return skuImg || this.goods.picture;
},
price() {
if (this.selectedSkuComb) {
return (this.selectedSkuComb.price / 100).toFixed(2);
}
// sku.price是一个格式化好的价格区间
return this.sku.price;
}
},
Expand Down

0 comments on commit f9445ba

Please sign in to comment.