1 |
- {"version":3,"file":"index.js","sources":["../../src/components/Payment/PriceOptions/index.tsx"],"sourcesContent":["import React, { useState } from \"react\";\r\nimport classnames from \"classnames\";\r\nimport { Input } from \"antd\";\r\nimport styles from \"./PriceOptions.less\";\r\n\r\ninterface Props {\r\n rowMode: \"single\" | \"multi\";\r\n price: number;\r\n onPriceChange: (v: number) => void;\r\n size: \"small\" | \"normal\" | \"large\";\r\n focusScroll: boolean;\r\n withTitle: boolean;\r\n titleText?: string | JSX.Element[] | JSX.Element;\r\n inputPlaceholderText?: string;\r\n priceOptions?: Array<any>;\r\n priceRender?: Function;\r\n inputPriceRender?: Function;\r\n inputSuffix?: string | JSX.Element[] | JSX.Element;\r\n injectOptions?: {\r\n priceBtnClass: any;\r\n priceInputClass: any;\r\n }\r\n inputRef: React.RefObject<any>;\r\n}\r\n\r\nconst PriceOptions = ({\r\n price,\r\n onPriceChange,\r\n rowMode = \"single\",\r\n size = \"normal\",\r\n focusScroll = true,\r\n withTitle = true,\r\n titleText = \"Price\",\r\n inputPlaceholderText = \"Others\",\r\n priceOptions = [100, 600, 800],\r\n priceRender = (i: any) => i / 100,\r\n inputPriceRender = (i: any) => (i ? i / 100 : \"\"),\r\n inputSuffix = \"¥\",\r\n injectOptions = {\r\n priceBtnClass: {},\r\n priceInputClass: {},\r\n },\r\n inputRef\r\n}: Props) => {\r\n const defaultOptions = priceOptions;\r\n // 控制是否为其他金额输入情况\r\n const [inputStatus, setInputStatus] = useState(false);\r\n const [inputPrice, setInputPrice] = useState('');\r\n\r\n return (\r\n <div className={classnames(styles.options, {\r\n [styles.multi]: rowMode === \"multi\"\r\n })}>\r\n {withTitle ? (titleText || null) : null}\r\n <div className={styles.infoItem}>\r\n <span className={styles.priceBtn}>\r\n {defaultOptions.map(item => (\r\n <span\r\n className={classnames({\r\n [styles.priceItem]: true,\r\n [styles.active]: price === item && !inputStatus,\r\n ...injectOptions.priceBtnClass,\r\n })}\r\n key={item}\r\n onClick={() => {\r\n onPriceChange(item);\r\n setInputStatus(false);\r\n }}\r\n >\r\n {priceRender(item)}\r\n </span>\r\n ))}\r\n </span>\r\n <Input\r\n ref={inputRef}\r\n className={classnames(styles.priceInput, {...injectOptions.priceInputClass})}\r\n onMouseEnter={() => {\r\n if (inputStatus && inputRef && inputRef.current) {\r\n inputRef.current.focus();\r\n inputRef.current.select();\r\n }\r\n }}\r\n suffix={inputSuffix}\r\n value={inputStatus ? inputPriceRender(inputPrice) : \"\"}\r\n placeholder={inputPlaceholderText}\r\n onChange={e => {\r\n const n = +e.target.value;\r\n if (Number.isNaN(n)) {\r\n return;\r\n }\r\n // 测试暂时改成1分\r\n setInputPrice(`${n * 100}`);\r\n onPriceChange(n * 100);\r\n }}\r\n onClick={e => {\r\n if (!inputStatus) {\r\n setInputPrice('');\r\n setInputStatus(true);\r\n }\r\n }}\r\n onFocus={e => {\r\n e.target.placeholder = \"\";\r\n if (inputStatus) {\r\n setInputPrice(`${price}`);\r\n } else {\r\n setInputPrice('');\r\n setInputStatus(true);\r\n }\r\n if (focusScroll) {\r\n e.target.scrollIntoView();\r\n }\r\n }}\r\n onBlur={e => {\r\n e.target.placeholder = inputPlaceholderText;\r\n if (inputPrice) {\r\n setInputStatus(true);\r\n } else {\r\n setInputStatus(false);\r\n }\r\n }}\r\n />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nexport default PriceOptions;\r\n"],"names":["PriceOptions","price","onPriceChange","rowMode","size","focusScroll","withTitle","titleText","inputPlaceholderText","priceOptions","priceRender","i","inputPriceRender","inputSuffix","injectOptions","priceBtnClass","priceInputClass","inputRef","defaultOptions","useState","inputStatus","setInputStatus","inputPrice","setInputPrice","React","createElement","className","classnames","styles","options","multi","infoItem","priceBtn","map","item","priceItem","active","key","onClick","Input","ref","priceInput","onMouseEnter","current","focus","select","suffix","value","placeholder","onChange","e","n","target","Number","isNaN","onFocus","scrollIntoView","onBlur"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAMA,YAAY,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