department-evaluate-statistics.component.ts 10 KB

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