index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  2. // Utils
  3. import { createNamespace } from '../utils';
  4. import { emit, inherit } from '../utils/functional'; // Components
  5. import Icon from '../icon';
  6. import Button from '../button'; // Types
  7. var _createNamespace = createNamespace('submit-bar'),
  8. createComponent = _createNamespace[0],
  9. bem = _createNamespace[1],
  10. t = _createNamespace[2];
  11. function SubmitBar(h, props, slots, ctx) {
  12. var tip = props.tip,
  13. price = props.price,
  14. tipIcon = props.tipIcon;
  15. function Text() {
  16. if (typeof price === 'number') {
  17. var priceArr = (price / 100).toFixed(props.decimalLength).split('.');
  18. var decimalStr = props.decimalLength ? "." + priceArr[1] : '';
  19. return h("div", {
  20. "style": {
  21. textAlign: props.textAlign ? props.textAlign : ''
  22. },
  23. "class": bem('text')
  24. }, [h("span", [props.label || t('label')]), h("span", {
  25. "class": bem('price')
  26. }, [props.currency, h("span", {
  27. "class": bem('price', 'integer')
  28. }, [priceArr[0]]), decimalStr]), props.suffixLabel && h("span", {
  29. "class": bem('suffix-label')
  30. }, [props.suffixLabel])]);
  31. }
  32. }
  33. function Tip() {
  34. if (slots.tip || tip) {
  35. return h("div", {
  36. "class": bem('tip')
  37. }, [tipIcon && h(Icon, {
  38. "class": bem('tip-icon'),
  39. "attrs": {
  40. "name": tipIcon
  41. }
  42. }), tip && h("span", {
  43. "class": bem('tip-text')
  44. }, [tip]), slots.tip && slots.tip()]);
  45. }
  46. }
  47. return h("div", _mergeJSXProps([{
  48. "class": bem({
  49. unfit: !props.safeAreaInsetBottom
  50. })
  51. }, inherit(ctx)]), [slots.top && slots.top(), Tip(), h("div", {
  52. "class": bem('bar')
  53. }, [slots.default && slots.default(), Text(), slots.button ? slots.button() : h(Button, {
  54. "attrs": {
  55. "round": true,
  56. "type": props.buttonType,
  57. "text": props.loading ? '' : props.buttonText,
  58. "color": props.buttonColor,
  59. "loading": props.loading,
  60. "disabled": props.disabled
  61. },
  62. "class": bem('button', props.buttonType),
  63. "on": {
  64. "click": function click() {
  65. emit(ctx, 'submit');
  66. }
  67. }
  68. })])]);
  69. }
  70. SubmitBar.props = {
  71. tip: String,
  72. label: String,
  73. price: Number,
  74. tipIcon: String,
  75. loading: Boolean,
  76. disabled: Boolean,
  77. textAlign: String,
  78. buttonText: String,
  79. buttonColor: String,
  80. suffixLabel: String,
  81. safeAreaInsetBottom: {
  82. type: Boolean,
  83. default: true
  84. },
  85. decimalLength: {
  86. type: [Number, String],
  87. default: 2
  88. },
  89. currency: {
  90. type: String,
  91. default: '¥'
  92. },
  93. buttonType: {
  94. type: String,
  95. default: 'danger'
  96. }
  97. };
  98. export default createComponent(SubmitBar);