值在达到 0 后重置回最大值

Value resets back to maxvalue after hitting 0

我正在创建一个计算器,它显示艺术家还剩下多少钱要支付给唱片公司。在我的代码中,每次 'artistCosts' 达到 0 时,它都会弹回到最大值。 这是我的代码:

  // als er bepaalde waarden wijzigen worden de berekeningen opnieuw uitgevoerd
  change() {
    console.log('change');
    this.calculateValues();
  }

  // wijziging in dealtype
  dealtypeChanged(value) {
    this.dealType = value;
    console.log(this.dealType);
    if (this.dealType == 'licentieDeal') {
      this.recordingCosts = 0;
      this.marketingCosts = 2000;
      this.splitArtist = 25;
    } else if (this.dealType == 'distributieDeal') {
      this.recordingCosts = 0;
      this.marketingCosts = 0;
      this.splitArtist = 80;
    } else if (this.dealType == 'eigenDeal') {
      this.splitArtist = 100;
      this.artistAdvance = 0;
      this.recordingCosts = 0;
      this.marketingCosts = 0;
    } else {
      this.splitArtist = 15;
      this.artistAdvance = 2000;
      this.recordingCosts = 2000;
      this.marketingCosts = 2000;
    }
    this.change();
  }

  // berekende en verdeeld kosten tussen label en artiest op basis van recoupable velden
  calculateCosts() {
    this.artistCosts = 0;
    this.labelCosts = this.artistAdvance + this.marketingCosts + this.recordingCosts;
    if (this.recoupableArtistAdvance === true) {
      this.artistCosts = this.artistCosts + this.artistAdvance;
    }
    if (this.recoupableMarketingCosts === true) {
      this.artistCosts = this.artistCosts + this.marketingCosts;
    }
    if (this.recoupableRecordingCosts === true) {
      this.artistCosts = this.artistCosts + this.recordingCosts;
    }
  }        

// Distributes revenue between artist and label via split
      divideRevenue() {
        let artistRevenue = (this.grossRevenue * (this.splitArtist / 100));
        let labelRevenue = (this.grossRevenue * (this.splitLabel / 100));
    
        // calculation of royalties label and artist after deduction of costs
        if (artistRevenue >= this.artistCosts) {
          this.artistBalancedRecouped = 100;
          this.artistRoyalty = artistRevenue - this.artistCosts;
        } else {
          this.artistBalancedRecouped = Math.round((artistRevenue / this.artistCosts) * 100);
          this.artistRoyalty = 0;
        }
        if (labelRevenue >= this.labelCosts) {
          this.labelRoyalty = labelRevenue - this.labelCosts;
        } else {
          this.labelRoyalty = labelRevenue - this.labelCosts;
        }
        if (this.artistCosts >= this.artistCosts - artistRevenue) {
          this.artistCosts = this.artistCosts - artistRevenue;
        }
      }

如何让我 'artistCosts' 在达到 0 时保持在 0 而不会弹回到最大值。

经过一番排查才发现,所以我的计算是错误的。仍然不知道为什么它不能按照我拳头的方式工作,但是这部分:

if (this.artistCosts >= this.artistCosts - artistRevenue) {
          this.artistCosts = this.artistCosts - artistRevenue;
        }

我改成了这样:

   if (this.artistRoyalty > 0 ) {
      this.artistCosts = 0;
    } else {
      this.artistCosts = this.artistCosts - artistRevenue;
    }

现在,当 this.artistRoyalty 大于 0 时,this.artistCosts 也将保持为 0。它不再对多个参数进行计算,它只是检查 this.artistRoyalty 是否大于 0 . 你不能做 if (this.artistRoyalty >= 0 ) 我不知道这是为什么,如果有人能解释为什么第一部分不起作用以及为什么 if (this.artistRoyalty >= 0 ) 不起作用。那将非常有帮助!