feat(Card): Card 组件样式调整添加 price 上方的插槽 (#5134)

This commit is contained in:
Lindy
2019-11-29 14:29:42 +08:00
committed by neverland
parent a7ae694dbb
commit abbee1062b
8 changed files with 97 additions and 27 deletions
+20 -5
View File
@@ -32,6 +32,7 @@ export type CardSlots = DefaultSlots & {
bottom?: ScopedSlot;
footer?: ScopedSlot;
'origin-price'?: ScopedSlot;
'price-top'?: ScopedSlot;
};
export type CardEvents = {
@@ -114,11 +115,22 @@ function Card(
}
}
function PriceContent() {
const priceArr = props.price!.toString().split('.');
return (
<div>
{props.currency}
<span class={bem('price', 'integer')}>{priceArr[0]}</span>.
{priceArr[1]}
</div>
);
}
function Price() {
if (showPrice) {
return (
<div class={bem('price')}>
{slots.price ? slots.price() : `${props.currency} ${props.price}`}
{slots.price ? slots.price() : PriceContent()}
</div>
);
}
@@ -137,7 +149,7 @@ function Card(
function Num() {
if (showNum) {
return <div class={bem('num')}>{slots.num ? slots.num() : `x ${props.num}`}</div>;
return <div class={bem('num')}>{slots.num ? slots.num() : `x${props.num}`}</div>;
}
}
@@ -152,11 +164,14 @@ function Card(
<div class={bem('header')}>
{Thumb()}
<div class={bem('content', { centered: props.centered })}>
{Title()}
{Desc()}
{slots.tags && slots.tags()}
<div>
{Title()}
{Desc()}
{slots.tags && slots.tags()}
</div>
{showBottom && (
<div class="van-card__bottom">
{slots['price-top'] && slots['price-top']()}
{Price()}
{OriginPrice()}
{Num()}