123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- import { Component, OnInit, Output, EventEmitter } from '@angular/core';
- import { NzModalRef, NzMessageService, NzModalService } from 'ng-zorro-antd';
- import { _HttpClient } from '@delon/theme';
- import { BaseMaterialFileModularService } from 'app/services/basedata/base-material-file-modular.service';
- import { ContractFileProduct } from 'app/entity/contract-management/contract-file-product';
- import { ContractFile } from 'app/entity/contract-management/contract-file';
- import { RoutesSharedModalProdutSelectComponent } from 'app/routes/shared/modal/produt-select/produt-select.component';
- import { BaseMaterialFileModular } from 'app/entity/basedata/base-material-file-modular';
- @Component({
- selector: 'app-contract-management-contract-file-update-product-module',
- templateUrl: './product-module.component.html',
- })
- export class ContractManagementContractFileUpdateProductModuleComponent implements OnInit {
- constructor(
- private modalService:NzModalService,
- private baseMaterialFileModularService:BaseMaterialFileModularService
- ) {}
- ngOnInit(): void {}
- productList: ContractFileProduct[] = []; //产品数据
- // moduleList:ContractFileModular[]=[];//模块数据
- formatterDollar = (value: number): string => `¥ ${value}`;
- parserDollar = (value: string): string => value.replace('¥ ', '');
- formatterDollar2 = (value: number): string => `${value}%`;
- parserDollar2 = (value: string): string => value.replace('%', '');
- /**
- * 产品新增行
- */
- prouctI = 0;
- productAddRow() {
- this.productList = [
- ...this.productList,
- {
- id: `${this.prouctI}`,
- code: '',
- name: '',
- discountRate: 0,
- standardQuotation: 0,
- unitPriceAfterDiscount: 0,
- standardAmount: 0,
- amountAfterDiscount: 0,
- costUnitPrice: 0,
- costAmount: 0,
- contractFileModularList: [],
- },
- ];
- this.prouctI++;
- }
- /**
- * 产品删除行
- */
- productDeleteRow(data) {
- this.productList = this.productList.filter(d => d.id !== data.id);
- //计算折扣单价总和
- this.getUnitPriceAfterDiscountTotal();
- //计算标准报价
- this.standardQuotationModuleKeyUp(data)
- }
- /**
- * 模块新增行
- */
- moduleI = 0;
- moduleAddRow(product) {
- product.contractFileModularList = [
- ...product.contractFileModularList,
- {
- id: `${this.moduleI}`,
- code: '',
- name: '',
- standardQuotation: 0,
- purchasePrice: 0,
- },
- ];
- this.moduleI++;
- }
- /**
- * 模块删除行
- */
- moduleDeleteRow(product, id) {
- product.contractFileModularList = product.contractFileModularList.filter(d => d.id !== id);
- //计算标准报价
- this.standardQuotationModuleKeyUp(product)
- }
- /**
- * 模块标准报价键盘弹起事件
- * @param product 产品对象
- */
- standardQuotationModuleKeyUp(product) {
- //判断当前产品下是否存在模块
- if (product && product.contractFileModularList) {
- let standardQuotationTotal = 0.0; //定义模块中标准报价总计
- //循环模块
- product.contractFileModularList.forEach(element => {
- //判断标准报价是否为数字
- if (!isNaN(Number(element.standardQuotation))) {
- //累加
- standardQuotationTotal = standardQuotationTotal + Number(element.standardQuotation);
- }
- });
- //把模块标准报价总和赋值给产品的标准报价
- product.standardQuotation = standardQuotationTotal;
- //获取品总标准报价并传入基本信息
- this.getContractFileStandardQuotationTotal();
- }
- }
- /**
- * 获取合同总共的标准报价
- */
- getContractFileStandardQuotationTotal() {
- if (this.productList) {
- let standardQuotationProductTotal = 0.0; //定义产品中标准报价总计
- this.productList.forEach(element => {
- //判断标准报价是否为数字
- if (!isNaN(Number(element.standardQuotation))) {
- //累加
- standardQuotationProductTotal = standardQuotationProductTotal + Number(element.standardQuotation);
- }
- });
- //把产品的总标准报价给合同标准报价
- this.contractFile.standardQuotation = standardQuotationProductTotal;
- //传给基本信息
- this.outContractFileObject();
- }
- }
- contractFile: ContractFile = {}; //合同的对象
- /**
- * 获取当前页面的相关信息传个父级页面
- */
- @Output() contractFileObject = new EventEmitter<{}>();
- outContractFileObject() {
- this.contractFileObject.emit(this.contractFile);
- }
- /**
- * 选择产品事件
- */
- selectProdutModal(product) {
- const modalRef = this.modalService.create({
- nzTitle: '选择产品',
- nzContent: RoutesSharedModalProdutSelectComponent,
- nzWidth: 1400,
- nzFooter: [
- {
- label: '关闭',
- type: 'default',
- onClick: addModel => {
- addModel.close();
- },
- },
- {
- label: '确定',
- type: 'primary',
- onClick: addModel => {
- addModel.save().then(()=>{
- product.code=addModel.selectObj[0].code
- product.name=addModel.selectObj[0].name
- product.baseMaterialFileProductId=addModel.selectObj[0].id
- //获取产品下的模块数据下拉供模块表格选择
- this.getModuleListByPid(product);
- });
- },
- },
- ],
- });
- }
- /**
- * 根据产品id查询所属模块集合(供模块表格下拉选择)
- */
- getModuleListByPid(product){
- return new Promise((resolve)=>{
- let baseMaterialFileModular=new BaseMaterialFileModular();
- baseMaterialFileModular.baseMaterialFileProductId=product.baseMaterialFileProductId;
- //查询当前选择产品的模块
- this.baseMaterialFileModularService.list(baseMaterialFileModular).then((response)=>{
- //放入产品对象中
- if(response.success){
- product.modularListSelect=JSON.parse(JSON.stringify(response.result.records))
- }
- resolve();
- })
- })
- }
- /**
- * 模块选择触发事件
- * 获取编码和名称
- */
- baseMaterialFileModularIdChange(product,data,event){
- if(event){
- product.modularListSelect.forEach(element => {
- if(event==element.id){
- data.code=element.code;
- data.name=element.name;
- data.standardQuotation=element.standardQuotation;
- }
- });
- }else{
- data.code="";
- data.name="";
- }
- //计算标准报价
- this.standardQuotationModuleKeyUp(product)
- }
- /**
- * 折扣后单价改变事件
- */
- unitPriceAfterDiscountBlur(data){
- //标准报价
- let standardQuotation=this.getIsNaN("standardQuotation",data);
- //折扣后单价
- let unitPriceAfterDiscount=this.getIsNaN("unitPriceAfterDiscount",data);
- //折扣率
- if (unitPriceAfterDiscount > 0.0 && standardQuotation > 0.0) {
- //(成交金额/标准报价)100
- let discountRate = Number(((unitPriceAfterDiscount / standardQuotation) * 100).toFixed(2));
- data.discountRate = discountRate;
- }
- //计算折扣单价总和
- this.getUnitPriceAfterDiscountTotal();
- }
- /**
- * 计算折扣单价总和
- */
- getUnitPriceAfterDiscountTotal(){
- //折扣后单价总和
- let unitPriceAfterDiscountTotal=0.0;
- if(this.productList){
- this.productList.forEach(element => {
- unitPriceAfterDiscountTotal=unitPriceAfterDiscountTotal+Number(element.unitPriceAfterDiscount);
- });
- //放到主对象中
- this.contractFile.transactionAmount=unitPriceAfterDiscountTotal;
- //传给父级页面
- this.outContractFileObject();
- }
- }
- /**
- * 验证是否数字
- */
- getIsNaN(name,data) {
- if (!isNaN(Number(data[name]))) {
- return Number(data[name]);
- } else {
- return 0.0;
- }
- }
- close() {}
- }
|