update.component.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 { ProjectManageArchivesService } from 'app/services/project-manage-archives/project-manage-archives.service';
  6. import { DatePipe } from '@angular/common';
  7. import { ProWorkMilestoneService } from 'app/services/project-work/pro-work-milestone.service';
  8. import { I18NService } from '@core';
  9. import { environment } from '@env/environment';
  10. import { ProWorkMilestone } from 'app/entity/project-work/pro-work-milestone';
  11. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  12. @Component({
  13. selector: 'app-project-work-product-confirmation-update',
  14. templateUrl: './update.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 ProjectWorkProductConfirmationUpdateComponent implements OnInit {
  32. constructor(
  33. private fb: FormBuilder,
  34. private projectManageArchivesService: ProjectManageArchivesService,
  35. private datePipe: DatePipe,
  36. private proWorkMilestoneService: ProWorkMilestoneService,
  37. private nzNotificationService: NzNotificationService,
  38. private i18NService: I18NService,
  39. private drawerRef: NzDrawerRef,
  40. private settingsService: SettingsService,
  41. ) {}
  42. ngOnInit(): void {
  43. //初始化表单
  44. this.validateForm = this.fb.group({
  45. proId: [null, [Validators.required]],
  46. mileId: [null, [Validators.required]],
  47. milSwitch: [null],
  48. confirmTime: [null, [Validators.required]],
  49. });
  50. //项目集合
  51. this.getProList().then(() => {});
  52. this.getById();
  53. }
  54. /**
  55. * 根据id查询数据
  56. */
  57. getById() {
  58. this.isLoadingSave=true;
  59. this.proWorkMilestoneService.queryById(this.id).then(response => {
  60. if (response.success) {
  61. //表数据
  62. this.proWorkMilestone = response.result;
  63. //确认状态
  64. if(this.proWorkMilestone.mileConfirm===1){
  65. this.milSwitch=true;
  66. }else{
  67. this.milSwitch=false;
  68. }
  69. //文件信息
  70. this.fileList=response.result.fileList;
  71. this.getFileListById();
  72. }
  73. this.isLoadingSave=false;
  74. });
  75. }
  76. getFileListById() {
  77. //文件集合不为空则显示文件下载
  78. if (this.fileList != null && this.fileList.length > 0) {
  79. this.fileList.forEach((element, index) => {
  80. const fileName = this.setAppendix(element);
  81. (element.uid = '-1'),
  82. (element.uid = index + 1),
  83. (element.name = fileName),
  84. (element.status = 'done'),
  85. (element.url = environment.SERVER_URL + 'sys/common/downloadFile/' + element.fileUrl);
  86. element.response = { message: element.fileUrl };
  87. });
  88. }
  89. }
  90. validateForm!: FormGroup;
  91. proWorkMilestone: ProWorkMilestone = {
  92. }; //对象
  93. isLoadingSave = false; //加载
  94. proList = []; //项目下拉列表
  95. milSwitch = false; //里程碑确认空间
  96. id = '';
  97. /**
  98. * 获取项目下拉数据
  99. */
  100. getProList() {
  101. return new Promise(resolve => {
  102. let projectManageArchives = new ProjectManageArchives();
  103. projectManageArchives.pageSize = 20000;
  104. projectManageArchives.pkOrg = sessionStorage.getItem('pkOrg');
  105. this.projectManageArchivesService.getList(projectManageArchives).then(response => {
  106. if (response.result.records) {
  107. this.proList = response.result.records;
  108. }
  109. resolve();
  110. });
  111. });
  112. }
  113. /**
  114. * 项目选择事件
  115. * @param event 项目档案id
  116. */
  117. proChange(event) {
  118. if (event) {
  119. //根据id获取项目档案数据
  120. this.projectManageArchivesService.getListById(event).then(response => {
  121. if (response.success) {
  122. let project = JSON.parse(JSON.stringify(response.result)); //项目档案对象
  123. this.proWorkMilestone.proCode = project.proCode; //项目档案编码
  124. this.proWorkMilestone.proName = project.proName; //项目档案名称
  125. this.proWorkMilestone.cusId = project.cusId; //客户id
  126. this.proWorkMilestone.cusCode = project.cusCode; //客户编码
  127. this.proWorkMilestone.cusName = project.cusName; //客户名称
  128. }
  129. });
  130. }
  131. }
  132. fileList = [];
  133. /**
  134. * 文件选择事件
  135. */
  136. handleChange(info: any): void {
  137. this.fileList = info.fileList;
  138. this.fileList.forEach(element => {
  139. if(!element.url&&element.response){
  140. element.url = environment.SERVER_URL + "sys/common/downloadFile/" + element.response.message
  141. }
  142. });
  143. }
  144. /**
  145. * 保存按钮
  146. */
  147. uploadUrlList = []; //传入后台的文件地址集合
  148. submitForm() {
  149. for (const i in this.validateForm.controls) {
  150. this.validateForm.controls[i].markAsDirty();
  151. this.validateForm.controls[i].updateValueAndValidity();
  152. }
  153. let valid = this.validateForm.valid;
  154. if (valid) {
  155. this.isLoadingSave=true;
  156. //获取里程碑确认状态
  157. if (this.milSwitch) {
  158. this.proWorkMilestone.mileConfirm = 1;
  159. } else {
  160. this.proWorkMilestone.mileConfirm = 0;
  161. }
  162. //事件格式化
  163. this.proWorkMilestone.confirmTime = this.datePipe.transform(
  164. this.proWorkMilestone.confirmTime,
  165. 'yyyy-MM-dd HH:mm:ss',
  166. );
  167. //文件集合
  168. this.getFileList();
  169. this.proWorkMilestone.fileList = this.uploadUrlList;
  170. this.proWorkMilestoneService.update(this.proWorkMilestone).then(response => {
  171. if (response.success) {
  172. //保存成功
  173. this.isLoadingSave = false;
  174. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  175. this.drawerRef.close(true);
  176. } else {
  177. //保存失败
  178. this.isLoadingSave = false;
  179. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  180. }
  181. this.isLoadingSave=false;
  182. });
  183. }
  184. }
  185. /**
  186. * 获取文件集合
  187. */
  188. getFileList() {
  189. if (this.fileList != null && this.fileList.length > 0) {
  190. this.fileList.forEach(element => {
  191. this.uploadUrlList = [
  192. ...this.uploadUrlList,
  193. {
  194. fileUrl: element.response.message, //文件地址
  195. },
  196. ];
  197. });
  198. }
  199. }
  200. close() {
  201. this.drawerRef.close();
  202. }
  203. //显示路径
  204. setAppendix(file: any) {
  205. const url = file.fileUrl;
  206. if (url != null && url !== '') {
  207. const idx = url.lastIndexOf('/');
  208. const fileUrl = url.slice(idx + 1);
  209. const index = fileUrl.lastIndexOf('_');
  210. const i = fileUrl.lastIndexOf('.');
  211. const fileName = fileUrl.substring(0, index);
  212. const fileSuffix = fileUrl.slice(i + 1);
  213. const f = fileName + '.' + fileSuffix;
  214. return f;
  215. }
  216. return '';
  217. }
  218. }