update.component.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 { PersonnelService } from 'app/services/basedata/personnel.service';
  6. import { ProjectManageArchivesService } from 'app/services/project-manage-archives/project-manage-archives.service';
  7. import { BaseArchivesCostService } from 'app/services/basedata/base-archives-cost.service';
  8. import { ReExpenseSlipService } from 'app/services/expense-reimbursement/re-expense-slip.service';
  9. import { I18NService } from '@core';
  10. import { DatePipe } from '@angular/common';
  11. import { ReExpenseSlip } from 'app/entity/expense-reimbursement/re-expense-slip';
  12. import { recursiveQuery } from '@shared';
  13. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  14. import { BaseArchivesCost } from 'app/entity/basedata/base-archives-cost';
  15. @Component({
  16. selector: 'app-expense-reimbursement-expense-reimbursement-form-update',
  17. templateUrl: './update.component.html',
  18. styles: [
  19. `
  20. .base {
  21. position: absolute;
  22. bottom: 0px;
  23. width: 100%;
  24. border-top: 1px solid rgb(232, 232, 232);
  25. padding: 6px 16px;
  26. text-align: right;
  27. left: 0px;
  28. background: #fff;
  29. z-index: 99;
  30. }
  31. `,
  32. ],
  33. })
  34. export class ExpenseReimbursementExpenseReimbursementFormUpdateComponent implements OnInit {
  35. constructor(
  36. private fb: FormBuilder,
  37. private personnelService: PersonnelService,
  38. private projectManageArchivesService: ProjectManageArchivesService,
  39. private settingsService: SettingsService,
  40. private baseArchivesCostService: BaseArchivesCostService,
  41. private nzNotificationService:NzNotificationService,
  42. private reExpenseSlipService:ReExpenseSlipService,
  43. private i18NService:I18NService,
  44. private drawerRef:NzDrawerRef,
  45. private datePipe:DatePipe
  46. ) {}
  47. ngOnInit(): void {
  48. //初始化表单
  49. this.validateForm = this.fb.group({
  50. proId: [null, [Validators.required]],
  51. date: [null, [Validators.required]],
  52. personId: [null, [Validators.required]],
  53. });
  54. this.isLoadingSave=true;
  55. //人员
  56. this.getPersonnelList().then(() => {
  57. return this.getProList(); //项目下拉
  58. }).then(()=>{
  59. return this.getCostIdList();//费用项目数据
  60. }).then(()=>{
  61. return this.getListById();//根据id查询
  62. }).then(()=>{
  63. this.isLoadingSave=false;
  64. });
  65. }
  66. isLoadingSave = false;
  67. validateForm!: FormGroup;
  68. reExpenseSlip: ReExpenseSlip = {
  69. producer: this.settingsService.user.realname,
  70. }; //对象
  71. proList = []; //项目集合
  72. personnelList = []; //人员集合
  73. id="";
  74. /**
  75. * 根据id查询主子表数据
  76. */
  77. getListById(){
  78. return new Promise((resolve)=>{
  79. this.reExpenseSlipService.getListById(this.id).then((response)=>{
  80. this.reExpenseSlip=response.result;//主表
  81. this.itemDataList=response.result.detailList;//子表明细
  82. if(this.itemDataList){
  83. this.sort=this.itemDataList.length+1;
  84. }
  85. resolve();
  86. })
  87. })
  88. }
  89. /**
  90. * 获取人员下拉数据到各个页签中
  91. */
  92. getPersonnelList() {
  93. return new Promise(resolve => {
  94. this.personnelService.queryApprover(sessionStorage.getItem('pkOrg')).then(response => {
  95. //人员
  96. this.personnelList = JSON.parse(JSON.stringify(response.result));
  97. recursiveQuery(this.personnelList);
  98. resolve();
  99. });
  100. });
  101. }
  102. /**
  103. * 获取项目下拉数据
  104. */
  105. getProList() {
  106. return new Promise(resolve => {
  107. //查询条件
  108. let projectManageArchives = new ProjectManageArchives();
  109. projectManageArchives.pageSize = 20000;
  110. projectManageArchives.pkOrg = sessionStorage.getItem('pkOrg');
  111. //查询
  112. this.projectManageArchivesService.getList(projectManageArchives).then(response => {
  113. if (response.result.records) {
  114. this.proList = response.result.records;
  115. }
  116. resolve();
  117. });
  118. });
  119. }
  120. /**
  121. * 增行按钮
  122. */
  123. itemDataList = []; //明细集合
  124. sort = 0;
  125. addRow() {
  126. this.itemDataList = [
  127. ...this.itemDataList,
  128. {
  129. price: '',
  130. uncoPrice: '',
  131. coPrice: '',
  132. sort: this.sort,
  133. },
  134. ];
  135. this.sort++;
  136. }
  137. /**
  138. * 删除行
  139. */
  140. deleteRow(sort) {
  141. this.itemDataList = this.itemDataList.filter(d => d.sort !== sort);
  142. }
  143. //金额格式化
  144. formatterDollar = (value: number) => {
  145. if (value) {
  146. return `$ ${value}`;
  147. } else {
  148. return `$ `;
  149. }
  150. };
  151. parserDollar = (value: string) => value.replace('$ ', '');
  152. /**
  153. * 查询费用档案数据
  154. */
  155. costIdList = []; //费用项目下拉数据集合
  156. getCostIdList() {
  157. return new Promise(resolve => {
  158. let baseArchivesCost = new BaseArchivesCost();
  159. baseArchivesCost.pkOrg = sessionStorage.getItem('pkOrg'); //组织
  160. baseArchivesCost.pageSize = 20000;
  161. this.baseArchivesCostService.getList(baseArchivesCost).then(response => {
  162. this.costIdList = response.result.records;
  163. resolve();
  164. });
  165. });
  166. }
  167. /**
  168. * 保存提交
  169. */
  170. submitForm(): any {
  171. return new Promise(resolve => {
  172. for (const i in this.validateForm.controls) {
  173. this.validateForm.controls[i].markAsDirty();
  174. this.validateForm.controls[i].updateValueAndValidity();
  175. }
  176. let valid = this.validateForm.valid;
  177. if(valid){
  178. this.isLoadingSave=true;
  179. this.reExpenseSlip.pkOrg=sessionStorage.getItem("pkOrg");//组织
  180. //日期
  181. this.reExpenseSlip.date = this.datePipe.transform(this.reExpenseSlip.date, 'yyyy-MM-dd HH:mm:ss');
  182. //人员名称
  183. if (this.reExpenseSlip.personId) {
  184. //循环集合数据获取名称
  185. this.personnelList.forEach(pkOrg => {
  186. pkOrg.children.forEach(depart => {
  187. depart.children.forEach(personnel => {
  188. if (personnel.key === this.reExpenseSlip.personId) {
  189. this.reExpenseSlip.person = personnel.name;
  190. }
  191. });
  192. });
  193. });
  194. }
  195. //项目名称
  196. if(this.reExpenseSlip.proId){
  197. this.proList.forEach(element => {
  198. if(element.id===this.reExpenseSlip.proId){
  199. this.reExpenseSlip.proName=element.proName;
  200. }
  201. });
  202. }
  203. //明细
  204. if(this.itemDataList){
  205. this.itemDataList.forEach(element => {
  206. //获取明细中下拉选择的费用项目名称
  207. if(element.costId){
  208. this.costIdList.forEach(cost => {
  209. if(cost.id===element.costId){
  210. element.costName=cost.name;
  211. }
  212. });
  213. }else{
  214. element.costName="";
  215. }
  216. });
  217. //获取明细数据
  218. this.reExpenseSlip.detailList=this.itemDataList;
  219. }else{
  220. this.nzNotificationService.warning('费用项目必填', '');
  221. this.isLoadingSave=false;
  222. return;
  223. }
  224. this.reExpenseSlipService.update(this.reExpenseSlip).then((response)=>{
  225. if (response.success) {
  226. //保存成功
  227. this.isLoadingSave = false;
  228. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  229. this.drawerRef.close(true);
  230. resolve();
  231. } else {
  232. //保存失败
  233. this.isLoadingSave = false;
  234. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  235. }
  236. })
  237. }
  238. });
  239. }
  240. close() {
  241. this.drawerRef.close();
  242. }
  243. }