Нема описа

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React, { useState } from "react";
  2. import classnames from "classnames";
  3. import { formatMoney } from "../../Utils/utils";
  4. import styles from "./PriceOptions.less";
  5. const FormattedMessage = ({ id }: any) => id;
  6. interface Props {
  7. price: number;
  8. onPriceChange: (v: number) => void;
  9. size: "small" | "normal" | "large";
  10. focusScroll: boolean;
  11. withTitle: boolean;
  12. inputRef: React.RefObject<any>;
  13. }
  14. const PriceOptions = ({
  15. price,
  16. onPriceChange,
  17. size = "normal",
  18. focusScroll = true,
  19. withTitle = true,
  20. inputRef
  21. }: Props) => {
  22. const defaultOptions = [100, 600, 800];
  23. // 控制是否为其他金额输入情况
  24. const [inputStatus, setInputStatus] = useState(false);
  25. return (
  26. <div
  27. className={classnames(styles.options)}
  28. >
  29. {withTitle ? (
  30. <p>
  31. <FormattedMessage id="pay.price.select.text" />
  32. </p>
  33. ) : null}
  34. <div className={styles.infoItem} style={{ marginBottom: "-12px" }}>
  35. <span className={styles.priceBtn}>
  36. {defaultOptions.map(item => (
  37. <span
  38. className={classnames({
  39. [styles.priceItem]: true,
  40. [styles.active]: price === item && !inputStatus
  41. })}
  42. key={item}
  43. onClick={() => {
  44. onPriceChange(item);
  45. setInputStatus(false);
  46. }}
  47. >
  48. <FormattedMessage id={`${formatMoney(item/100, 0)}¥`} />
  49. </span>
  50. ))}
  51. </span>
  52. {/* <Input
  53. ref={inputRef}
  54. onMouseEnter={() => {
  55. if (inputStatus && inputRef && inputRef.current) {
  56. inputRef.current.focus();
  57. inputRef.current.select();
  58. }
  59. }}
  60. suffix="¥"
  61. className={styles.priceInput}
  62. value={inputStatus ? price / 100 || "" : ""}
  63. placeholder="Others"
  64. onChange={e => {
  65. const n = +e.target.value;
  66. if (Number.isNaN(n)) {
  67. return;
  68. }
  69. // 测试暂时改成1分
  70. onPriceChange(n * 100);
  71. }}
  72. onClick={e => {
  73. onPriceChange(0);
  74. setInputStatus(true);
  75. }}
  76. onFocus={e => {
  77. if (focusScroll) {
  78. e.target.scrollIntoView();
  79. }
  80. }}
  81. /> */}
  82. </div>
  83. </div>
  84. );
  85. };
  86. export default PriceOptions;