product-module.component.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { Component, OnInit, Output, EventEmitter } from '@angular/core';
  2. import { NzModalRef, NzMessageService, NzModalService } from 'ng-zorro-antd';
  3. import { _HttpClient } from '@delon/theme';
  4. import { ContractFileProduct } from 'app/entity/contract-management/contract-file-product';
  5. import { ContractFileModular } from 'app/entity/contract-management/contract-file-modular';
  6. import { ContractFile } from 'app/entity/contract-management/contract-file';
  7. import { RoutesSharedModalProdutSelectComponent } from 'app/routes/shared/modal/produt-select/produt-select.component';
  8. @Component({
  9. selector: 'app-contract-management-contract-file-add-product-module',
  10. templateUrl: './product-module.component.html',
  11. })
  12. export class ContractManagementContractFileAddProductModuleComponent implements OnInit {
  13. constructor(
  14. private modalService:NzModalService
  15. ) {}
  16. ngOnInit(): void {}
  17. productList: ContractFileProduct[] = []; //产品数据
  18. // moduleList:ContractFileModular[]=[];//模块数据
  19. formatterDollar = (value: number): string => `¥ ${value}`;
  20. parserDollar = (value: string): string => value.replace('¥ ', '');
  21. /**
  22. * 产品新增行
  23. */
  24. prouctI = 0;
  25. productAddRow() {
  26. this.productList = [
  27. ...this.productList,
  28. {
  29. id: `${this.prouctI}`,
  30. code: '',
  31. name: '',
  32. discountRate: 0,
  33. standardQuotation: 0,
  34. unitPriceAfterDiscount: 0,
  35. standardAmount: 0,
  36. amountAfterDiscount: 0,
  37. costUnitPrice: 0,
  38. costAmount: 0,
  39. contractFileModularList: [],
  40. },
  41. ];
  42. this.prouctI++;
  43. }
  44. /**
  45. * 产品删除行
  46. */
  47. productDeleteRow(id) {
  48. this.productList = this.productList.filter(d => d.id !== id);
  49. }
  50. /**
  51. * 模块新增行
  52. */
  53. moduleI = 0;
  54. moduleAddRow(product) {
  55. product.contractFileModularList = [
  56. ...product.contractFileModularList,
  57. {
  58. id: `${this.moduleI}`,
  59. code: '',
  60. name: '',
  61. standardQuotation: 0,
  62. purchasePrice: 0,
  63. },
  64. ];
  65. this.moduleI++;
  66. }
  67. /**
  68. * 模块删除行
  69. */
  70. moduleDeleteRow(product, id) {
  71. product.contractFileModularList = product.contractFileModularList.filter(d => d.id !== id);
  72. }
  73. /**
  74. * 模块标准报价键盘弹起事件
  75. * @param product 产品对象
  76. */
  77. standardQuotationModuleKeyUp(product) {
  78. //判断当前产品下是否存在模块
  79. if (product && product.contractFileModularList) {
  80. let standardQuotationTotal = 0.0; //定义模块中标准报价总计
  81. //循环模块
  82. product.contractFileModularList.forEach(element => {
  83. //判断标准报价是否为数字
  84. if (!isNaN(Number(element.standardQuotation))) {
  85. //累加
  86. standardQuotationTotal = standardQuotationTotal + Number(element.standardQuotation);
  87. }
  88. });
  89. //把模块标准报价总和赋值给产品的标准报价
  90. product.standardQuotation = standardQuotationTotal;
  91. //获取品总标准报价并传入基本信息
  92. this.getContractFileStandardQuotationTotal();
  93. }
  94. }
  95. /**
  96. * 获取合同总共的标准报价
  97. */
  98. getContractFileStandardQuotationTotal() {
  99. if (this.productList) {
  100. let standardQuotationProductTotal = 0.0; //定义产品中标准报价总计
  101. this.productList.forEach(element => {
  102. //判断标准报价是否为数字
  103. if (!isNaN(Number(element.standardQuotation))) {
  104. //累加
  105. standardQuotationProductTotal = standardQuotationProductTotal + Number(element.standardQuotation);
  106. }
  107. });
  108. //把产品的总标准报价给合同标准报价
  109. this.contractFile.standardQuotation = standardQuotationProductTotal;
  110. //传给基本信息
  111. this.outContractFileObject();
  112. }
  113. }
  114. contractFile: ContractFile = {}; //合同的对象
  115. /**
  116. * 获取当前页面的相关信息传个父级页面
  117. */
  118. @Output() contractFileObject = new EventEmitter<{}>();
  119. outContractFileObject() {
  120. this.contractFileObject.emit(this.contractFile);
  121. }
  122. /**
  123. * 选择产品事件
  124. */
  125. selectProdutModal(data) {
  126. const modalRef = this.modalService.create({
  127. nzTitle: '选择产品',
  128. nzContent: RoutesSharedModalProdutSelectComponent,
  129. nzWidth: 1400,
  130. nzFooter: [
  131. {
  132. label: '关闭',
  133. type: 'default',
  134. onClick: addModel => {
  135. addModel.close();
  136. },
  137. },
  138. {
  139. label: '确定',
  140. type: 'primary',
  141. onClick: addModel => {
  142. addModel.save().then(()=>{
  143. data.code=addModel.selectObj[0].code
  144. data.name=addModel.selectObj[0].name
  145. data.baseMaterialFileProductId=addModel.selectObj[0].id
  146. });
  147. },
  148. },
  149. ],
  150. });
  151. }
  152. close() {}
  153. }