仅做笔记。
html
<el-input v-model.number="ruleForm_lottery.lotteryNumber" onKeypress="return (/[d]/.test(String.fromCharCode(event.keyCode)))" @blur="blurFunc_lottery('lotteryNumber')" maxlength="3" placeholder="请输入开奖人数"></el-input>
<el-input v-model="ruleForm_redpacket.singleAmount" onkeyup="this.value=this.value.match(/d+.?d{0,2}/);this.dispatchEvent(new Event('input'))" @blur="blurFunc_redpacket('singleAmount', 2)" maxlength="5" placeholder="请输入红包单个金额"></el-input>
JS
const reg = /(^[1-9]d*$)/; let check_lottery_number = (rule, value, callback) => { value ? reg.test(value) ? Number(value) > Number(this.ruleForm_lottery.stock) ? callback(new Error("奖品数量不可超过库存最大值")) : callback() : callback(new Error('请输入正确的奖品数量')) : callback(new Error('请输入奖品数量')); }; let checkNumber = (rule, value, callback) => {//红包个数 value ? reg.test(value) ? Number(value) <= 100 ? this.ruleForm_redpacket.amount ? ( Number(this.ruleForm_redpacket.amount) / Number(this.ruleForm_redpacket.number) ) >= 0.01 ? callback() : callback(new Error('单个红包不可低于0.01元')) : callback() : callback(new Error('红包个数不可超过100')) : callback(new Error('请输入正确的红包个数')) : callback(new Error('请输入红包个数')); }; let checkAmount = (rule, value, callback) => { value ? callback() : callback(new Error('请输入红包总金额')); };
rules_lottery: { number: [ { required: true, validator: check_lottery_number, trigger: 'blur' } ], },