product-module.component.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 { BaseMaterialFileModularService } from 'app/services/basedata/base-material-file-modular.service';
  5. import { ContractFileProduct } from 'app/entity/contract-management/contract-file-product';
  6. import { ContractFile } from 'app/entity/contract-management/contract-file';
  7. import { RoutesSharedModalProdutSelectComponent } from 'app/routes/shared/modal/produt-select/produt-select.component';
  8. import { BaseMaterialFileModular } from 'app/entity/basedata/base-material-file-modular';
  9. @Component({
  10. selector: 'app-contract-management-contract-file-update-product-module',
  11. templateUrl: './product-module.component.html',
  12. })
  13. export class ContractManagementContractFileUpdateProductModuleComponent implements OnInit {
  14. constructor(
  15. private modalService:NzModalService,
  16. private baseMaterialFileModularService:BaseMaterialFileModularService
  17. ) {}
  18. ngOnInit(): void {}
  19. productList: ContractFileProduct[] = []; //产品数据
  20. // moduleList:ContractFileModular[]=[];//模块数据
  21. formatterDollar = (value: number): string => `¥ ${value}`;
  22. parserDollar = (value: string): string => value.replace('¥ ', '');
  23. formatterDollar2 = (value: number): string => `${value}%`;
  24. parserDollar2 = (value: string): string => value.replace('%', '');
  25. /**
  26. * 产品新增行
  27. */
  28. prouctI = 0;
  29. productAddRow() {
  30. this.productList = [
  31. ...this.productList,
  32. {
  33. id: `${this.prouctI}`,
  34. code: '',
  35. name: '',
  36. discountRate: 0,
  37. standardQuotation: 0,
  38. unitPriceAfterDiscount: 0,
  39. standardAmount: 0,
  40. amountAfterDiscount: 0,
  41. costUnitPrice: 0,
  42. costAmount: 0,
  43. contractFileModularList: [],
  44. },
  45. ];
  46. this.prouctI++;
  47. }
  48. /**
  49. * 产品删除行
  50. */
  51. productDeleteRow(data) {
  52. this.productList = this.productList.filter(d => d.id !== data.id);
  53. //计算折扣单价总和
  54. this.getUnitPriceAfterDiscountTotal();
  55. //计算标准报价
  56. this.standardQuotationModuleKeyUp(data)
  57. }
  58. /**
  59. * 模块新增行
  60. */
  61. moduleI = 0;
  62. moduleAddRow(product) {
  63. product.contractFileModularList = [
  64. ...product.contractFileModularList,
  65. {
  66. id: `${this.moduleI}`,
  67. code: '',
  68. name: '',
  69. standardQuotation: 0,
  70. purchasePrice: 0,
  71. },
  72. ];
  73. this.moduleI++;
  74. }
  75. /**
  76. * 模块删除行
  77. */
  78. moduleDeleteRow(product, id) {
  79. product.contractFileModularList = product.contractFileModularList.filter(d => d.id !== id);
  80. //计算标准报价
  81. this.standardQuotationModuleKeyUp(product)
  82. }
  83. /**
  84. * 模块标准报价键盘弹起事件
  85. * @param product 产品对象
  86. */
  87. standardQuotationModuleKeyUp(product) {
  88. //判断当前产品下是否存在模块
  89. if (product && product.contractFileModularList) {
  90. let standardQuotationTotal = 0.0; //定义模块中标准报价总计
  91. //循环模块
  92. product.contractFileModularList.forEach(element => {
  93. //判断标准报价是否为数字
  94. if (!isNaN(Number(element.standardQuotation))) {
  95. //累加
  96. standardQuotationTotal = standardQuotationTotal + Number(element.standardQuotation);
  97. }
  98. });
  99. //把模块标准报价总和赋值给产品的标准报价
  100. product.standardQuotation = standardQuotationTotal;
  101. //获取品总标准报价并传入基本信息
  102. this.getContractFileStandardQuotationTotal();
  103. }
  104. }
  105. /**
  106. * 获取合同总共的标准报价
  107. */
  108. getContractFileStandardQuotationTotal() {
  109. if (this.productList) {
  110. let standardQuotationProductTotal = 0.0; //定义产品中标准报价总计
  111. this.productList.forEach(element => {
  112. //判断标准报价是否为数字
  113. if (!isNaN(Number(element.standardQuotation))) {
  114. //累加
  115. standardQuotationProductTotal = standardQuotationProductTotal + Number(element.standardQuotation);
  116. }
  117. });
  118. //把产品的总标准报价给合同标准报价
  119. this.contractFile.standardQuotation = standardQuotationProductTotal;
  120. //传给基本信息
  121. this.outContractFileObject();
  122. }
  123. }
  124. contractFile: ContractFile = {}; //合同的对象
  125. /**
  126. * 获取当前页面的相关信息传个父级页面
  127. */
  128. @Output() contractFileObject = new EventEmitter<{}>();
  129. outContractFileObject() {
  130. this.contractFileObject.emit(this.contractFile);
  131. }
  132. /**
  133. * 选择产品事件
  134. */
  135. selectProdutModal(product) {
  136. const modalRef = this.modalService.create({
  137. nzTitle: '选择产品',
  138. nzContent: RoutesSharedModalProdutSelectComponent,
  139. nzWidth: 1400,
  140. nzFooter: [
  141. {
  142. label: '关闭',
  143. type: 'default',
  144. onClick: addModel => {
  145. addModel.close();
  146. },
  147. },
  148. {
  149. label: '确定',
  150. type: 'primary',
  151. onClick: addModel => {
  152. addModel.save().then(()=>{
  153. product.code=addModel.selectObj[0].code
  154. product.name=addModel.selectObj[0].name
  155. product.baseMaterialFileProductId=addModel.selectObj[0].id
  156. //获取产品下的模块数据下拉供模块表格选择
  157. this.getModuleListByPid(product);
  158. });
  159. },
  160. },
  161. ],
  162. });
  163. }
  164. /**
  165. * 根据产品id查询所属模块集合(供模块表格下拉选择)
  166. */
  167. getModuleListByPid(product){
  168. return new Promise((resolve)=>{
  169. let baseMaterialFileModular=new BaseMaterialFileModular();
  170. baseMaterialFileModular.baseMaterialFileProductId=product.baseMaterialFileProductId;
  171. //查询当前选择产品的模块
  172. this.baseMaterialFileModularService.list(baseMaterialFileModular).then((response)=>{
  173. //放入产品对象中
  174. if(response.success){
  175. product.modularListSelect=JSON.parse(JSON.stringify(response.result.records))
  176. }
  177. resolve();
  178. })
  179. })
  180. }
  181. /**
  182. * 模块选择触发事件
  183. * 获取编码和名称
  184. */
  185. baseMaterialFileModularIdChange(product,data,event){
  186. if(event){
  187. product.modularListSelect.forEach(element => {
  188. if(event==element.id){
  189. data.code=element.code;
  190. data.name=element.name;
  191. data.standardQuotation=element.standardQuotation;
  192. }
  193. });
  194. }else{
  195. data.code="";
  196. data.name="";
  197. }
  198. //计算标准报价
  199. this.standardQuotationModuleKeyUp(product)
  200. }
  201. /**
  202. * 折扣后单价改变事件
  203. */
  204. unitPriceAfterDiscountBlur(data){
  205. //标准报价
  206. let standardQuotation=this.getIsNaN("standardQuotation",data);
  207. //折扣后单价
  208. let unitPriceAfterDiscount=this.getIsNaN("unitPriceAfterDiscount",data);
  209. //折扣率
  210. if (unitPriceAfterDiscount > 0.0 && standardQuotation > 0.0) {
  211. //(成交金额/标准报价)100
  212. let discountRate = Number(((unitPriceAfterDiscount / standardQuotation) * 100).toFixed(2));
  213. data.discountRate = discountRate;
  214. }
  215. //计算折扣单价总和
  216. this.getUnitPriceAfterDiscountTotal();
  217. }
  218. /**
  219. * 计算折扣单价总和
  220. */
  221. getUnitPriceAfterDiscountTotal(){
  222. //折扣后单价总和
  223. let unitPriceAfterDiscountTotal=0.0;
  224. if(this.productList){
  225. this.productList.forEach(element => {
  226. unitPriceAfterDiscountTotal=unitPriceAfterDiscountTotal+Number(element.unitPriceAfterDiscount);
  227. });
  228. //放到主对象中
  229. this.contractFile.transactionAmount=unitPriceAfterDiscountTotal;
  230. //传给父级页面
  231. this.outContractFileObject();
  232. }
  233. }
  234. /**
  235. * 验证是否数字
  236. */
  237. getIsNaN(name,data) {
  238. if (!isNaN(Number(data[name]))) {
  239. return Number(data[name]);
  240. } else {
  241. return 0.0;
  242. }
  243. }
  244. close() {}
  245. }