SkuActions.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { use } from '../../utils';
  2. import { inherit } from '../../utils/functional';
  3. import Button from '../../button';
  4. // Types
  5. import Vue, { CreateElement, RenderContext } from 'vue/types';
  6. import { DefaultSlots } from '../../utils/use/sfc';
  7. export type SkuActionsProps = {
  8. buyText?: string;
  9. skuEventBus: Vue;
  10. showAddCartBtn?: boolean;
  11. };
  12. const [sfc, bem] = use('sku-actions');
  13. function SkuActions(
  14. h: CreateElement,
  15. props: SkuActionsProps,
  16. slots: DefaultSlots,
  17. ctx: RenderContext<SkuActionsProps>
  18. ) {
  19. const emit = (name: string) => () => {
  20. props.skuEventBus.$emit(name);
  21. };
  22. return (
  23. <div class={bem()} {...inherit(ctx)}>
  24. {props.showAddCartBtn && (
  25. <Button bottomAction text="加入购物车" onClick={emit('sku:addCart')} />
  26. )}
  27. <Button
  28. type="primary"
  29. bottomAction
  30. text={props.buyText || '立即购买'}
  31. onClick={emit('sku:buy')}
  32. />
  33. </div>
  34. );
  35. }
  36. SkuActions.props = {
  37. buyText: String,
  38. skuEventBus: Object,
  39. showAddCartBtn: Boolean
  40. };
  41. export default sfc<SkuActionsProps>(SkuActions);