简体   繁体   English

带可选参数的角度计算

[英]angular calculation with optional parameter

I'm implementing a tool for our sales reps to enable them to negotiate prices with customers. 我正在为我们的销售代表实施一种工具,使他们能够与客户协商价格。 I'm loading a list of products with rateplan and charges from a back end and show it to the user in a table in the frontend. 我正在从后端加载带有Rateplan和费用的产品列表,并在前端的表中将其显示给用户。 1 product has n rateplans (you would only select one) and one rateplan has n charges (one time fees for setup, 0 or n flat fees which occurs monthly and optional 0-2 pay per per use fees). 1个产品有n个费率计划(您只能选择一个),一个费率计划有n个费用(安装的一次性费用,每月发生0或n个固定费用,并且每次使用费用可选0-2支付)。 The sales rep can give discount on each charge. 销售代表可以为每笔费用提供折扣。 There are also charges where you define a quantity. 在定义数量的地方也有收费。

the last column of each row should show the discounted price for charges WITHOUT quantities the calculation should be listprice - (listprice/100*discount). 每行的最后一列应显示不包含数量的费用的折扣价,计算应为标价-(标价/ 100 *折扣)。 For charges WITH quantities the calculation should be like this: (listprice-(listprice/100*qantity))*quantity 对于具有数量的费用,计算应如下所示:(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>

I'm calling the function total() with different input parameters based on if there is quantity applying or not 我正在基于是否有数量应用使用不同的输入参数调用函数total()

the function looks like this: 该函数如下所示:

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

for some reason the quantity is always undefined. 由于某些原因,数量总是不确定的。 Does anybody have an idea why or knows a workaround (I was thinking to implement a hidden input field with value="1" so one is being passed to total... But I ran into the same issue...) 是否有人知道为什么还是知道一种解决方法(我当时正在考虑实现一个值=“ 1”的隐藏输入字段,所以一个要传递给总数...但是我遇到了同样的问题...)

Appreciate your support! 感谢您的支持! :) :)

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