update.component.ts 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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-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 ProjectWorkDevelopmentLogUpdateComponent 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. startDate:[null,[Validators.required]],
  52. endDate:[null,[Validators.required]]
  53. });
  54. //项目下拉
  55. this.isLoadingSave = true;
  56. this.getProList()
  57. .then(() => {
  58. //人员下来数据
  59. return this.getPersonnelList();
  60. }).then(()=>{
  61. //根据id查询
  62. return this.getById();
  63. })
  64. .then(() => {
  65. this.isLoadingSave = false;
  66. });
  67. }
  68. isLoadingSave = false;
  69. validateForm!: FormGroup;
  70. proWorkLogic: ProWorkLogic = {
  71. }; //对象
  72. proList = []; //项目下拉数据
  73. personnelList = []; //汇报人下拉数据
  74. itemList = []; //明细集合
  75. mieList = []; //里程碑数据下拉
  76. date = null;
  77. id="";
  78. /**
  79. * 开始时间禁用事件
  80. */
  81. disabledDate = (current: Date): boolean => {
  82. // Can not select days before today and today
  83. if(this.proWorkLogic.endDate){
  84. let end=new Date(this.proWorkLogic.endDate);//结束时间
  85. //开始时间大于结束时间的禁用
  86. return current.getTime()>end.getTime();
  87. }else{
  88. return false;
  89. }
  90. };
  91. /**
  92. * 结束
  93. * 时间禁用事件
  94. */
  95. disabledDate2 = (current: Date): boolean => {
  96. // Can not select days before today and today
  97. if(this.proWorkLogic.startDate){
  98. let start=new Date(this.proWorkLogic.startDate);//开始时间
  99. //结束时间小于开始时间禁用
  100. return current.getTime()<start.getTime();
  101. }else{
  102. return false;
  103. }
  104. };
  105. /**
  106. * 根据id查询
  107. */
  108. getById(){
  109. return new Promise((resolve)=>{
  110. this.proWorkLogicService.getListById(this.id).then((response)=>{
  111. if(response.result){
  112. this.proWorkLogic=response.result;//主表对象
  113. this.itemList=response.result.detailList;//明细数组
  114. //最大排序
  115. if(this.itemList){
  116. this.sort=this.itemList.length+1;
  117. }
  118. //开始时间-结束时间
  119. this.date=[new Date(this.proWorkLogic.startDate),new Date(this.proWorkLogic.endDate)]
  120. }
  121. resolve();
  122. })
  123. })
  124. }
  125. /**
  126. * 获取项目下拉数据
  127. */
  128. getProList() {
  129. return new Promise(resolve => {
  130. let projectManageArchives = new ProjectManageArchives();
  131. projectManageArchives.pageSize = 20000;
  132. projectManageArchives.pkOrg = sessionStorage.getItem('pkOrg');
  133. this.projectManageArchivesService.getList(projectManageArchives).then(response => {
  134. if (response.result.records) {
  135. this.proList = response.result.records;
  136. }
  137. resolve();
  138. });
  139. });
  140. }
  141. /**
  142. * 项目下拉选择事件
  143. */
  144. proChange(event) {
  145. this.getMieList(event);
  146. }
  147. /**
  148. * 获取汇报人下拉数据
  149. */
  150. getPersonnelList() {
  151. return new Promise(resolve => {
  152. this.personnelService.queryApprover(sessionStorage.getItem('pkOrg')).then(response => {
  153. if (response.result) {
  154. this.personnelList = JSON.parse(JSON.stringify(response.result));
  155. }
  156. recursiveQuery(this.personnelList);
  157. resolve();
  158. });
  159. });
  160. }
  161. /**
  162. * 里程碑数据下拉
  163. */
  164. getMieList(proArchivesId) {
  165. return new Promise(resolve => {
  166. let plan = { id: proArchivesId, planType: '3' };
  167. this.projectManageArchivesService.getPlanListById(plan).then(response => {
  168. if (response.result) {
  169. this.mieList = response.result;
  170. }
  171. resolve();
  172. });
  173. });
  174. }
  175. /**
  176. * 里程碑选择事件
  177. */
  178. proArchivesIdChange(data) {
  179. console.log(data.proArchivesId);
  180. //是否选择里程碑
  181. if (data.proArchivesId) {
  182. this.getChild(this.mieList, data);
  183. } else {
  184. data.proArchivesMilestone = '';
  185. data.proArchivesId = '';
  186. }
  187. }
  188. /**
  189. * 递归查询名称
  190. */
  191. getChild(mieList, data) {
  192. mieList.forEach(element => {
  193. if (element.key === data.proArchivesId) {
  194. data.proArchivesMilestone = element.title;
  195. data.proArchivesId = element.key;
  196. data.proPlanId=element.id;
  197. } else {
  198. if (element.children) {
  199. this.getChild(element.children, data);
  200. }
  201. }
  202. });
  203. }
  204. /**
  205. * 增行按钮
  206. */
  207. sort = 0;
  208. addRow() {
  209. this.itemList = [
  210. ...this.itemList,
  211. {
  212. sort: this.sort,
  213. },
  214. ];
  215. this.sort++;
  216. }
  217. /**
  218. * 删除行
  219. */
  220. deleteRow(sort) {
  221. this.itemList = this.itemList.filter(d => d.sort !== sort);
  222. }
  223. /**
  224. * 保存按钮
  225. */
  226. submitForm(): any {
  227. return new Promise(resolve => {
  228. for (const i in this.validateForm.controls) {
  229. this.validateForm.controls[i].markAsDirty();
  230. this.validateForm.controls[i].updateValueAndValidity();
  231. }
  232. let valid = this.validateForm.valid;
  233. if (valid) {
  234. this.isLoadingSave = true;
  235. // this.proWorkLogic.type = '1'; //实施
  236. this.proWorkLogic.pkOrg = sessionStorage.getItem('pkOrg');
  237. //项目名称
  238. if (this.proWorkLogic.proId) {
  239. this.proList.forEach(element => {
  240. if (element.id === this.proWorkLogic.proId) {
  241. this.proWorkLogic.proName = element.proName;
  242. }
  243. });
  244. } else {
  245. this.proWorkLogic.proName = '';
  246. }
  247. //汇报人名称
  248. if (this.proWorkLogic.reporterId) {
  249. //循环集合数据获取名称
  250. this.personnelList.forEach(pkOrg => {
  251. pkOrg.children.forEach(depart => {
  252. depart.children.forEach(personnel => {
  253. if (personnel.key === this.proWorkLogic.reporterId) {
  254. this.proWorkLogic.reporter = personnel.name;
  255. }
  256. });
  257. });
  258. });
  259. } else {
  260. this.proWorkLogic.reporter = '';
  261. }
  262. //时间格式化
  263. // this.proWorkLogic.startDate = this.datePipe.transform(this.date[0], 'yyyy-MM-dd HH:mm:ss');
  264. // this.proWorkLogic.endDate = this.datePipe.transform(this.date[1], 'yyyy-MM-dd HH:mm:ss');
  265. this.proWorkLogic.startDate = this.datePipe.transform(this.proWorkLogic.startDate, 'yyyy-MM-dd HH:mm:ss');
  266. this.proWorkLogic.endDate = this.datePipe.transform(this.proWorkLogic.endDate, 'yyyy-MM-dd HH:mm:ss');
  267. //判断两个时间差的工时是否大于明细总工时
  268. if (!this.getHourBoole()) {
  269. this.nzNotificationService.warning('工作用时不得大于开始时间与结束时间之差', '');
  270. this.isLoadingSave = false;
  271. return;
  272. }
  273. //子表\
  274. //判断是否输入子表数据
  275. if (this.itemList && this.itemList.length > 0) {
  276. this.proWorkLogic.detailList = this.itemList;
  277. } else {
  278. this.nzNotificationService.warning('工作内容必填', '');
  279. this.isLoadingSave = false;
  280. return;
  281. }
  282. this.proWorkLogicService.update(this.proWorkLogic).then(response => {
  283. if (response.success) {
  284. //保存成功
  285. this.isLoadingSave = false;
  286. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  287. this.drawerRef.close(true);
  288. resolve();
  289. } else {
  290. //保存失败
  291. this.isLoadingSave = false;
  292. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  293. }
  294. });
  295. }
  296. });
  297. }
  298. /**
  299. * 判断两个时间差的工时是否大于明细总工时
  300. */
  301. getHourBoole(): boolean {
  302. //明细总工时
  303. let itemHour = 0;
  304. //两个时间差
  305. let dateHour = this.getInervalHour(new Date(this.proWorkLogic.startDate), new Date(this.proWorkLogic.endDate));
  306. //循环获取明细的总工时
  307. this.itemList.forEach(element => {
  308. if (element.duration) {
  309. itemHour = itemHour + Number(element.duration);
  310. }
  311. });
  312. return dateHour >= itemHour;
  313. }
  314. /**
  315. * 获取两个时间差
  316. */
  317. getInervalHour(startDate, endDate) {
  318. var ms = endDate.getTime() - startDate.getTime();
  319. if (ms < 0) return 0;
  320. return Math.floor(ms / 1000 / 60 / 60);
  321. }
  322. close() {
  323. this.drawerRef.close();
  324. }
  325. }