import { createNamespace } from '../utils'; import Icon from '../icon'; import Button from '../button'; const [createComponent, bem, t] = createNamespace('submit-bar'); export default createComponent({ 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', }, }, emits: ['submit'], setup(props, { emit, slots }) { return () => { 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()}
); }; }, });