onSubmit = () => {
console.log(this.props.form, "form123");
this.props.form.validateFields((error, value) => {
console.log(this.state.formValue, "this.state.formValue");
this.setState({ formValue: value });
console.log(this.state.formValue, "this.state.formValue2");
if (
this.state.formValue === "" ||
JSON.stringify(this.state.formValue) === JSON.stringify(value)
) {
Toast.info("未修改禁止提交");
return;
}
if (!error) {
const {
proInfoFormEdit: { list },
} = this.props;
//出生地省
this.state.birth_sheng_value
? (list[0].infoItems[2].value = this.state.birth_sheng_value)
: "";
// 出生地市
this.state.birth_city_value
? (list[0].infoItems[3].value = this.state.birth_city_value)
: "";
// 现住省份
this.state.now_sheng_value
? (list[0].infoItems[5].value = this.state.now_sheng_value)
: "";
// 现住市
this.state.now_city_value
? (list[0].infoItems[6].value = this.state.now_city_value)
: "";
// 户口省
this.state.hukou_sheng_value
? (list[0].infoItems[9].value = this.state.hukou_sheng_value)
: "";
// 户口市
this.state.hukou_city_value
? (list[0].infoItems[10].value = this.state.hukou_city_value)
: "";
const submitData = {};
submitData.dataObj = convertFormData(value, list);
submitData.param = this.state.item.editId;
console.log("submitData: ", submitData);
this.props.dispatch({
type: "proInfoFormEdit/getListDataForRestCode",
payload: {
arguments: JSON.stringify(submitData),
methodName: "saveEditEmpInfoApply",
restCode: "hcm",
},
callback: (code, msg) => {
if (code === "0") {
Toast.info(msg);
} else if (code === "1") {
this.setState({ visible: true });
}
},
});
} else {
submitError(error);
}
});
};
这里利用一下setstate 是异步的更新的机制
首先 先把value保存在 formValue中,但是下面用formValue的时候,肯定还是初始值空,第二次点击的时候,他才会有值,并且formValue的值和第二次的值相等,就可以禁止提交了