|
在字段的 onChange事件里 增加计算代码,emitFieldDataChange(newValue, oldValue) {
this.emit$('field-value-changed', [newValue, oldValue]),
this.broadcast("FieldWidget", "sync-field-value", [this.field.options.name, this.field.options.keyName, this.subFormName, this.subFormRowId, newValue, this.getObjectName()]),
this.getFormRef().broadcast("FieldWidget", "calculate-formula", [newValue, this]),
/* 必须用dispatch向指定父组件派发消息!! */
this.dispatch('VFormRender', 'fieldChange',[this.field.options.name, newValue, oldValue, this.subFormName, this.subFormRowIndex])
},
this.on$("calculate-formula", (e)=>{
if (!!this.field.options.formulaEnabled && !!this.field.options.formula) {
//console.log(e)
const oChangeField = e[1];
const t = this.field.options.name;
//console.log(this.field.options.formula, o)
// this.getFormRef().getWidgetRef.getWidgetRef
let ret = calcExpression(this.field.options.formula,this.getFormRef(), this.getGlobalDsv(),this,oChangeField);
// console.log(this.field.type)
if(ret !== null){
if(this.field.type=='number'){
if(getDataType(ret) == "Number"){
this.setValue(ret,true);
}else if(getDataType(ret)==="String"){
this.setValue(parseFloat(ret),true);
}
}else
this.setValue(ret,true);
}
}
}) |
|