Commit bcdaccbf authored by haiyoucuv's avatar haiyoucuv

Enhance DetailPage with input validation for buy and sell amounts, integrate...

Enhance DetailPage with input validation for buy and sell amounts, integrate SellPanel for redemption simulations, and update input fields to accept decimal values.
parent 065be0c3
......@@ -13,6 +13,7 @@ import { _asyncThrottle } from '@/utils/utils';
import hxLink from "hx-product_detail-link";
import { ModalCtrl } from "@/core/ctrls/ModalCtrl.tsx";
import { BuyPanel } from "@/panels/BuyPanel/BuyPanel.tsx";
import { SellPanel } from '@/panels/SellPanel/SellPanel';
enum EOpType {
Buy = "buy",
......@@ -76,6 +77,11 @@ class DetailPage extends React.Component<any, any> {
clickSimulateBuy = _asyncThrottle(async () => {
const { buyInput } = this.state;
if (!buyInput || buyInput.trim() === "") {
Toast.show("请输入买入金额");
return;
}
if (+buyInput * 100 > this.state.availableFunds) {
Toast.show("超出买入上限啦");
return;
......@@ -101,12 +107,17 @@ class DetailPage extends React.Component<any, any> {
clickSimulateSell = _asyncThrottle(async () => {
const { sellInput } = this.state;
if (!sellInput || sellInput.trim() === "") {
Toast.show("请输入赎回份额");
return;
}
if (+sellInput * 100 > this.state.tranche) {
Toast.show("超出赎回上限啦");
return;
}
ModalCtrl.showModal(BuyPanel, {
ModalCtrl.showModal(SellPanel, {
name: this.state.productName,
amount: sellInput,
call: async () => {
......@@ -118,6 +129,17 @@ class DetailPage extends React.Component<any, any> {
});
});
// 新增:输入校验,只允许数字和最多两位小数
handleInputChange = (e: React.ChangeEvent<HTMLInputElement>, key: 'buyInput' | 'sellInput') => {
let value = e.target.value;
// 只允许输入数字和最多两位小数
if (value === '' || /^\d*(\.\d{0,2})?$/.test(value)) {
this.setState({
[key]: value,
});
}
}
render() {
const {
tabType, iframeUrl,
......@@ -175,13 +197,10 @@ class DetailPage extends React.Component<any, any> {
<input
className={styles.bugInput}
placeholder="¥最低买入1.00元"
type='number'
type='text'
inputMode='decimal'
value={buyInput}
onChange={(e) => {
this.setState({
buyInput: e.target.value,
});
}}
onChange={(e) => this.handleInputChange(e, 'buyInput')}
/>
<div className={styles.buyTip}>首次购买1.00元起 再次购买1.00元起 1.00元递增</div>
<Button
......@@ -206,13 +225,10 @@ class DetailPage extends React.Component<any, any> {
<div className={styles.sellInput}>
<input
value={sellInput}
type='number'
type='text'
inputMode='decimal'
placeholder="最多可赎回0份"
onChange={(e) => {
this.setState({
sellInput: e.target.value,
});
}}
onChange={(e) => this.handleInputChange(e, 'sellInput')}
/>
<Button className={styles.sellAll} onClick={() => {
this.setState({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment