essential-information.component.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. import { Component, OnInit, Output, EventEmitter } from '@angular/core';
  2. import { NzModalRef, NzMessageService, NzModalService } from 'ng-zorro-antd';
  3. import { _HttpClient, SettingsService } from '@delon/theme';
  4. import { FormGroup, Validators, FormBuilder } from '@angular/forms';
  5. import { ContractFile } from 'app/entity/contract-management/contract-file';
  6. import { BaseArchivesProjectApproval } from 'app/entity/basedata/base-archives-project-approval';
  7. import { BaseArchivesProjectApprovalService } from 'app/services/basedata/base-archives-project-approval.service';
  8. import { DictService } from 'app/services/dict.service';
  9. import { BasedataCustomerModalTableComponent } from 'app/routes/basedata/customer/modal-table/modal-table.component';
  10. import { CustomerService } from 'app/services/basedata/customer.service';
  11. import { DatePipe } from '@angular/common';
  12. import { RoutesSharedModalCustomerSelectComponent } from 'app/routes/shared/modal/customer-select/customer-select.component';
  13. @Component({
  14. selector: 'app-contract-management-contract-file-add-essential-information',
  15. templateUrl: './essential-information.component.html',
  16. })
  17. export class ContractManagementContractFileAddEssentialInformationComponent implements OnInit {
  18. constructor(
  19. private fb: FormBuilder,
  20. private modalService: NzModalService,
  21. private customerService: CustomerService,
  22. private settingsService: SettingsService,
  23. private datePipe:DatePipe
  24. ) {}
  25. validateForm!: FormGroup;
  26. ngOnInit(): void {
  27. //初始化表单
  28. this.validateForm = this.fb.group({
  29. proId: [null, [Validators.required]],
  30. overview: [],
  31. businessTypeDictId: [],
  32. fdCustomerName: [null, [Validators.required]],
  33. fdCustomerPersonnelId: [null, [Validators.required]],
  34. fdCustomeraddress: [],
  35. fdCustomerPersonnelTel: [],
  36. salesmanId: [null, [Validators.required]],
  37. freeAfterSalesStart: [null, [Validators.required]],
  38. freeAfterSalesEnd: [null, [Validators.required]],
  39. standardQuotation: [],
  40. transactionAmount: [],
  41. discountRate: [],
  42. giftAmount: [],
  43. cost: [],
  44. contractCost: [],
  45. contractProfit: [],
  46. accountsReceivable: [],
  47. performanceCalculationRate: [],
  48. milestoneId: [],
  49. received: [],
  50. contractDate:[null, [Validators.required]]
  51. });
  52. }
  53. user=this.settingsService.user//当前登录用户信息
  54. contractFile: ContractFile = {
  55. standardQuotation: 0,
  56. transactionAmount: 0,
  57. discountRate: 0,
  58. giftAmount: 0,
  59. cost: 0,
  60. contractCost: 0,
  61. contractProfit: 0,
  62. accountsReceivable: 0,
  63. performanceCalculationRate: 0,
  64. received: 0,
  65. createBy:this.user.realname,
  66. createTime:this.datePipe.transform(new Date(), 'yyyy-MM-dd HH:mm:ss')
  67. }; //合同对象
  68. proList: any = []; //项目下拉集合
  69. businessTypeDictList: any = []; //业务类型集合
  70. salesStaffList: any = []; //销售人员tree下拉数据
  71. formatterDollar = (value: number): string => `¥ ${value}`;
  72. parserDollar = (value: string): string => value.replace('¥ ', '');
  73. milestoneList: any = []; //里程碑类型
  74. formatterDollar2 = (value: number): string => `${value}%`;
  75. parserDollar2 = (value: string): string => value.replace('%', '');
  76. /**
  77. * 项目名称下拉款触发事件
  78. */
  79. proChange(event) {
  80. if (!event) {
  81. this.contractFile.proId = '';
  82. }
  83. }
  84. /**
  85. * 客户选择
  86. */
  87. modalTable() {
  88. const modalRef = this.modalService.create({
  89. nzTitle: '选择客户',
  90. nzContent: RoutesSharedModalCustomerSelectComponent,
  91. nzWidth: 1400,
  92. nzFooter: [
  93. {
  94. label: '关闭',
  95. type: 'default',
  96. onClick: addModel => {
  97. addModel.handleCancel();
  98. },
  99. },
  100. {
  101. label: '确定',
  102. type: 'primary',
  103. onClick: addModel => {
  104. addModel.handleOk();
  105. // addModel.selectObj 包含勾选项的 id 和 name
  106. this.contractFile.fdCustomerName = addModel.selectObj[0].name;
  107. this.contractFile.fdCustomerId = addModel.selectObj[0].id;
  108. //查询客户的联系人
  109. this.getLdCustomerPersonnelList();
  110. },
  111. },
  112. ],
  113. });
  114. }
  115. /**
  116. * 根据客户获取客户人员数据
  117. */
  118. fdCustomerPersonnelList: any = [];
  119. getLdCustomerPersonnelList() {
  120. return new Promise(resolve => {
  121. this.customerService.getContactsByMainId(this.contractFile.fdCustomerId).then(response => {
  122. this.fdCustomerPersonnelList = response.result;
  123. resolve();
  124. });
  125. });
  126. }
  127. /**
  128. * 客户人员选择事件
  129. */
  130. fdCustomerPersonnelChange(event) {
  131. if (event) {
  132. this.fdCustomerPersonnelList.forEach(element => {
  133. if (element.id == event) {
  134. this.contractFile.fdCustomerPersonnelTel = element.contectTel;
  135. }
  136. });
  137. } else {
  138. this.contractFile.fdCustomerPersonnelId = '';
  139. this.contractFile.fdCustomerPersonnelTel = '';
  140. }
  141. }
  142. /**
  143. * 业务类型选择事件
  144. */
  145. businessTypeDictIdChange(event) {
  146. if (!event) {
  147. this.contractFile.businessTypeDictId = '';
  148. }
  149. }
  150. /**
  151. * 销售人员选择时间
  152. * @param event
  153. */
  154. onChangeSalesmanId(event) {
  155. if (event) {
  156. //获取人员名称
  157. this.salesStaffList.forEach(pkOrg => {
  158. pkOrg.children.forEach(depart => {
  159. depart.children.forEach(personnel => {
  160. if (personnel.key === event) {
  161. this.contractFile.salesmanName = personnel.name;
  162. }
  163. });
  164. });
  165. });
  166. } else {
  167. this.contractFile.salesmanName = '';
  168. }
  169. }
  170. /**
  171. * 免费售后起始
  172. */
  173. disabledDate = (current: Date): boolean => {
  174. // Can not select days before today and today
  175. if (this.contractFile.freeAfterSalesEnd) {
  176. let end = new Date(this.contractFile.freeAfterSalesEnd); //结束时间
  177. //开始时间大于结束时间的禁用
  178. return current.getTime() > end.getTime();
  179. } else {
  180. return false;
  181. }
  182. };
  183. /**
  184. * 免费售后截至
  185. */
  186. disabledDate2 = (current: Date): boolean => {
  187. // Can not select days before today and today
  188. if (this.contractFile.freeAfterSalesStart) {
  189. let start = new Date(this.contractFile.freeAfterSalesStart); //开始时间
  190. //结束时间小于开始时间禁用
  191. return current.getTime() < start.getTime();
  192. } else {
  193. return false;
  194. }
  195. };
  196. /**
  197. * 里程碑类型选择事件
  198. */
  199. //回写里程碑类型到其他页签查询明细
  200. @Output() milestone = new EventEmitter<{}>();
  201. milestoneChange(event) {
  202. if (event) {
  203. // this.milestoneList.forEach(element => {
  204. // if (element.value === event) {
  205. // this.projectManageArchivesa.milestoneType = element.text;
  206. // }
  207. // });
  208. this.milestone.emit(this.contractFile);
  209. }
  210. }
  211. /**
  212. * 成交金额改变事件
  213. */
  214. transactionAmountBlur() {
  215. //计算折扣率
  216. this.calculation();
  217. //计算应收金额
  218. this.calculationAccountsReceivable();
  219. }
  220. /**
  221. * 计算折扣率
  222. */
  223. calculation() {
  224. /**计算折扣率*/
  225. //标准报价
  226. let standardQuotation = this.getIsNaN('standardQuotation');
  227. //成交金额
  228. let transactionAmount = this.getIsNaN('transactionAmount');
  229. //折扣率
  230. if (transactionAmount > 0.0 && standardQuotation > 0.0) {
  231. //(成交金额/标准报价)100
  232. let discountRate = Number(((transactionAmount / standardQuotation) * 100).toFixed(2));
  233. this.contractFile.discountRate = discountRate;
  234. }
  235. //计算合同利润
  236. this.calculationContractProfit();
  237. }
  238. /**
  239. * 成本改变事件
  240. */
  241. costBlur() {
  242. //计算合同利润
  243. this.calculationContractProfit();
  244. }
  245. /**
  246. * 合同费用改变事件
  247. */
  248. contractCostBlur() {
  249. //计算合同利润
  250. this.calculationContractProfit();
  251. }
  252. /**
  253. * 计算合同利润
  254. */
  255. calculationContractProfit() {
  256. //成交金额
  257. let transactionAmount = this.getIsNaN('transactionAmount');
  258. //成本
  259. let cost = this.getIsNaN('cost');
  260. //合同费用
  261. let contractCost = this.getIsNaN('contractCost');
  262. //合同利润
  263. if (transactionAmount > 0.0) {
  264. //成交金额-成本-合同费用
  265. let contractProfit = transactionAmount - cost - contractCost;
  266. this.contractFile.contractProfit = contractProfit;
  267. }
  268. }
  269. /**
  270. * 计算应收款账
  271. */
  272. calculationAccountsReceivable(){
  273. //成交金额
  274. let transactionAmount = this.getIsNaN('transactionAmount');
  275. //回款金额
  276. let received=this.getIsNaN("received");
  277. //计算应收金额
  278. if(transactionAmount>0.0){
  279. //成交金额-回款金额
  280. this.contractFile.accountsReceivable=transactionAmount-received;
  281. }
  282. }
  283. /**
  284. * 验证是否数字
  285. */
  286. getIsNaN(name) {
  287. if (!isNaN(Number(this.contractFile[name]))) {
  288. return Number(this.contractFile[name]);
  289. } else {
  290. return 0.0;
  291. }
  292. }
  293. submitForm() {
  294. for (const i in this.validateForm.controls) {
  295. this.validateForm.controls[i].markAsDirty();
  296. this.validateForm.controls[i].updateValueAndValidity();
  297. }
  298. let valid = this.validateForm.valid;
  299. return valid;
  300. }
  301. close() {}
  302. }