簡體   English   中英

帶可選參數的角度計算

[英]angular calculation with optional parameter

我正在為我們的銷售代表實施一種工具,使他們能夠與客戶協商價格。 我正在從后端加載帶有Rateplan和費用的產品列表,並在前端的表中將其顯示給用戶。 1個產品有n個費率計划(您只能選擇一個),一個費率計划有n個費用(安裝的一次性費用,每月發生0或n個固定費用,並且每次使用費用可選0-2支付)。 銷售代表可以為每筆費用提供折扣。 在定義數量的地方也有收費。

每行的最后一列應顯示不包含數量的費用的折扣價,計算應為標價-(標價/ 100 *折扣)。 對於具有數量的費用,計算應如下所示:(listprice-(listprice / 100 * qantity))*數量

                             <div>
            <span>PRODUCT RATE PLAN</span>
            <mat-divider></mat-divider>
            <div *ngFor="let product of orderIntake; let productIndex = index">
                <br />
                <span class="rightpadding"><b>Product:</b> {{ product.productName }}</span><span class="rightpadding"><b>Rate plan:</b> {{ product.productRatePlans['name'] }}</span>
                <table class="subtable">
                    <tr class="header">
                        <th>CHARGE NAME</th>
                        <th>TYPE</th>
                        <th>MODEL</th>
                        <th>UOM</th>
                        <th>LISTPRICE</th>
                        <th>DISCOUNT AMOUNT</th>
                        <th>DISCOUNT PERCENTAGE</th>
                        <th>QUANTITY</th>
                        <th>PRICE</th>
                    </tr>
                    <tr>
                        <td colspan="11">
                            <mat-divider></mat-divider>
                        </td>
                    </tr>
                    <tr *ngFor="let rateplancharge of product.productRatePlans['productRatePlanCharges']; let ratePlanChargeIndex = index">
                        <td>{{ rateplancharge.name }}</td>
                        <td>{{ rateplancharge.type }}</td>
                        <td>{{ rateplancharge.model }}</td>
                        <td>{{ rateplancharge.uom }}</td>
                        <td>{{ rateplancharge.pricing['0'].price }}<span matSuffix>.00 {{ rateplancharge.pricing['0'].currency }}</span></td>
                        <td>
                            <mat-form-field appearance="outline"><input matInput disabled placeholder="Discount" value="{{ getDiscount(rateplancharge.pricing['0'].price, discountP.value | number : '1.2-2' ) }}" type="number" style="text-align: right"></mat-form-field>
                        </td>
                        <td>
                            <mat-form-field appearance="outline">
                                <input matInput placeholder="Discount %" min="0" max="10" value="0" type="number" style="text-align: right" #discountP>
                                <span matSuffix>.00 %</span>
                            </mat-form-field>
                        </td>
                        <td style="text-align: center"><span *ngIf="!rateplancharge['defaultQuantity']">N.A.</span>
                            <mat-form-field appearance="outline" *ngIf="rateplancharge.defaultQuantity">
                                <input matInput placeholder="Quantity" min="0" value="{{ rateplancharge.defaultQuantity }}" type="number" style="text-align: right" #quantityP id="quantityP{{ratePlanChargeIndex}}">
                            </mat-form-field>
                        </td>

                        <td>{{ total(rateplancharge.pricing['0'].price, discountP.value, ratePlanChargeIndex, quantityP) }}</td>
                    </tr>
                </table><br />
                <mat-divider></mat-divider>
            </div>
        </div>

我正在基於是否有數量應用使用不同的輸入參數調用函數total()

該函數如下所示:

  total(listprice, discount, index, quantityP?) {
    if (document.getElementById('quantityP' + index) !== null) {
      quantityP = document.getElementById('quantityP' + index).value;
    } else {
      quantityP = 1;
    }
    return (listprice - (listprice / 100) * discount) * quantityP;
  }

由於某些原因,數量總是不確定的。 是否有人知道為什么還是知道一種解決方法(我當時正在考慮實現一個值=“ 1”的隱藏輸入字段,所以一個要傳遞給總數...但是我遇到了同樣的問題...)

感謝您的支持! :)

total(rateplancharge.pricing['0'].price, discountP.value, quantityP)

實際上應該是

total(rateplancharge.pricing['0'].price, discountP.value, quantityP.value)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM