department-incident-statistics.component.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import { debounceTime } from 'rxjs/operators';
  2. import { Subject } from 'rxjs';
  3. import { NzMessageService } from 'ng-zorro-antd/message';
  4. import { format, addMonths, startOfMonth, endOfMonth, startOfDay, endOfDay } from 'date-fns';
  5. import { Component, OnInit, HostListener, AfterViewInit } from "@angular/core";
  6. import { MainService } from 'src/app/services/main.service';
  7. import { ActivatedRoute } from '@angular/router';
  8. @Component({
  9. selector: "app-department-incident-statistics",
  10. templateUrl: "./department-incident-statistics.component.html",
  11. styleUrls: ["./department-incident-statistics.component.less"],
  12. })
  13. export class DepartmentIncidentStatisticsComponent implements OnInit, AfterViewInit {
  14. constructor(
  15. private mainService: MainService,
  16. private message: NzMessageService,
  17. private route: ActivatedRoute,
  18. ) {}
  19. listOfData: any[] = []; //表格数据
  20. listOfDataEnd: any[] = []; //表格合计
  21. pageIndex: number = 1; //表格当前页码
  22. pageSize: number = 30; //表格每页展示条数
  23. listLength: number = 0; //表格总数据量
  24. repairDeptId;//报修科室id
  25. searchTimerSubject = new Subject();
  26. ngOnInit() {
  27. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  28. let fun = v[0];
  29. fun.call(this, v[1]);
  30. });
  31. this.initSessionData();
  32. this.search();
  33. }
  34. ngAfterViewInit(){
  35. this.onResize();
  36. }
  37. tableHeight:number = 0;
  38. @HostListener('window:resize')
  39. onResize(): void {
  40. setTimeout(() => {
  41. this.tableHeight = window.innerHeight - 64 - 64 - 36 - 48 - 8 - 45 - 54 - this.getMoreFilter;
  42. console.log('this.tableHeight:', this.tableHeight)
  43. }, 0)
  44. }
  45. get getMoreFilter(){
  46. let flag = this.fieldConfig.fields.groupDTO || this.fieldConfig.fields.userDTO || this.fieldConfig.fields.category1DTO || this.fieldConfig.fields.category2DTO || this.fieldConfig.fields.category3DTO || this.fieldConfig.fields.sourceDTO;
  47. return flag ? 21 : 0;
  48. }
  49. // 初始化缓存数据
  50. queryType:any;
  51. hosId:any;
  52. dutyId:any;
  53. parentDutyId:any;
  54. initSessionData(){
  55. let maintenanceStatistics = JSON.parse(sessionStorage.getItem('maintenanceStatistics'));
  56. let queryType:any = maintenanceStatistics.queryType;
  57. let hosId:any = maintenanceStatistics.hospitalId;
  58. let dutyId:any = maintenanceStatistics.dutyId;
  59. queryType = queryType ? +queryType : undefined;
  60. hosId = hosId ? +hosId : undefined;
  61. dutyId = dutyId ? +dutyId : undefined;
  62. this.queryType = queryType;
  63. if(queryType == 1){
  64. this.hosId = undefined;
  65. this.dutyId = undefined;
  66. this.parentDutyId = undefined;
  67. }else if(queryType == 2){
  68. this.hosId = hosId;
  69. this.dutyId = undefined;
  70. this.parentDutyId = undefined;
  71. }else if(queryType == 3){
  72. this.hosId = undefined;
  73. this.dutyId = dutyId;
  74. this.parentDutyId = undefined;
  75. }else if(queryType == 4){
  76. this.hosId = undefined;
  77. this.dutyId = undefined;
  78. this.parentDutyId = dutyId;
  79. }
  80. }
  81. get getHosId(){
  82. return this.parentDutyId || this.dutyId || this.hosId;
  83. }
  84. // 表格数据
  85. loading1 = false;
  86. getList(num?: number, field?: string, sort?: string) {
  87. if (num !== undefined) {
  88. this.pageIndex = num;
  89. }
  90. let postData:any = {
  91. idx: this.pageIndex - 1,
  92. sum: this.pageSize,
  93. startDate: this.dateRange[0],
  94. endDate: this.dateRange[1],
  95. hosId: this.hosId,
  96. dutyId: this.dutyId,
  97. parentDutyId: this.parentDutyId,
  98. repairDeptId: this.repairDeptId,
  99. groupId: this.fieldConfig.fields.groupId,
  100. userId: this.fieldConfig.fields.userId,
  101. categoryId: this.fieldConfig.fields.categoryId,
  102. sourceId: this.fieldConfig.fields.sourceId,
  103. hierarchy: this.fieldConfig.fields.hierarchy,
  104. };
  105. if (field && sort) {
  106. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  107. }
  108. this.loading1 = true;
  109. this.mainService
  110. .postCustom("itsm/report", "incidentWorkOrder", postData)
  111. .subscribe((result) => {
  112. this.loading1 = false;
  113. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  114. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  115. this.listLength = result.totalCount;
  116. });
  117. }
  118. // 列表排序
  119. sortCurrent = {};
  120. sortCurrentKey: string = "";
  121. sortCurrentValue: string | null = "";
  122. sort(e) {
  123. const { key, value } = e;
  124. this.sortCurrentKey = key;
  125. this.sortCurrentValue = value;
  126. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  127. }
  128. // 搜索
  129. search() {
  130. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  131. }
  132. // 日期选择
  133. dateRange: any = [format(startOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss'), format(endOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss')];
  134. changeDate(result?): void {
  135. result[0] = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss');
  136. result[1] = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss');
  137. this.dateRange = result;
  138. }
  139. onCalendarChangeDate(dateArr){
  140. console.log(dateArr)
  141. if(dateArr.length == 2){
  142. this.dateRange = [format(startOfDay(dateArr[0]), 'yyyy-MM-dd HH:mm:ss'), format(endOfDay(dateArr[1]), 'yyyy-MM-dd HH:mm:ss')];
  143. }
  144. }
  145. // 导出
  146. excelExportLoading:any = false;
  147. excelExport(){
  148. this.excelExportLoading = this.message.loading("导出中..", {
  149. nzDuration: 0,
  150. }).messageId;
  151. let postData:any = {
  152. startDate: this.dateRange[0],
  153. endDate: this.dateRange[1],
  154. hosId: this.hosId,
  155. dutyId: this.dutyId,
  156. parentDutyId: this.parentDutyId,
  157. repairDeptId: this.repairDeptId,
  158. groupId: this.fieldConfig.fields.groupId,
  159. userId: this.fieldConfig.fields.userId,
  160. categoryId: this.fieldConfig.fields.categoryId,
  161. sourceId: this.fieldConfig.fields.sourceId,
  162. hierarchy: this.fieldConfig.fields.hierarchy,
  163. };
  164. if (this.sortCurrentKey && this.sortCurrentValue) {
  165. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  166. }
  167. this.mainService
  168. .postExportCustom("itsm/export", "incidentWorkOrder", postData)
  169. .subscribe((data) => {
  170. this.message.remove(this.excelExportLoading);
  171. this.excelExportLoading = false;
  172. this.message.success('导出成功');
  173. var file = new Blob([data], {
  174. type: "application/vnd.ms-excel",
  175. });
  176. //trick to download store a file having its URL
  177. var fileURL = URL.createObjectURL(file);
  178. var a = document.createElement("a");
  179. a.href = fileURL;
  180. a.target = "_blank";
  181. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  182. document.body.appendChild(a);
  183. a.click();
  184. },(err) => {
  185. this.message.remove(this.excelExportLoading);
  186. this.excelExportLoading = false;
  187. this.message.error('导出失败');
  188. });
  189. }
  190. // 重置
  191. reset(){
  192. this.sortCurrentKey = "";
  193. this.sortCurrentValue = "";
  194. this.sortCurrent = {};
  195. this.dateRange = [format(startOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss'), format(endOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss')]
  196. this.repairDeptId = undefined;
  197. this.fieldConfig.fields = {groupId: undefined, userId: undefined, categoryId: undefined, sourceId: undefined, hierarchy: undefined};
  198. this.search();
  199. }
  200. // 科室搜索
  201. changeRepairDeptInp(e) {
  202. this.searchTimer(this.getRepairDeptList, e);
  203. }
  204. // 防抖
  205. isLoading = false;
  206. searchTimer(fun, e) {
  207. this.isLoading = true;
  208. this.searchTimerSubject.next([fun, e]);
  209. }
  210. openChangeRepairDept(flag){
  211. flag && this.getRepairDeptList();
  212. }
  213. // 获取报修科室列表
  214. repairDeptList:any[] = [];
  215. getRepairDeptList(keyword?) {
  216. let data = {
  217. department: {
  218. cascadeHosId: this.getHosId,
  219. dept: keyword,
  220. searchType: 1,
  221. },
  222. idx: 0,
  223. sum: 20,
  224. };
  225. this.isLoading = true;
  226. this.mainService
  227. .getFetchDataList("data", "department", data)
  228. .subscribe((data) => {
  229. this.isLoading = false;
  230. this.repairDeptList = data.list;
  231. });
  232. }
  233. // 详细搜索
  234. fieldConfig:any = {
  235. fields: {groupId: undefined, userId: undefined, categoryId: undefined, sourceId: undefined, hierarchy: undefined},
  236. config: {groupAndUser: true, category123: true, source: true},
  237. }
  238. showSearchMore:boolean = false;
  239. showMore(){
  240. this.showSearchMore = true;
  241. }
  242. cancelEvent(){
  243. this.showSearchMore = false;
  244. }
  245. submitEvent(fields){
  246. this.showSearchMore = false;
  247. this.fieldConfig.fields = fields;
  248. console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
  249. this.search();
  250. this.onResize();
  251. }
  252. }