BIP 两个请求成功后,才能做某一件事

      //保存前校验

      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;
      }

 

posted @ 2023-03-02 13:58  龙旋风  阅读(22)  评论(0编辑  收藏  举报