这边是vue2+antd+使用的是v-decorator
那么如果想要获取表单的值需要getFieldsValue
getFieldsValue | 获取一组输入控件的值,如不传入参数,则获取全部组件的值 |
<a-input-number v-decorator="['freeRentMonth', { rules: validatorRules.inputIf.rules }]" :min="0" @change="changedataSource" />
<span class="text"> (免租金额:{{automatic}})</span>
data() {
return {
visible: false,
visible2: false,
formData: {},
form: null,
validatorRules: {
// 表单验证
inputIf: { rules: [{ required: true, message: "此项不能为空" }] },
uploadIf: { rules: [{ required: true, message: "请上传" }] },
},
editForm: this.$form.createForm(this),
dataSource: [],
loading: false,
type: "add",
title: "",
automatic: '待计算'
};
},
// 计算 资产租金
changedataSource() {
if (this.houseType == 1) {
this.dataSource = this.dataSource.map((item) => {
return {
...item,
areas: Number(item.areas),
monthRentMoney: item.assetRentAreas > 0 && item.singlePrice > 0 ? (item.singlePrice * item.assetRentAreas).toFixed(2) : 0,
yearRentMoney: item.assetRentAreas > 0 && item.singlePrice > 0 ? (item.singlePrice * item.assetRentAreas * 12).toFixed(2) : 0,
};
});
} else {
this.dataSource = this.dataSource.map((item) => {
return {
...item,
monthRentMoney: item.number > 0 && item.singlePrice > 0 ? (item.number * item.singlePrice).toFixed(2) : 0,
yearRentMoney: item.number > 0 && item.singlePrice > 0 ? (item.number * item.singlePrice * 12).toFixed(2) : 0,
};
});
}
this.$nextTick(()=>{
let freeRentMonth = this.editForm.getFieldValue('freeRentMonth')
if(freeRentMonth===0){
this.automatic = 0
return
}
if(this.dataSource.every(item=>{return item.monthRentMoney>0})&&freeRentMonth>0){
let mMoney = 0
this.dataSource.forEach(item=>{
mMoney=mMoney+Number(item.monthRentMoney)
})
this.automatic = mMoney*freeRentMonth.toFixed(2)
}else{
this.automatic = '待计算'
}
})
},