vant/packages/sku/components/SkuHeader.vue
neverland 9d8eb14f0a [bugfix] delete unnecessary style in sku (#205)
* [Document] add english document of Checkbox

* [Document] add english document of Field

* [Document] add english document of NumberKeyboard

* [bugfix] NumberKeyboard should not dispaly title when title is empty

* [Document] add english document of PasswordInput

* [Document] add english document of Radio

* [document] add english document of Switch

* [bugfix] remove redundent styles in english document

* [Document] fix details

* fix Switch test cases

* [bugfix] Swipe shouid reinitialize when item changes

* [new feature] ImagePreview reconstruct

* [new feature] add Tabbar component

* [bugfix] delete unnecessary style in sku
2017-10-12 22:14:40 -05:00

67 lines
1.7 KiB
Vue

<template>
<div class="van-sku-header van-hairline--bottom">
<div class="van-sku-header__img-wrap">
<img class="van-sku__goods-img" :src="goodsImg">
</div>
<div class="van-sku-header__goods-info">
<div class="van-sku__goods-name">{{ 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>
<span class="van-sku__close-icon" @click="onCloseClicked"></span>
</div>
</div>
</template>
<script>
export default {
name: 'van-sku-header',
props: {
skuEventBus: Object,
sku: Object,
selectedSku: Object,
selectedSkuComb: Object,
goods: Object
},
computed: {
skuTree() {
return this.sku.tree;
},
goodsImg() {
const s1Id = this.selectedSku.s1;
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;
}
},
methods: {
onCloseClicked() {
this.skuEventBus.$emit('sku:close');
},
getSkuImg(id) {
if (!id) return;
// 目前skuImg都挂载在skuTree中s1那类sku上
const treeItem = this.skuTree.filter(treeItem => treeItem.k_s === 's1')[0] || {};
if (!treeItem.v) {
return;
}
const matchedSku = treeItem.v.filter(skuValue => skuValue.id === id)[0];
if (matchedSku && matchedSku.imgUrl) {
return matchedSku.imgUrl;
}
}
}
};
</script>