SubmitBar.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. default: () => stdin_default,
  21. submitBarProps: () => submitBarProps
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_icon = require("../icon");
  28. var import_button = require("../button");
  29. var import_use_placeholder = require("../composables/use-placeholder");
  30. const [name, bem, t] = (0, import_utils.createNamespace)("submit-bar");
  31. const submitBarProps = {
  32. tip: String,
  33. label: String,
  34. price: Number,
  35. tipIcon: String,
  36. loading: Boolean,
  37. currency: (0, import_utils.makeStringProp)("\xA5"),
  38. disabled: Boolean,
  39. textAlign: String,
  40. buttonText: String,
  41. buttonType: (0, import_utils.makeStringProp)("danger"),
  42. buttonColor: String,
  43. suffixLabel: String,
  44. placeholder: Boolean,
  45. decimalLength: (0, import_utils.makeNumericProp)(2),
  46. safeAreaInsetBottom: import_utils.truthProp
  47. };
  48. var stdin_default = (0, import_vue2.defineComponent)({
  49. name,
  50. props: submitBarProps,
  51. emits: ["submit"],
  52. setup(props, {
  53. emit,
  54. slots
  55. }) {
  56. const root = (0, import_vue2.ref)();
  57. const renderPlaceholder = (0, import_use_placeholder.usePlaceholder)(root, bem);
  58. const renderText = () => {
  59. const {
  60. price,
  61. label,
  62. currency,
  63. textAlign,
  64. suffixLabel,
  65. decimalLength
  66. } = props;
  67. if (typeof price === "number") {
  68. const pricePair = (price / 100).toFixed(+decimalLength).split(".");
  69. const decimal = decimalLength ? `.${pricePair[1]}` : "";
  70. return (0, import_vue.createVNode)("div", {
  71. "class": bem("text"),
  72. "style": {
  73. textAlign
  74. }
  75. }, [(0, import_vue.createVNode)("span", null, [label || t("label")]), (0, import_vue.createVNode)("span", {
  76. "class": bem("price")
  77. }, [currency, (0, import_vue.createVNode)("span", {
  78. "class": bem("price-integer")
  79. }, [pricePair[0]]), decimal]), suffixLabel && (0, import_vue.createVNode)("span", {
  80. "class": bem("suffix-label")
  81. }, [suffixLabel])]);
  82. }
  83. };
  84. const renderTip = () => {
  85. var _a;
  86. const {
  87. tip,
  88. tipIcon
  89. } = props;
  90. if (slots.tip || tip) {
  91. return (0, import_vue.createVNode)("div", {
  92. "class": bem("tip")
  93. }, [tipIcon && (0, import_vue.createVNode)(import_icon.Icon, {
  94. "class": bem("tip-icon"),
  95. "name": tipIcon
  96. }, null), tip && (0, import_vue.createVNode)("span", {
  97. "class": bem("tip-text")
  98. }, [tip]), (_a = slots.tip) == null ? void 0 : _a.call(slots)]);
  99. }
  100. };
  101. const onClickButton = () => emit("submit");
  102. const renderButton = () => {
  103. if (slots.button) {
  104. return slots.button();
  105. }
  106. return (0, import_vue.createVNode)(import_button.Button, {
  107. "round": true,
  108. "type": props.buttonType,
  109. "text": props.buttonText,
  110. "class": bem("button", props.buttonType),
  111. "color": props.buttonColor,
  112. "loading": props.loading,
  113. "disabled": props.disabled,
  114. "onClick": onClickButton
  115. }, null);
  116. };
  117. const renderSubmitBar = () => {
  118. var _a, _b;
  119. return (0, import_vue.createVNode)("div", {
  120. "ref": root,
  121. "class": [bem(), {
  122. "van-safe-area-bottom": props.safeAreaInsetBottom
  123. }]
  124. }, [(_a = slots.top) == null ? void 0 : _a.call(slots), renderTip(), (0, import_vue.createVNode)("div", {
  125. "class": bem("bar")
  126. }, [(_b = slots.default) == null ? void 0 : _b.call(slots), renderText(), renderButton()])]);
  127. };
  128. return () => {
  129. if (props.placeholder) {
  130. return renderPlaceholder(renderSubmitBar);
  131. }
  132. return renderSubmitBar();
  133. };
  134. }
  135. });