|
|
@@ -28,11 +28,12 @@
|
|
|
<text class="section-limit" >0元即不限制金额</text>
|
|
|
</text>
|
|
|
<view class="flex align-center"><u-input v-model="form.contentConditions"
|
|
|
- placeholder="输入金额" />元</view>
|
|
|
+ placeholder="输入金额" @input="(val) => handleAmountInput(val, 'contentConditions', true)" />元</view>
|
|
|
</view>
|
|
|
<view style="width: 46%;">
|
|
|
<text class="section-title" style="font-weight: 500;">减</text>
|
|
|
- <view class="flex align-center"><u-input v-model="form.contentInfo" placeholder="输入金额" />元
|
|
|
+ <view class="flex align-center"><u-input v-model="form.contentInfo" placeholder="输入金额"
|
|
|
+ @input="(val) => handleAmountInput(val, 'contentInfo', false)" />元
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -372,6 +373,44 @@ export default {
|
|
|
url: '/pages/coupon/activity?params=' + encodeURIComponent(JSON.stringify(this.form.couponRangeInfo))
|
|
|
})
|
|
|
},
|
|
|
+ handleAmountInput(val, field, allowZero = false) {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (!val && val !== 0) {
|
|
|
+ this.form[field] = ''
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let value = val.toString().replace(/[^\d.]/g, '')
|
|
|
+ const dotIndex = value.indexOf('.')
|
|
|
+ if (dotIndex !== -1) {
|
|
|
+ value = value.slice(0, dotIndex + 1) + value.slice(dotIndex + 1).replace(/\./g, '')
|
|
|
+ }
|
|
|
+ const parts = value.split('.')
|
|
|
+ if (parts.length === 2 && parts[1].length > 2) {
|
|
|
+ value = parts[0] + '.' + parts[1].slice(0, 2)
|
|
|
+ }
|
|
|
+ if (value.startsWith('0') && value.length > 1 && value[1] !== '.') {
|
|
|
+ value = value.replace(/^0+/, '') || '0'
|
|
|
+ }
|
|
|
+ if (!allowZero && value !== '' && parseFloat(value) === 0) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '减免金额必须大于0',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ this.form[field] = ''
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.form[field] = value
|
|
|
+ })
|
|
|
+ },
|
|
|
+ isValidAmount(value, allowZero = false) {
|
|
|
+ if (value === '' || value === null || value === undefined) return false
|
|
|
+ const str = String(value)
|
|
|
+ if (!/^\d+(\.\d{1,2})?$/.test(str)) return false
|
|
|
+ const num = parseFloat(str)
|
|
|
+ if (isNaN(num) || num < 0) return false
|
|
|
+ if (allowZero) return num >= 0
|
|
|
+ return num > 0
|
|
|
+ },
|
|
|
//提交审核
|
|
|
submit() {
|
|
|
console.log('++++')
|
|
|
@@ -381,15 +420,33 @@ export default {
|
|
|
icon: 'none'
|
|
|
});
|
|
|
return
|
|
|
- } else if (this.form.contentConditions=='') {
|
|
|
+ } else if (this.form.contentConditions === '') {
|
|
|
uni.showToast({
|
|
|
title: '请输入满减金额',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
return
|
|
|
- } else if (!this.form.contentInfo) {
|
|
|
+ } else if (!this.isValidAmount(this.form.contentConditions, true)) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '满减金额只能输入0或正数',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return
|
|
|
+ } else if (!this.form.contentInfo) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请输入减免金额',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return
|
|
|
+ } else if (!this.isValidAmount(this.form.contentInfo, false)) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '减免金额只能输入正数',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return
|
|
|
+ } else if (parseFloat(this.form.contentConditions) > 0 && parseFloat(this.form.contentInfo) > parseFloat(this.form.contentConditions)) {
|
|
|
uni.showToast({
|
|
|
- title: '请输入金额',
|
|
|
+ title: '减免金额不能大于满减门槛',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
return
|