add.component.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import { Component, OnInit } from '@angular/core';
  2. import { NzModalRef, NzMessageService, NzNotificationService, NzDrawerRef } from 'ng-zorro-antd';
  3. import { _HttpClient } from '@delon/theme';
  4. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  5. import { ManagerPaymentAndReceiptSlip } from 'app/entity/down-payment-management/manager-payment-and-receipt-slip';
  6. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  7. import { ProjectManageArchivesService } from 'app/services/project-manage-archives/project-manage-archives.service';
  8. import { ManagerPaymentAndReceiptSlipService } from 'app/services/down-payment-management/manager-payment-and-receipt-slip.service';
  9. import { I18NService } from '@core';
  10. import { InvoiceManagePurchase } from 'app/entity/invoice-management/invoice-manage-purchase';
  11. import { InvoiceManagePurchaseService } from 'app/services/invoice-management/invoice-manage-purchase.service';
  12. @Component({
  13. selector: 'app-down-payment-management-receipt-add',
  14. templateUrl: './add.component.html',
  15. styles: [
  16. `
  17. .base {
  18. position: absolute;
  19. bottom: 0px;
  20. width: 100%;
  21. border-top: 1px solid rgb(232, 232, 232);
  22. padding: 6px 16px;
  23. text-align: right;
  24. left: 0px;
  25. background: #fff;
  26. z-index: 99;
  27. }
  28. `,
  29. ],
  30. })
  31. export class DownPaymentManagementReceiptAddComponent implements OnInit {
  32. constructor(
  33. private fb: FormBuilder,
  34. private projectManageArchivesService: ProjectManageArchivesService,
  35. private managerPaymentAndReceiptSlipService: ManagerPaymentAndReceiptSlipService,
  36. private nzNotificationService: NzNotificationService,
  37. private i18NService: I18NService,
  38. private drawerRef: NzDrawerRef,
  39. private invoiceManagePurchaseService:InvoiceManagePurchaseService
  40. ) {}
  41. ngOnInit(): void {
  42. //初始化表单
  43. this.validateForm = this.fb.group({
  44. proId: [null, [Validators.required]],
  45. });
  46. this.isLoadingSave = true;
  47. //项目下拉数据
  48. this.getProList().then(() => {
  49. this.isLoadingSave = false;
  50. });
  51. }
  52. validateForm!: FormGroup;
  53. managerPaymentAndReceiptSlip: ManagerPaymentAndReceiptSlip = {}; //对象
  54. isLoadingSave = false;
  55. proList = []; //项目下拉数据
  56. proArchivesList = []; //里程碑下拉数据
  57. coArchivesList = []; //条线下拉数据
  58. invoiceIdList = []; //发票数据集合
  59. //金额格式化
  60. formatterDollar = (value: number) => {
  61. if (value) {
  62. return `$ ${value}`;
  63. } else {
  64. return `$ `;
  65. }
  66. };
  67. parserDollar = (value: string) => value.replace('$ ', '');
  68. /**
  69. * 获取销售发票下拉数据
  70. */
  71. getInvoiceIdList(){
  72. return new Promise((resolve)=>{
  73. let invoiceManagePurchase=new InvoiceManagePurchase();
  74. invoiceManagePurchase.pageSize=20000;
  75. invoiceManagePurchase.type="2";
  76. invoiceManagePurchase.pkOrg=sessionStorage.getItem("pkOrg");
  77. invoiceManagePurchase.proArchivesId=this.managerPaymentAndReceiptSlip.proId;//项目id
  78. this.invoiceManagePurchaseService.getList(invoiceManagePurchase).then((response)=>{
  79. if(response.success){
  80. this.invoiceIdList=response.result.records
  81. }
  82. resolve();
  83. })
  84. })
  85. }
  86. /**
  87. * 获取项目下拉数据
  88. */
  89. getProList() {
  90. return new Promise(resolve => {
  91. let projectManageArchives = new ProjectManageArchives();
  92. projectManageArchives.pageSize = 20000;
  93. projectManageArchives.pkOrg = sessionStorage.getItem('pkOrg');
  94. this.projectManageArchivesService.getList(projectManageArchives).then(response => {
  95. if (response.result.records) {
  96. this.proList = response.result.records;
  97. }
  98. resolve();
  99. });
  100. });
  101. }
  102. /**
  103. * 项目下拉选择事件
  104. */
  105. proChange(event) {
  106. if (event) {
  107. //根据id获取项目档案数据
  108. this.projectManageArchivesService.getListById(event).then(response => {
  109. if (response.success) {
  110. let project = JSON.parse(JSON.stringify(response.result)); //项目档案对象
  111. this.managerPaymentAndReceiptSlip.proCode = project.proCode; //项目档案编码
  112. this.managerPaymentAndReceiptSlip.proName = project.proName; //项目档案名称
  113. this.managerPaymentAndReceiptSlip.cusId = project.cusId; //客户id
  114. this.managerPaymentAndReceiptSlip.cusCode = project.cusCode; //客户编码
  115. this.managerPaymentAndReceiptSlip.cusName = project.cusName; //客户名称
  116. //获取条线下拉数据
  117. this.getLineList();
  118. //获取发票下拉数据
  119. this.getInvoiceIdList()
  120. }
  121. });
  122. }
  123. }
  124. //获取条线下拉数据
  125. getLineList() {
  126. //查询条件
  127. let projectManageArchives = { proArchivesId: this.managerPaymentAndReceiptSlip.proId, planType: '2' };
  128. this.projectManageArchivesService.getLineList(projectManageArchives).then(response => {
  129. if (response.success) {
  130. this.coArchivesList = response.result;
  131. }
  132. });
  133. }
  134. /**
  135. * 条件选择事件
  136. * 获取条线名称、获取里程碑数据
  137. */
  138. coArchivesIdChange(data) {
  139. if (data.coArchivesId) {
  140. //获取条线名称
  141. this.coArchivesList.forEach(element => {
  142. if (data.coArchivesId === element.id) {
  143. data.coArchivesName = element.planName;
  144. }
  145. });
  146. // //获取里程碑下拉数据
  147. this.getMilList(data);
  148. }
  149. }
  150. /**
  151. * 获取里程碑下拉数据
  152. */
  153. getMilList(data) {
  154. //获取里程碑下拉数据
  155. let where = { businessId: data.coArchivesId };
  156. this.projectManageArchivesService.getMileNameById(where).then(response => {
  157. if (response.success) {
  158. data.proArchivesIdList = response.result;
  159. //一般用于选择完里程碑又反过来选条线 则重新获取金额
  160. if(data.proArchivesId){
  161. this.proBusinessChange(data);
  162. }
  163. }
  164. });
  165. }
  166. /**
  167. * 里程碑选择事件
  168. */
  169. proBusinessChange(data) {
  170. if (data.proArchivesId) {
  171. data.proArchivesIdList.forEach(element => {
  172. if (element.mileId === data.proArchivesId) {
  173. data.proArchivesMilestone = element.mileName; //名称
  174. data.coPrvice = element.price; //金额
  175. }
  176. });
  177. //计算总金额
  178. this.getCoPrviceTotal();
  179. }
  180. }
  181. itemDataList = []; //子表明细集合
  182. /**
  183. * 增行按钮
  184. */
  185. sort = 0;
  186. addRow() {
  187. this.itemDataList = [
  188. ...this.itemDataList,
  189. {
  190. price: '',
  191. uncoPrice: '',
  192. coPrice: '',
  193. sort: this.sort,
  194. },
  195. ];
  196. this.sort++;
  197. }
  198. /**
  199. * 删除行
  200. */
  201. deleteRow(sort) {
  202. this.itemDataList = this.itemDataList.filter(d => d.sort !== sort);
  203. //计算总金额
  204. this.getCoPrviceTotal();
  205. }
  206. /**
  207. * 金额填写事件
  208. */
  209. coPrviceKeyUp() {
  210. //计算总金额
  211. this.getCoPrviceTotal();
  212. }
  213. /**
  214. * 获取收款金额合计
  215. */
  216. getCoPrviceTotal() {
  217. //判断是否有值
  218. if (!this.itemDataList) {
  219. return;
  220. }
  221. //获取所有金额总计
  222. let coPrviceTotal = 0;
  223. this.itemDataList.forEach(element => {
  224. if (element.coPrvice && !isNaN(Number(element.coPrvice))) {
  225. coPrviceTotal = coPrviceTotal + Number(element.coPrvice);
  226. }
  227. });
  228. this.managerPaymentAndReceiptSlip.totalPrice = coPrviceTotal;
  229. }
  230. /**
  231. * 保存提交
  232. */
  233. submitForm(): any {
  234. return new Promise(resolve => {
  235. for (const i in this.validateForm.controls) {
  236. this.validateForm.controls[i].markAsDirty();
  237. this.validateForm.controls[i].updateValueAndValidity();
  238. }
  239. let valid = this.validateForm.valid;
  240. if (valid) {
  241. this.managerPaymentAndReceiptSlip.type = '1'; //收款表
  242. this.managerPaymentAndReceiptSlip.pkOrg = sessionStorage.getItem('pkOrg'); //公司组织
  243. this.managerPaymentAndReceiptSlip.detailList = this.itemDataList;
  244. //子表数据处理
  245. if(this.itemDataList&&this.itemDataList.length>0){
  246. this.itemDataList.forEach(element => {
  247. //获取发票下拉中选中的名称
  248. if(element.invoiceId){
  249. this.invoiceIdList.forEach(invoice => {
  250. if(invoice.id===element.invoiceId){
  251. element.invoice=invoice.billcode;
  252. }
  253. });
  254. }
  255. });
  256. }else {
  257. this.nzNotificationService.warning('明细数据必填', '');
  258. this.isLoadingSave=false;
  259. return;
  260. }
  261. this.managerPaymentAndReceiptSlipService.add(this.managerPaymentAndReceiptSlip).then(response => {
  262. if (response.success) {
  263. //保存成功
  264. this.isLoadingSave = false;
  265. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  266. this.drawerRef.close(true);
  267. resolve();
  268. } else {
  269. //保存失败
  270. this.isLoadingSave = false;
  271. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  272. }
  273. });
  274. }
  275. });
  276. }
  277. close() {
  278. this.drawerRef.close();
  279. }
  280. }