//保存前校验 let SetXStatus = 0; viewModel.on("beforeSave", function (args) { let _this = this; console.log(_this); let rows = viewModel.getGridModel().getRows(); if (rows <= 0) { cb.utils.alert("未匹配到认证方案,无法保存单据!", "error"); return false; } var promisex = new cb.promise(); this.SetXStatus = 0; Promise.all([supMaterial(_this), SetsupCertTask(_this)]).then((res) => { if (_this.SetXStatus == 0) { console.log("失败"); promisex.reject(); // 失败 } else if (_this.SetXStatus == 1) { console.log("失败"); promisex.reject(); // 失败 } else if (_this.SetXStatus == 2) { console.log("放行"); promisex.resolve(); // 放行 } }); return promisex; // ------------------------------- }); function supMaterial(_this) { // let _this = this; let proxy = viewModel.setProxy({ ensure: { url: "/supCertTask/supMaterial", method: "POST", }, }); let param = { state: viewModel.getParams().mode, certMaterialClass: viewModel.get("certMaterialClass").getValue(), certSupplier: viewModel.get("certSupplier").getValue(), }; var promise = new cb.promise(); proxy.ensure(param, function (error, result) { if (_this.SetXStatus == 0) { _this.SetXStatus = 1; } else if (_this.SetXStatus == 1) { _this.SetXStatus = 2; } if (!result) { _this.SetXStatus = 0; cb.utils.alert( "存在同一供应商和物料分类的未完成的供应商认证任务,当前不允许新增同一维度的认证任务!", "error" ); promise.reject(); // 失败 } promise.resolve(); // 放行 }); return promise; } function SetsupCertTask(_this) { // let _this = this; var prom = new cb.promise(); let proxy = viewModel.setProxy({ ensure: { url: "/supCertTask/savebefore", method: "POST", }, }); let tempIds = []; let Rows = viewModel.getGridModel().getRows(); if (Rows.length > 0) { for (let i = 0; i < Rows.length; i++) { tempIds.push(Rows[i]["tempId"]); } } let param = { tempIds: tempIds, count: viewModel.getGridModel().getRows().length, id: viewModel.get("certstepId").getValue(), }; proxy.ensure(param, function (error, result) { if (_this.SetXStatus == 0) { _this.SetXStatus = 1; } else if (_this.SetXStatus == 1) { _this.SetXStatus = 2; } if (result.flag == "true") { } else { _this.SetXStatus = 0; cb.utils.alert( result.msg || "上游任认证方案数据异常,请确认和重试", "error" ); prom.reject(); // 失败 } prom.resolve(); // 放行 }); return prom; }
标签:function,一件,viewModel,SetXStatus,result,promise,let,BIP,请求 From: https://www.cnblogs.com/LFxanla/p/17171580.html