簡體   English   中英

表角材料getTotalCost()動態

[英]Table angular material getTotalCost() dynamic

我需要一個角度材料表的幫助,我創建了一個字段,用戶可以在其中增加或減少表中的產品單位,從而進行乘法運算。 產品的價格還可以,但getTotalCost()函數根據產品的價格不會變得動態。 我怎么定義這個?

<table mat-table [dataSource]="dataSource " class="table table-striped" matSort>
                <!-- Name Column -->
                <ng-container matColumnDef="referencia">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header> Referência </th>
                    <td mat-cell *matCellDef="let element">{{element.produto.referencia}} </td>
                </ng-container>
                <!-- Position Column -->
                <ng-container matColumnDef="codigo">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Código </th>
                    <td mat-cell *matCellDef="let element"> {{element.produto.codigo}} </td>
                </ng-container>
                <!-- Weight Column -->
                <ng-container matColumnDef="descricao">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Descrição</th>
                    <td mat-cell *matCellDef="let element"> {{element.produto.descricao}} </td>
                </ng-container>
                <!-- Symbol Column -->
                <ng-container matColumnDef="nomeFantasia">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header> Fabricante </th>
                    <td mat-cell *matCellDef="let element"> {{element.produto.NomeFantasia}} </td>
                </ng-container>
                <ng-container matColumnDef="precoVendaPraticado">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Preço </th>
                    <td mat-cell *matCellDef="let element"> {{element.produto.precoVendaPraticado * obterQtdeItem(element.produto.codigo)| currency}} </td>
                </ng-container>
                <ng-container matColumnDef="precoPromocao">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Preço promoção</th>
                    <td mat-cell *matCellDef="let element"> {{element.produto.precoPromocao}} </td>
                </ng-container>
                <ng-container matColumnDef="precoSugestaoVenda">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Preço sugestão venda</th>
                    <td mat-cell *matCellDef="let element"> {{element.produto.precoSugestaoVenda}} </td>
                </ng-container>
                <ng-container matColumnDef="estoque">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Estoque</th>
                    <td mat-cell *matCellDef="let element">
                        {{element.estoque}}
                    </td>
                </ng-container>
                <ng-container matColumnDef="unidadeMedida">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header> Un. medida </th>
                    <td mat-cell *matCellDef="let element"> {{element.produto.unidadeMedida.unidadeMedida}} </td>
                </ng-container>
                <ng-container matColumnDef="quantidade"0>
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Quantidade</th>
                    <td mat-cell *matCellDef="let element">
                        <button mat-raised-button class="btn-xs space-button">
                            <mat-icon (click)="decrementarQuantidade(element.produto)">remove</mat-icon>
                        </button>
                        <mat-form-field class="col-md-4 col-xs-5" appearance="outline" style="font-size:10.7px;" appearance="outline">
                            <input matInput [value]="obterQtdeItem(element.produto.codigo)" min="0" style="font-size:11px;">
                        </mat-form-field>
                        <button mat-raised-button class="btn-xs space-button" (click)="incrementarQuantidade(element.produto)">
                            <mat-icon>add</mat-icon>
                        </button>
                        <button mat-raised-button class="btn-xs btn-danger space-button-button-small">
                            <mat-icon (click)="removerDoCarrinho(element.produto.codigo)">clear</mat-icon>
                        </button>
                        <!--mat-icon *ngIf="incluidoNoCarrinho(element.produto.codigo)" class="text-success pull-right">add_shopping_cart</!--mat-icon-->
                    </td>

                </ng-container>
                <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
                <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
            </table>
 getTotalCost() {
      return this.pedido.itens.map(t => t.produto.precoVendaPraticado).reduce((acc, value) => acc + value, 0);  
  }

通過將項目數量乘以項目的價格來解決問題。

 getTotalCost(){
return this.pedido.itens.map(t => t.produto.precoVendaPraticado * this.obterQtdeItem(t.produto.codigo)).reduce((acc, value) => acc + value, 0);  

}

暫無
暫無

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

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