修改本地生活 付款只能输入大于0的数字,且保留两位小数
This commit is contained in:
parent
fc9e6b2ff7
commit
29b21d9e53
@ -18,8 +18,8 @@
|
||||
|
||||
<div class="Msg">
|
||||
<div class="payMony">
|
||||
¥<input type="text" v-model="Money" placeholder="付款金额" placeholder-style="font-size: 50rpx;">
|
||||
</div>
|
||||
¥<input type="number" v-model="Money" placeholder="付款金额" placeholder-style="font-size: 50rpx;"
|
||||
@blur="handleMoneyInput" step="0.01" min="0.01"> </div>
|
||||
<div class="payRemark">
|
||||
<input type="text" v-model="remarks" placeholder="付款备注">
|
||||
</div>
|
||||
@ -62,7 +62,8 @@
|
||||
<div class="line"></div>
|
||||
<div class="btnItem" @click="home">首页</div>
|
||||
<div class="btnItem2" @click="changeBoxshadow">
|
||||
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/local_qrcode.png" mode="aspectFill"></image>
|
||||
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/local_qrcode.png"
|
||||
mode="aspectFill"></image>
|
||||
本页二维码
|
||||
</div>
|
||||
</div>
|
||||
@ -135,6 +136,29 @@ export default {
|
||||
|
||||
|
||||
methods: {
|
||||
handleMoneyInput() {
|
||||
// 清除非数字和非小数点的字符
|
||||
let value = this.Money.toString().replace(/[^\d.]/g, '');
|
||||
|
||||
// 限制只能有一个小数点
|
||||
value = value.replace(/\.{2,}/g, '.');
|
||||
|
||||
// 确保小数点后最多两位
|
||||
value = value.replace(/^(\d+)\.(\d{2}).*$/, '$1.$2');
|
||||
|
||||
// 处理开头是小数点的情况
|
||||
if (value.startsWith('.')) {
|
||||
value = '0' + value;
|
||||
}
|
||||
|
||||
// 处理大于0的验证
|
||||
const num = parseFloat(value);
|
||||
if (isNaN(num) || num <= 0) {
|
||||
value = '';
|
||||
}
|
||||
|
||||
this.Money = value;
|
||||
},
|
||||
|
||||
createQrcode() {
|
||||
uni.showLoading({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user