mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-03-13 15:44:26 +08:00
Clean target value if formula unready
This commit is contained in:
parent
787f2cd869
commit
7f214334c6
1 changed files with 20 additions and 9 deletions
|
@ -778,13 +778,15 @@ class RbFormNumber extends RbFormText {
|
|||
|
||||
this.calcFormula__values = {}
|
||||
// 初始值
|
||||
watchFields.forEach((item) => {
|
||||
const name = item.substr(1, item.length - 2)
|
||||
const fieldComp = this.props.$$$parent.refs[`fieldcomp-${name}`]
|
||||
if (fieldComp && fieldComp.state.value) {
|
||||
this.calcFormula__values[name] = fieldComp.state.value
|
||||
}
|
||||
})
|
||||
setTimeout(() => {
|
||||
watchFields.forEach((item) => {
|
||||
const name = item.substr(1, item.length - 2)
|
||||
const fieldComp = this.props.$$$parent.refs[`fieldcomp-${name}`]
|
||||
if (fieldComp && fieldComp.state.value) {
|
||||
this.calcFormula__values[name] = this._removeComma(fieldComp.state.value)
|
||||
}
|
||||
})
|
||||
}, 400)
|
||||
|
||||
// 小数位
|
||||
const fixed = this.props.decimalFormat ? (this.props.decimalFormat.split('.')[1] || '').length : 0
|
||||
|
@ -792,13 +794,22 @@ class RbFormNumber extends RbFormText {
|
|||
// 表单计算
|
||||
this.props.$$$parent.onFieldValueChange((s) => {
|
||||
if (!watchFields.includes(`{${s.name}}`)) return
|
||||
this.calcFormula__values[s.name] = s.value
|
||||
|
||||
if (s.value) {
|
||||
this.calcFormula__values[s.name] = this._removeComma(s.value)
|
||||
} else {
|
||||
delete this.calcFormula__values[s.name]
|
||||
}
|
||||
|
||||
let formula = calcFormula
|
||||
for (let key in this.calcFormula__values) {
|
||||
formula = formula.replace(new RegExp(`{${key}}`, 'ig'), this.calcFormula__values[key] || 0)
|
||||
}
|
||||
if (formula.includes('{')) return
|
||||
|
||||
if (formula.includes('{')) {
|
||||
this.setValue(null)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
let calcv = null
|
||||
|
|
Loading…
Reference in a new issue