department-evaluate-statistics.component.ts 8.8 KB

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