import { defineComponent } from 'vue'; // Utils import { createNamespace, isDef } from '../utils'; // Components import { Tag } from '../tag'; import { Image } from '../image'; const [name, bem] = createNamespace('card'); export default defineComponent({ name, props: { tag: String, num: [Number, String], desc: String, thumb: String, title: String, price: [Number, String], centered: Boolean, lazyLoad: Boolean, thumbLink: String, originPrice: [Number, String], currency: { type: String, default: '¥', }, }, emits: ['click-thumb'], setup(props, { slots, emit }) { const renderTitle = () => { if (slots.title) { return slots.title(); } if (props.title) { return (
{props.title}
); } }; const renderThumbTag = () => { if (slots.tag || props.tag) { return (
{slots.tag ? ( slots.tag() ) : ( {props.tag} )}
); } }; const renderThumbImage = () => { if (slots.thumb) { return slots.thumb(); } return ( ); }; const renderThumb = () => { if (slots.thumb || props.thumb) { return ( emit('click-thumb', event)} > {renderThumbImage()} {renderThumbTag()} ); } }; const renderDesc = () => { if (slots.desc) { return slots.desc(); } if (props.desc) { return
{props.desc}
; } }; const renderPriceText = () => { const priceArr = props.price!.toString().split('.'); return (
{props.currency} {priceArr[0]}. {priceArr[1]}
); }; return () => { const showNum = slots.num || isDef(props.num); const showPrice = slots.price || isDef(props.price); const showOriginPrice = slots['origin-price'] || isDef(props.originPrice); const showBottom = showNum || showPrice || showOriginPrice || slots.bottom; const Price = showPrice && (
{slots.price ? slots.price() : renderPriceText()}
); const OriginPrice = showOriginPrice && (
{slots['origin-price'] ? slots['origin-price']() : `${props.currency} ${props.originPrice}`}
); const Num = showNum && (
{slots.num ? slots.num() : `x${props.num}`}
); const Footer = slots.footer && (
{slots.footer()}
); const Bottom = showBottom && (
{slots['price-top']?.()} {Price} {OriginPrice} {Num} {slots.bottom?.()}
); return (
{renderThumb()}
{renderTitle()} {renderDesc()} {slots.tags?.()}
{Bottom}
{Footer}
); }; }, });