work-hour-big-statistics.component.ts 9.4 KB

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