Brak opisu

index.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var _rollupPluginBabelHelpers = require('../_rollupPluginBabelHelpers-3469b70d.js');
  5. var React = require('react');
  6. var React__default = _interopDefault(React);
  7. require('../_commonjsHelpers-72d386ba.js');
  8. var index = require('../index-44e17595.js');
  9. var styleInject_es = require('../style-inject.es-dcee06b6.js');
  10. var antd = require('antd');
  11. var css = ".PriceOptions_options__J-ZSS {\n border-bottom: 1px dashed #00000017;\n}\n.PriceOptions_options__J-ZSS p {\n font-size: 14px;\n font-weight: 400;\n color: #616a79;\n margin-bottom: 20px;\n}\n.PriceOptions_options__J-ZSS .PriceOptions_infoItem__3IL3a {\n padding-right: 0;\n}\n.PriceOptions_options__J-ZSS .PriceOptions_infoItem__3IL3a .PriceOptions_priceItem__rJ9o2 {\n background: rgba(243, 243, 243, 0.14);\n border-radius: 4px;\n border: 1px solid #cfcfcf;\n font-size: 14px;\n font-weight: 600;\n color: #616a79;\n display: inline-block;\n text-align: center;\n vertical-align: top;\n height: 30px;\n width: 70px;\n line-height: 30px;\n cursor: pointer;\n margin: 6px;\n}\n.PriceOptions_options__J-ZSS .PriceOptions_infoItem__3IL3a .PriceOptions_priceItem__rJ9o2.PriceOptions_active__3WyAU {\n background: rgba(255, 50, 102, 0.1);\n border-radius: 4px;\n border: 1px solid #ff3266;\n color: #616a79;\n}\n.PriceOptions_options__J-ZSS .PriceOptions_infoItem__3IL3a .PriceOptions_priceInput__1MrVy {\n display: inline-block;\n min-width: 70px;\n width: auto;\n margin: 6px;\n text-align: center;\n}\n.PriceOptions_options__J-ZSS .PriceOptions_infoItem__3IL3a button {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n height: 30px;\n width: 50px;\n vertical-align: top;\n padding: 0 5px;\n}\n.PriceOptions_options__J-ZSS .PriceOptions_infoItem__3IL3a .PriceOptions_rate__QgHQ3 {\n margin-left: 10px;\n}\n.PriceOptions_options__J-ZSS .PriceOptions_infoItem__3IL3a .PriceOptions_rate__QgHQ3 i {\n margin-right: 5px;\n color: #1790FF;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_small__2-wzl {\n padding: 0 0 12px 0;\n border-bottom: none;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_small__2-wzl p {\n margin-bottom: 8px;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_small__2-wzl .PriceOptions_infoItem__3IL3a {\n text-align: center;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_small__2-wzl .PriceOptions_infoItem__3IL3a .PriceOptions_priceItem__rJ9o2 {\n border-radius: 6px;\n height: 32px;\n width: 72px;\n margin: 0 0 12px 19px;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_small__2-wzl .PriceOptions_infoItem__3IL3a .PriceOptions_priceItem__rJ9o2:first-child {\n margin: 0 0 12px 0px;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_small__2-wzl .PriceOptions_infoItem__3IL3a .PriceOptions_priceInput__1MrVy {\n display: block;\n width: 254px;\n border-radius: 6px;\n height: 32px;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_multi__N_Xc4 {\n padding: 20px 20px;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_multi__N_Xc4 p {\n font-size: 14px;\n font-weight: 400;\n color: #616a79;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_multi__N_Xc4 .PriceOptions_infoItem__3IL3a {\n padding-right: 0;\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_multi__N_Xc4 .PriceOptions_infoItem__3IL3a .PriceOptions_priceBtn__Xz4m_ {\n display: flex;\n justify-content: space-between;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_multi__N_Xc4 .PriceOptions_infoItem__3IL3a .PriceOptions_priceItem__rJ9o2 {\n display: inline-block;\n background-color: #fff;\n width: 74px;\n height: 36px;\n line-height: 36px;\n border-radius: 4px;\n border: 1px solid #cfcfcf;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_multi__N_Xc4 .PriceOptions_infoItem__3IL3a .PriceOptions_priceItem__rJ9o2.PriceOptions_active__3WyAU {\n background-color: #fff;\n color: #FF3266FF;\n border-radius: 4px;\n border: 1px solid #ff3266;\n}\n.PriceOptions_options__J-ZSS.PriceOptions_multi__N_Xc4 .PriceOptions_infoItem__3IL3a .PriceOptions_priceInput__1MrVy {\n border-radius: 6px;\n height: 36px;\n width: auto;\n}\n";
  12. var styles = {"options":"PriceOptions_options__J-ZSS","infoItem":"PriceOptions_infoItem__3IL3a","priceItem":"PriceOptions_priceItem__rJ9o2","active":"PriceOptions_active__3WyAU","priceInput":"PriceOptions_priceInput__1MrVy","rate":"PriceOptions_rate__QgHQ3","small":"PriceOptions_small__2-wzl","multi":"PriceOptions_multi__N_Xc4","priceBtn":"PriceOptions_priceBtn__Xz4m_"};
  13. styleInject_es.styleInject(css);
  14. var PriceOptions = function PriceOptions(_ref) {
  15. var price = _ref.price,
  16. onPriceChange = _ref.onPriceChange,
  17. _ref$rowMode = _ref.rowMode,
  18. rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
  19. _ref$size = _ref.size,
  20. _ref$focusScroll = _ref.focusScroll,
  21. focusScroll = _ref$focusScroll === void 0 ? true : _ref$focusScroll,
  22. _ref$withTitle = _ref.withTitle,
  23. withTitle = _ref$withTitle === void 0 ? true : _ref$withTitle,
  24. _ref$titleText = _ref.titleText,
  25. titleText = _ref$titleText === void 0 ? "Price" : _ref$titleText,
  26. _ref$inputPlaceholder = _ref.inputPlaceholderText,
  27. inputPlaceholderText = _ref$inputPlaceholder === void 0 ? "Others" : _ref$inputPlaceholder,
  28. _ref$priceOptions = _ref.priceOptions,
  29. priceOptions = _ref$priceOptions === void 0 ? [100, 600, 800] : _ref$priceOptions,
  30. _ref$priceRender = _ref.priceRender,
  31. priceRender = _ref$priceRender === void 0 ? function (i) {
  32. return i / 100;
  33. } : _ref$priceRender,
  34. _ref$inputPriceRender = _ref.inputPriceRender,
  35. inputPriceRender = _ref$inputPriceRender === void 0 ? function (i) {
  36. return i ? i / 100 : "";
  37. } : _ref$inputPriceRender,
  38. _ref$inputSuffix = _ref.inputSuffix,
  39. inputSuffix = _ref$inputSuffix === void 0 ? "¥" : _ref$inputSuffix,
  40. _ref$injectOptions = _ref.injectOptions,
  41. injectOptions = _ref$injectOptions === void 0 ? {
  42. priceBtnClass: {},
  43. priceInputClass: {}
  44. } : _ref$injectOptions,
  45. inputRef = _ref.inputRef;
  46. var defaultOptions = priceOptions; // 控制是否为其他金额输入情况
  47. var _useState = React.useState(false),
  48. _useState2 = _rollupPluginBabelHelpers._slicedToArray(_useState, 2),
  49. inputStatus = _useState2[0],
  50. setInputStatus = _useState2[1];
  51. var _useState3 = React.useState(''),
  52. _useState4 = _rollupPluginBabelHelpers._slicedToArray(_useState3, 2),
  53. inputPrice = _useState4[0],
  54. setInputPrice = _useState4[1];
  55. return React__default.createElement("div", {
  56. className: index.classnames(styles.options, _rollupPluginBabelHelpers._defineProperty({}, styles.multi, rowMode === "multi"))
  57. }, withTitle ? titleText || null : null, React__default.createElement("div", {
  58. className: styles.infoItem
  59. }, React__default.createElement("span", {
  60. className: styles.priceBtn
  61. }, defaultOptions.map(function (item) {
  62. var _objectSpread2;
  63. return React__default.createElement("span", {
  64. className: index.classnames(_rollupPluginBabelHelpers._objectSpread2((_objectSpread2 = {}, _rollupPluginBabelHelpers._defineProperty(_objectSpread2, styles.priceItem, true), _rollupPluginBabelHelpers._defineProperty(_objectSpread2, styles.active, price === item && !inputStatus), _objectSpread2), injectOptions.priceBtnClass)),
  65. key: item,
  66. onClick: function onClick() {
  67. onPriceChange(item);
  68. setInputStatus(false);
  69. }
  70. }, priceRender(item));
  71. })), React__default.createElement(antd.Input, {
  72. ref: inputRef,
  73. className: index.classnames(styles.priceInput, _rollupPluginBabelHelpers._objectSpread2({}, injectOptions.priceInputClass)),
  74. onMouseEnter: function onMouseEnter() {
  75. if (inputStatus && inputRef && inputRef.current) {
  76. inputRef.current.focus();
  77. inputRef.current.select();
  78. }
  79. },
  80. suffix: inputSuffix,
  81. value: inputStatus ? inputPriceRender(inputPrice) : "",
  82. placeholder: inputPlaceholderText,
  83. onChange: function onChange(e) {
  84. var n = +e.target.value;
  85. if (Number.isNaN(n)) {
  86. return;
  87. } // 测试暂时改成1分
  88. setInputPrice("".concat(n * 100));
  89. onPriceChange(n * 100);
  90. },
  91. onClick: function onClick(e) {
  92. if (!inputStatus) {
  93. setInputPrice('');
  94. setInputStatus(true);
  95. }
  96. },
  97. onFocus: function onFocus(e) {
  98. e.target.placeholder = "";
  99. if (inputStatus) {
  100. setInputPrice("".concat(price));
  101. } else {
  102. setInputPrice('');
  103. setInputStatus(true);
  104. }
  105. if (focusScroll) {
  106. e.target.scrollIntoView();
  107. }
  108. },
  109. onBlur: function onBlur(e) {
  110. e.target.placeholder = inputPlaceholderText;
  111. if (inputPrice) {
  112. setInputStatus(true);
  113. } else {
  114. setInputStatus(false);
  115. }
  116. }
  117. })));
  118. };
  119. exports.default = PriceOptions;
  120. //# sourceMappingURL=index.js.map