vue中按顺序调用方法
promise
saveBusiness (resolve) {
if (this.addId) {
this.$refs["dataForm"].validate((valid, obj) => {
if (valid) {
const loading = this.$loading({
lock: true,
text: "Loading",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
this.dataForm.id = this.addId;
codeApi.getCode(this.codeForm).then((res) => {
this.dataForm.documentNo = res.data;
console.log("保存时的编号===>", this.dataForm.documentNo)
if (res.success) {
businessApi.updateBusiness(this.dataForm).then((res) => {
if (res.success) {
this.$message.success("保存成功");
}
loading.close()
resolve()//添加返回!!!!!!!!!
}).catch(res => {
loading.close()
})
}
});
} else {
var a = [];
for (const key in obj) {
a.push(obj[key][0].message);
}
this.$message({
message: a[0],
type: "warning",
});
}
})
} else {
this.$refs["dataForm"].validate((valid, obj) => {
if (valid) {
const loading = this.$loading({
lock: true,
text: "Loading",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
codeApi.getCode(this.codeForm).then((res) => {
this.dataForm.documentNo = res.data;
console.log("保存时的编号===>", this.dataForm.documentNo)
if (res.success) {
businessApi.saveBusiness(this.dataForm).then((res) => {
if (res.success) {
this.addId = res.data.id;
this.dataForm.createUserOrgName = res.data.createUserOrgName;
this.isId = true;
this.approveFrom.id = this.addId
this.$message.success("保存成功");
}
loading.close()
}).catch(res => {
loading.close()
})
}
});
} else {
var a = [];
for (const key in obj) {
a.push(obj[key][0].message);
}
this.$message({
message: a[0],
type: "warning",
});
}
})
}
},
approvalBusiness () {
new Promise((resolve) => {
this.saveBusiness(resolve)//调用的第一个方法
}).then(() => {
//第二个方法的方法体
})
}
浙公网安备 33010602011771号