// Utils import { createNamespace } from '../utils'; import { emit, inherit } from '../utils/functional'; // Components import Icon from '../icon'; import Button, { ButtonType } from '../button'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { ScopedSlot, DefaultSlots } from '../utils/types'; export type SubmitBarProps = { tip?: string; tipIcon?: string; label?: string; price?: number; loading?: boolean; currency: string; disabled?: boolean; buttonType: ButtonType; buttonText?: string; buttonColor?: string; suffixLabel?: string; decimalLength: number; safeAreaInsetBottom?: boolean; textAlign?: 'right' | 'left'; }; export type SubmitBarSlots = DefaultSlots & { top?: ScopedSlot; tip?: ScopedSlot; }; const [createComponent, bem, t] = createNamespace('submit-bar'); function SubmitBar( h: CreateElement, props: SubmitBarProps, slots: SubmitBarSlots, ctx: RenderContext ) { const { tip, price, tipIcon } = props; function Text() { if (typeof price === 'number') { const priceArr = (price / 100).toFixed(props.decimalLength).split('.'); const decimalStr = props.decimalLength ? `.${priceArr[1]}` : ''; return (
{props.label || t('label')} {props.currency} {priceArr[0]} {decimalStr} {props.suffixLabel && ( {props.suffixLabel} )}
); } } function Tip() { if (slots.tip || tip) { return (
{tipIcon && } {tip && {tip}} {slots.tip && slots.tip()}
); } } return (
{slots.top && slots.top()} {Tip()}
{slots.default && slots.default()} {Text()}
); } SubmitBar.props = { tip: String, label: String, price: Number, tipIcon: String, loading: Boolean, disabled: Boolean, textAlign: String, buttonText: String, buttonColor: String, suffixLabel: String, safeAreaInsetBottom: { type: Boolean, default: true, }, decimalLength: { type: [Number, String], default: 2, }, currency: { type: String, default: '¥', }, buttonType: { type: String, default: 'danger', }, }; export default createComponent(SubmitBar);