import React from 'react'; import { View, Text, Image } from '@tarojs/components'; import classNames from 'classnames'; interface PriceProps { /** 积分 */ buyPoint?: number; /** 价格 */ price?: number; /** 划线价 */ linePrice?: number; /** 整数部分样式 */ priceSize?: 'long' | 'large' | 'middle' | 'small' | 'mini' | 'default'; /**小数部分样式 */ decimalSize?: 'long' | 'large' | 'middle' | 'small' | 'mini' | 'default'; /** 加号样式 */ plusSize?: 'large' | 'default'; /** 展示付费会员标签 */ payMemberLabel?: string; } /** * 价格组件 */ const Price: React.FC = ({ buyPoint = 0, price = 0, linePrice = 0, priceSize = 'small', decimalSize = 'default', plusSize = 'default', payMemberLabel = '', }) => { // 积分部分 const renderPointsItem = () => { const buyPointClassnames = classNames( 'text', `wm-price-points-${priceSize}`, ); const buyPointTextClassnames = classNames('text', 'wm-price-points-text'); return ( {buyPoint} 积分 ); }; //积分与价格相加 const renderPlusItem = () => { const plusClassnames = classNames('text', `wm-price-plus-${plusSize}`); return ( + ); }; //价格部分 const renderPriceItem = () => { const priceString = Number(price).toFixed(2); const arr = priceString.split('.'); const priceClassnames = classNames('text', `wm-price-style-${priceSize}`); const decimalClassnames = classNames( 'text', `wm-price-style-${decimalSize}`, ); return ( {arr[0]} .{arr[1]} ); }; //默认宽度为240像素,列表使用134 const classObject = classNames( 'wm-price', plusSize === 'default' && 'wm-price-default', linePrice && 'wm-price-block', ); return ( {buyPoint > 0 && renderPointsItem()} {buyPoint > 0 && price > 0 && renderPlusItem()} {!(buyPoint > 0 && price === 0) && renderPriceItem()} { payMemberLabel !== '' && } {linePrice > 0 && ( ¥{linePrice.toFixed(2)} )} ); }; export default Price;