add.component.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 { PersonnelService } from 'app/services/basedata/personnel.service';
  8. import { ProWorkLogicService } from 'app/services/project-work/pro-work-logic.service';
  9. import { I18NService } from '@core';
  10. import { ProWorkLogic } from 'app/entity/project-work/pro-work-logic';
  11. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  12. import { recursiveQuery } from '@shared';
  13. @Component({
  14. selector: 'app-project-work-development-log-add',
  15. templateUrl: './add.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 ProjectWorkDevelopmentLogAddComponent implements OnInit {
  33. constructor(
  34. private fb: FormBuilder,
  35. private settingsService: SettingsService,
  36. private datePipe: DatePipe,
  37. private projectManageArchivesService: ProjectManageArchivesService,
  38. private personnelService: PersonnelService,
  39. private proWorkLogicService: ProWorkLogicService,
  40. private nzNotificationService: NzNotificationService,
  41. private i18NService: I18NService,
  42. private drawerRef: NzDrawerRef,
  43. ) {}
  44. ngOnInit(): void {
  45. //初始化表单
  46. this.validateForm = this.fb.group({
  47. billcode: [{ value: '', disabled: true }],
  48. proId: [null, [Validators.required]],
  49. date: [null, [Validators.required]],
  50. reporterId: [null, [Validators.required]],
  51. });
  52. //项目下拉
  53. this.isLoadingSave = true;
  54. this.getProList()
  55. .then(() => {
  56. //人员下来数据
  57. return this.getPersonnelList();
  58. })
  59. .then(() => {
  60. this.isLoadingSave = false;
  61. });
  62. }
  63. isLoadingSave = false;
  64. validateForm!: FormGroup;
  65. proWorkLogic: ProWorkLogic = {
  66. currentUser: this.settingsService.user.realname,
  67. createTime: this.datePipe.transform(new Date(), 'yyyy-MM-dd HH:mm:ss'),
  68. }; //对象
  69. proList = []; //项目下拉数据
  70. personnelList = []; //汇报人下拉数据
  71. itemList = []; //明细集合
  72. mieList = []; //里程碑数据下拉
  73. date = null;
  74. /**
  75. * 获取项目下拉数据
  76. */
  77. getProList() {
  78. return new Promise(resolve => {
  79. let projectManageArchives = new ProjectManageArchives();
  80. projectManageArchives.pageSize = 20000;
  81. projectManageArchives.pkOrg = sessionStorage.getItem('pkOrg');
  82. this.projectManageArchivesService.getList(projectManageArchives).then(response => {
  83. if (response.result.records) {
  84. this.proList = response.result.records;
  85. }
  86. resolve();
  87. });
  88. });
  89. }
  90. /**
  91. * 项目下拉选择事件
  92. */
  93. proChange(event) {
  94. this.getMieList(event);
  95. }
  96. /**
  97. * 获取汇报人下拉数据
  98. */
  99. getPersonnelList() {
  100. return new Promise(resolve => {
  101. this.personnelService.queryApprover(sessionStorage.getItem('pkOrg')).then(response => {
  102. if (response.result) {
  103. this.personnelList = JSON.parse(JSON.stringify(response.result));
  104. }
  105. recursiveQuery(this.personnelList);
  106. resolve();
  107. });
  108. });
  109. }
  110. /**
  111. * 里程碑数据下拉
  112. */
  113. getMieList(proArchivesId) {
  114. return new Promise(resolve => {
  115. let plan = { id: proArchivesId, planType: '3' };
  116. this.projectManageArchivesService.getPlanListById(plan).then(response => {
  117. if (response.result) {
  118. this.mieList = response.result;
  119. }
  120. resolve();
  121. });
  122. });
  123. }
  124. /**
  125. * 里程碑选择事件
  126. */
  127. proArchivesIdChange(data) {
  128. console.log(data.proArchivesId);
  129. //是否选择里程碑
  130. if (data.proArchivesId) {
  131. this.getChild(this.mieList, data);
  132. } else {
  133. data.proArchivesMilestone = '';
  134. data.proArchivesId = '';
  135. }
  136. }
  137. /**
  138. * 递归查询名称
  139. */
  140. getChild(mieList, data) {
  141. mieList.forEach(element => {
  142. if (element.key === data.proArchivesId) {
  143. data.proArchivesMilestone = element.title;
  144. data.proArchivesId = element.key;
  145. data.proPlanId=element.id;
  146. } else {
  147. if (element.children) {
  148. this.getChild(element.children, data);
  149. }
  150. }
  151. });
  152. }
  153. /**
  154. * 增行按钮
  155. */
  156. sort = 0;
  157. addRow() {
  158. this.itemList = [
  159. ...this.itemList,
  160. {
  161. sort: this.sort,
  162. },
  163. ];
  164. this.sort++;
  165. }
  166. /**
  167. * 删除行
  168. */
  169. deleteRow(sort) {
  170. this.itemList = this.itemList.filter(d => d.sort !== sort);
  171. }
  172. /**
  173. * 保存按钮
  174. */
  175. submitForm(): any {
  176. return new Promise(resolve => {
  177. for (const i in this.validateForm.controls) {
  178. this.validateForm.controls[i].markAsDirty();
  179. this.validateForm.controls[i].updateValueAndValidity();
  180. }
  181. let valid = this.validateForm.valid;
  182. if (valid) {
  183. this.isLoadingSave = true;
  184. this.proWorkLogic.type = '1'; //开发
  185. this.proWorkLogic.pkOrg = sessionStorage.getItem('pkOrg');
  186. //项目名称
  187. if (this.proWorkLogic.proId) {
  188. this.proList.forEach(element => {
  189. if (element.id === this.proWorkLogic.proId) {
  190. this.proWorkLogic.proName = element.proName;
  191. }
  192. });
  193. } else {
  194. this.proWorkLogic.proName = '';
  195. }
  196. //汇报人名称
  197. if (this.proWorkLogic.reporterId) {
  198. //循环集合数据获取名称
  199. this.personnelList.forEach(pkOrg => {
  200. pkOrg.children.forEach(depart => {
  201. depart.children.forEach(personnel => {
  202. if (personnel.key === this.proWorkLogic.reporterId) {
  203. this.proWorkLogic.reporter = personnel.name;
  204. }
  205. });
  206. });
  207. });
  208. } else {
  209. this.proWorkLogic.reporter = '';
  210. }
  211. //时间格式化
  212. this.proWorkLogic.startDate = this.datePipe.transform(this.date[0], 'yyyy-MM-dd HH:mm:ss');
  213. this.proWorkLogic.endDate = this.datePipe.transform(this.date[1], 'yyyy-MM-dd HH:mm:ss');
  214. //判断两个时间差的工时是否大于明细总工时
  215. if(!this.getHourBoole()){
  216. this.nzNotificationService.warning("工作用时不得大于开始时间与结束时间之差","");
  217. this.isLoadingSave=false;
  218. return;
  219. }
  220. //子表\
  221. //判断是否输入子表数据
  222. if (this.itemList && this.itemList.length > 0) {
  223. this.proWorkLogic.detailList = this.itemList;
  224. } else {
  225. this.nzNotificationService.warning('工作内容必填', '');
  226. this.isLoadingSave=false;
  227. return;
  228. }
  229. this.proWorkLogicService.add(this.proWorkLogic).then(response => {
  230. if (response.success) {
  231. //保存成功
  232. this.isLoadingSave = false;
  233. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  234. this.drawerRef.close(true);
  235. resolve();
  236. } else {
  237. //保存失败
  238. this.isLoadingSave = false;
  239. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  240. }
  241. });
  242. }
  243. });
  244. }
  245. /**
  246. * 判断两个时间差的工时是否大于明细总工时
  247. */
  248. getHourBoole():boolean{
  249. //明细总工时
  250. let itemHour=0;
  251. //两个时间差
  252. let dateHour=this.getInervalHour(this.date[0], this.date[1]);
  253. //循环获取明细的总工时
  254. this.itemList.forEach(element => {
  255. if(element.duration){
  256. itemHour=itemHour+Number(element.duration);
  257. }
  258. });
  259. return dateHour>=itemHour;
  260. }
  261. /**
  262. * 获取两个时间差
  263. */
  264. getInervalHour(startDate, endDate) {
  265. var ms = endDate.getTime() - startDate.getTime();
  266. if (ms < 0) return 0;
  267. return Math.floor(ms / 1000 / 60 / 60);
  268. }
  269. close() {
  270. this.drawerRef.close();
  271. }
  272. }