Commit 02ecc34d by liangjianmin

feat(apply): add amount formatter for fee input field

- Change input type from "number" to "digit" for better mobile keyboard support
- Add formatAmount() method to validate and format currency input
- Restrict decimal places to maximum 2 digits for CNY amounts
- Remove non-numeric characters except decimal point during input
- Handle multiple decimal points by keeping only the first one
- Improve user experience with proper currency input validation
parent a3ec3504
Showing with 33 additions and 1 deletions
......@@ -19,7 +19,14 @@
<view class="form-section">
<view class="section-header">费用明细</view>
<u-form-item label="申请免收金额" prop="apply_fee_amount" required borderBottom>
<u--input v-model="form.apply_fee_amount" placeholder="请输入" border="none" inputAlign="right" type="number"></u--input>
<u--input
v-model="form.apply_fee_amount"
placeholder="请输入"
border="none"
inputAlign="right"
type="digit"
:formatter="formatAmount"
></u--input>
</u-form-item>
<view class="currency-hint">
<text>CNY-人民币元</text>
......@@ -104,6 +111,31 @@
},
/**
* 金额格式化函数,限制只能输入两位小数
* @param {string} value - 输入的金额值
* @return {string} 格式化后的值
*/
formatAmount(value) {
if (!value) return '';
// 移除所有非数字和小数点的字符
var cleanValue = value.replace(/[^\d.]/g, '');
// 处理多个小数点的情况,只保留第一个
var parts = cleanValue.split('.');
if (parts.length > 2) {
cleanValue = parts[0] + '.' + parts.slice(1).join('');
}
// 限制小数点后最多两位
if (parts.length === 2 && parts[1].length > 2) {
cleanValue = parts[0] + '.' + parts[1].substring(0, 2);
}
return cleanValue;
},
/**
* 订单号输入事件,防抖获取客户名称
* @return {void}
*/
......
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 sign in to comment