update.component.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { Component, OnInit } from '@angular/core';
  2. import { NzModalRef, NzMessageService, NzNotificationService, NzDrawerRef } from 'ng-zorro-antd';
  3. import { _HttpClient, SettingsService } from '@delon/theme';
  4. import { FormBuilder, Validators, FormGroup } from '@angular/forms';
  5. import { DatePipe } from '@angular/common';
  6. import { ProjectManageArchivesService } from 'app/services/project-manage-archives/project-manage-archives.service';
  7. import { BaseArchivesCollectionLineService } from 'app/services/basedata/base-archives-collection-line.service';
  8. import { InvoiceManagePurchaseService } from 'app/services/invoice-management/invoice-manage-purchase.service';
  9. import { I18NService } from '@core';
  10. import { InvoiceManagePurchase } from 'app/entity/invoice-management/invoice-manage-purchase';
  11. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  12. import { BaseArchivesCollectionLine } from 'app/entity/basedata/base-archives-collection-line';
  13. @Component({
  14. selector: 'app-invoice-management-invoice-manage-purchase-update',
  15. templateUrl: './update.component.html',
  16. styles: [
  17. `
  18. .base {
  19. position: absolute;
  20. bottom: 0px;
  21. width: 100%;
  22. border-top: 1px solid rgb(232, 232, 232);
  23. padding: 6px 16px;
  24. text-align: right;
  25. left: 0px;
  26. background: #fff;
  27. z-index: 99;
  28. }
  29. `,
  30. ],
  31. })
  32. export class InvoiceManagementInvoiceManagePurchaseUpdateComponent implements OnInit {
  33. constructor(
  34. private fb: FormBuilder,
  35. private settingsService: SettingsService,
  36. private datePipe: DatePipe,
  37. private projectManageArchivesService: ProjectManageArchivesService,
  38. private baseArchivesCollectionLineService: BaseArchivesCollectionLineService,
  39. private nzNotificationService: NzNotificationService,
  40. private drawerRef: NzDrawerRef,
  41. private invoiceManagePurchaseService: InvoiceManagePurchaseService,
  42. private i18NService: I18NService,
  43. ) {}
  44. ngOnInit(): void {
  45. //初始化表单
  46. this.validateForm = this.fb.group({
  47. proArchivesId: [null, [Validators.required]],
  48. });
  49. //项目下拉数据
  50. this.isLoadingSave = true;
  51. this.getProList()
  52. .then(() => {
  53. //获取条线下拉数据
  54. return this.getCoArchivesList();
  55. }).then(()=>{
  56. //根据id查询
  57. return this.queryById();
  58. })
  59. .then(() => {
  60. this.isLoadingSave = false;
  61. });
  62. }
  63. validateForm!: FormGroup;
  64. invoiceManagePurchase: InvoiceManagePurchase = {
  65. }; //对象
  66. isLoadingSave = false;
  67. proList = []; //项目下拉数据
  68. itemDataList = []; //明细表格数据集合
  69. coArchivesList = []; //条线档案数据集合
  70. id = '';
  71. queryById() {
  72. return new Promise(resolve => {
  73. this.invoiceManagePurchaseService.queryById(this.id).then(response => {
  74. if(response.success){
  75. this.invoiceManagePurchase=response.result;//主表
  76. this.itemDataList=response.result.detailList;//子表数据
  77. if(this.itemDataList){//获取最大排序
  78. this.sort=this.itemDataList.length+1;
  79. }
  80. resolve();
  81. }else{
  82. resolve();
  83. }
  84. });
  85. });
  86. }
  87. /**
  88. * 获取项目下拉数据
  89. */
  90. getProList() {
  91. return new Promise(resolve => {
  92. let projectManageArchives = new ProjectManageArchives();
  93. projectManageArchives.pageSize = 20000;
  94. projectManageArchives.pkOrg = sessionStorage.getItem('pkOrg');
  95. this.projectManageArchivesService.getList(projectManageArchives).then(response => {
  96. if (response.result.records) {
  97. this.proList = response.result.records;
  98. }
  99. resolve();
  100. });
  101. });
  102. }
  103. /**
  104. * 获取条线下拉数据
  105. */
  106. getCoArchivesList() {
  107. return new Promise(resolve => {
  108. let baseArchivesCollectionLine = new BaseArchivesCollectionLine();
  109. baseArchivesCollectionLine.pageSize = 20000;
  110. baseArchivesCollectionLine.pkOrg = sessionStorage.getItem('pkOrg');
  111. this.baseArchivesCollectionLineService.getList(baseArchivesCollectionLine).then(response => {
  112. if (response.result.records) {
  113. this.coArchivesList = response.result.records;
  114. }
  115. resolve();
  116. });
  117. });
  118. }
  119. /**
  120. * 项目下拉选择事件
  121. */
  122. proChange(event) {
  123. if (event) {
  124. //根据id获取项目档案数据
  125. this.projectManageArchivesService.getListById(event).then(response => {
  126. if (response.success) {
  127. let project = JSON.parse(JSON.stringify(response.result)); //项目档案对象
  128. this.invoiceManagePurchase.proCode = project.proCode; //项目档案编码
  129. this.invoiceManagePurchase.proName = project.proName; //项目档案名称
  130. }
  131. });
  132. }
  133. }
  134. /**
  135. * 增行按钮
  136. */
  137. sort = 0;
  138. addRow() {
  139. this.itemDataList = [
  140. ...this.itemDataList,
  141. {
  142. price: '',
  143. uncoPrice: '',
  144. coPrice: '',
  145. sort: this.sort,
  146. },
  147. ];
  148. this.sort++;
  149. }
  150. /**
  151. * 删除行
  152. */
  153. deleteRow(sort) {
  154. this.itemDataList = this.itemDataList.filter(d => d.sort !== sort);
  155. }
  156. //金额格式化
  157. formatterDollar = (value: number) =>{
  158. if(value){
  159. return `$ ${value}`;
  160. }else{
  161. return `$ `;
  162. }
  163. };
  164. parserDollar = (value: string) => value.replace('$ ', '');
  165. /**
  166. * 提交保存按钮
  167. */
  168. submitForm(): any {
  169. return new Promise(resolve => {
  170. for (const i in this.validateForm.controls) {
  171. this.validateForm.controls[i].markAsDirty();
  172. this.validateForm.controls[i].updateValueAndValidity();
  173. }
  174. let valid = this.validateForm.valid;
  175. if (valid) {
  176. this.isLoadingSave = true;
  177. this.invoiceManagePurchase.type = '1'; //采购
  178. this.invoiceManagePurchase.pkOrg = sessionStorage.getItem('pkOrg');
  179. //子表保存数据处理
  180. if (this.itemDataList && this.itemDataList.length > 0) {
  181. this.itemDataList.forEach(element => {
  182. //获取条线名称
  183. if (element.coArchivesId) {
  184. this.coArchivesList.forEach(coArchives => {
  185. if (coArchives.id == element.coArchivesId) {
  186. element.coArchivesName = coArchives.name;
  187. }
  188. });
  189. } else {
  190. element.coArchivesName = '';
  191. }
  192. });
  193. } else {
  194. //是否填写明细数据
  195. this.nzNotificationService.warning('填写明细数据', '');
  196. this.isLoadingSave = false;
  197. return;
  198. }
  199. this.invoiceManagePurchase.detailList = this.itemDataList;
  200. this.invoiceManagePurchaseService.update(this.invoiceManagePurchase).then(response => {
  201. if (response.success) {
  202. //保存成功
  203. this.isLoadingSave = false;
  204. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  205. this.drawerRef.close(true);
  206. resolve();
  207. } else {
  208. //保存失败
  209. this.isLoadingSave = false;
  210. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  211. }
  212. });
  213. }
  214. });
  215. }
  216. close() {
  217. this.drawerRef.close();
  218. }
  219. }