💊 fix: 修复红包表达校验

This commit is contained in:
wangsongsole 2023-06-29 15:42:00 +08:00
parent 9fca5fad96
commit 3c607b1e3f
3 changed files with 31 additions and 27 deletions

View File

@ -375,7 +375,7 @@ export default class addKnockGold extends Component {
return item.cash_activity_id === this.props.data.cash_activity_id return item.cash_activity_id === this.props.data.cash_activity_id
}) })
/* 校验表单 */ /* 校验表单 */
if (additionalRules(this.state) === false) { if (additionalRules(this.state, this.computeMin(), this.computeMax_Min(false)) === false) {
return false return false
} }
/* 兼容老数据 */ /* 兼容老数据 */
@ -390,7 +390,7 @@ export default class addKnockGold extends Component {
return true return true
} else { } else {
/* 校验表单 */ /* 校验表单 */
if (additionalRules(this.state) === false) { if (additionalRules(this.state, this.computeMin(), this.computeMax_Min(false)) === false) {
return false return false
} }
// //
@ -450,7 +450,7 @@ export default class addKnockGold extends Component {
} }
/* 计算随机最大面额中的最大值 */ /* 计算随机最大面额中的最大值 */
computeMax_Min() { computeMax_Min(is = true) {
const { min_denomination, num, all_budget } = this.state.model const { min_denomination, num, all_budget } = this.state.model
const b = this.state.model.channel === 1 ? 0.01 : 0.1 const b = this.state.model.channel === 1 ? 0.01 : 0.1
const max = all_budget - (num - 1) * min_denomination const max = all_budget - (num - 1) * min_denomination
@ -465,12 +465,13 @@ export default class addKnockGold extends Component {
this.setState({ this.setState({
computeMax: a.toFixed(2) computeMax: a.toFixed(2)
}) })
this.onHandleChange("", "max_denomination") is && this.onHandleChange("", "max_denomination")
return a.toFixed(2)
} }
/* 计算随机最大面额中的最小值 */ /* 计算随机最大面额中的最小值 */
computeMin() { computeMin() {
let data = "" let data = 0
const b = this.state.model.channel === 1 ? 0.01 : 0.1 const b = this.state.model.channel === 1 ? 0.01 : 0.1
if (isFinite(this.state.model.all_budget / this.state.model.num)) { if (isFinite(this.state.model.all_budget / this.state.model.num)) {
const a = this.state.model.all_budget / this.state.model.num const a = this.state.model.all_budget / this.state.model.num
@ -484,10 +485,7 @@ export default class addKnockGold extends Component {
} else { } else {
data = b data = b
} }
this.setState({ return data.toFixed(2)
computeMin: data.toFixed(2)
})
this.onHandleChange("", "max_denomination")
} }
//tag //tag
@ -504,7 +502,7 @@ export default class addKnockGold extends Component {
return "请输入" return "请输入"
} }
if (this.state.computeMax) { if (this.state.computeMax) {
return `最大面额为${this.state.computeMin} ~ ${this.state.computeMax}` return `最大面额为${this.computeMin()} ~ ${this.state.computeMax}`
} }
return "请输入" return "请输入"
} }

View File

@ -44,7 +44,7 @@ export default {
} }
/* 额外验证规则 */ /* 额外验证规则 */
export function additionalRules(params) { export function additionalRules(params, computeMin, computeMax) {
const model = cloneDeep(params.model) const model = cloneDeep(params.model)
model.all_budget = Number(model.all_budget) model.all_budget = Number(model.all_budget)
model.day_budget = Number(model.day_budget) model.day_budget = Number(model.day_budget)
@ -159,11 +159,14 @@ export function additionalRules(params) {
if (model.cash_amount_type === "2") { if (model.cash_amount_type === "2") {
/* TODO: 2:微信 1:支付宝 */ /* TODO: 2:微信 1:支付宝 */
if (model.channel === 2) { if (model.channel === 2) {
return rulesRandom(model, 0.1) if (!rulesRandom(model, 0.1)) {
}
} }
if (model.channel === 1) { if (model.channel === 1) {
return rulesRandom(model, 0.01) if (!rulesRandom(model, 0.01)) {
return false
}
} }
if (model.all_budget < model.min_denomination * model.num) { if (model.all_budget < model.min_denomination * model.num) {
@ -176,6 +179,16 @@ export function additionalRules(params) {
return false return false
} }
if (computeMax < model.max_denomination) {
Notify.error("随机最大面额不得大于计算最大面额")
return false
}
if (computeMin > model.max_denomination) {
Notify.error("随机最大面额不得小于计算最小面额")
return false
}
if (model.all_budget < model.all_budget / model.num) { if (model.all_budget < model.all_budget / model.num) {
Notify.error("最大面额不得小于最大面额中的最小值") Notify.error("最大面额不得小于最大面额中的最小值")
return false return false
@ -196,11 +209,15 @@ export function additionalRules(params) {
if (model.cash_amount_type === "1") { if (model.cash_amount_type === "1") {
/* TODO: 2:微信 1:支付宝 */ /* TODO: 2:微信 1:支付宝 */
if (model.channel === 2) { if (model.channel === 2) {
return rulesFixed(model, 0.1) if (!rulesFixed(model, 0.1)) {
return false
}
} }
if (model.channel === 1) { if (model.channel === 1) {
return rulesFixed(model, 0.01) if (!rulesFixed(model, 0.01)) {
return false
}
} }
if (model.all_budget < model.denomination || model.day_budget < model.denomination) { if (model.all_budget < model.denomination || model.day_budget < model.denomination) {
@ -208,16 +225,6 @@ export function additionalRules(params) {
return false return false
} }
if (params.computeMax < model.max_denomination) {
Notify.error("随机最大面额不得大于计算最大面额")
return false
}
if (params.computeMin < model.min_denomination) {
Notify.error("随机最小面额不得大于计算最小面额")
return false
}
if (model.day_budget < model.denomination || model.day_budget > model.all_budget) { if (model.day_budget < model.denomination || model.day_budget > model.all_budget) {
Notify.error("单日发放预算不得小于面额且不大于总预算") Notify.error("单日发放预算不得小于面额且不大于总预算")
return false return false

View File

@ -65,7 +65,6 @@ export function model({ data }) {
userSelectList: [] /* 预警人数据 */, userSelectList: [] /* 预警人数据 */,
form_data: {}, form_data: {},
isEdit: !!data?.id /* 是否为编辑 */, isEdit: !!data?.id /* 是否为编辑 */,
computeMax: "" /* 随机最大面额 */, computeMax: "" /* 随机最大面额 */
computeMin: "" /* 随机最小面额 */
} }
} }