department-quality-control-statistics.component.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 { format, addMonths, startOfMonth, endOfMonth, startOfDay, endOfDay } from 'date-fns';
  6. import { Component, OnInit, HostListener, AfterViewInit } from "@angular/core";
  7. import { MainService } from 'src/app/services/main.service';
  8. import { ActivatedRoute } from '@angular/router';
  9. import { ToolService } from "../../../../services/tool.service";
  10. @Component({
  11. selector: "app-department-quality-control-statistics",
  12. templateUrl: "./department-quality-control-statistics.component.html",
  13. styleUrls: ["./department-quality-control-statistics.component.less"],
  14. })
  15. export class DepartmentQualityControlStatisticsComponent 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. buildingId;//楼栋id
  29. hospital:any;
  30. deptTypeId;//科室类型id
  31. deptId;
  32. searchTimerSubject = new Subject();
  33. ngOnInit() {
  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.taskTypeDTO || this.fieldConfig.fields.statisticsTypeDTO;
  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. widthValue:any;
  104. widthConfig:any = [];
  105. getList(num?: number, field?: string, sort?: string) {
  106. if (num !== undefined) {
  107. this.pageIndex = num;
  108. }
  109. let postData:any = {
  110. idx: this.pageIndex - 1,
  111. sum: this.pageSize,
  112. showParentDept: this.parent==1 ? 'true' : undefined,
  113. deptId: this.deptId || undefined,
  114. buildingId: this.fieldConfig.fields.buildingId || undefined,
  115. startDate: this.dateRange[0] || undefined,
  116. endDate: this.dateRange[1] || undefined,
  117. hosId: this.getHosId,
  118. groupId: this.fieldConfig.fields.userId ? undefined : (this.fieldConfig.fields.groupId || undefined),
  119. userId: this.fieldConfig.fields.userId || undefined,
  120. statisticsTypeId: this.fieldConfig.fields.statisticsTypeId || undefined,
  121. taskTypeId: this.fieldConfig.fields.taskTypeId || undefined,
  122. };
  123. if (field && sort) {
  124. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  125. }
  126. if(this.parent==1){
  127. this.widthConfig = new Array(11).fill('100px').map((v, i) => { return (i == 0 || i == 1 && this.parent==1) || (i == 0 && this.parent==0) ? '150px' : '100px' });;
  128. this.widthValue = 11 * 100 + 300 * 1 + 20
  129. }else{
  130. this.widthConfig = new Array(10).fill('100px').map((v, i) => { return (i == 0 || i == 1 && this.parent==1) || (i == 0 && this.parent==0) ? '150px' : '100px' });;
  131. this.widthValue = 10 * 100 + 162 * 1 + 20
  132. }
  133. this.loading1 = true;
  134. this.mainService
  135. .postCustom("itsm/report", "deptTransOrderQc", postData)
  136. .subscribe((result) => {
  137. this.loading1 = false;
  138. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  139. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  140. this.listLength = result.totalCount;
  141. });
  142. }
  143. // 列表排序
  144. sortCurrent:any = {};
  145. sortCurrentKey: string = "";
  146. sortCurrentValue: string | null = "";
  147. sort(e) {
  148. const { key, value } = e;
  149. this.sortCurrentKey = key;
  150. this.sortCurrentValue = value;
  151. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  152. }
  153. // 搜索
  154. search() {
  155. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  156. }
  157. // 日期选择
  158. 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')];
  159. changeDate(result?): void {
  160. result[0] = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss');
  161. result[1] = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss');
  162. this.dateRange = result;
  163. }
  164. onCalendarChangeDate(dateArr){
  165. console.log(dateArr)
  166. if(dateArr.length == 2){
  167. this.dateRange = [format(startOfDay(dateArr[0]), 'yyyy-MM-dd HH:mm:ss'), format(endOfDay(dateArr[1]), 'yyyy-MM-dd HH:mm:ss')];
  168. }
  169. }
  170. // 导出
  171. excelExportLoading:any = false;
  172. excelExport(){
  173. this.excelExportLoading = this.message.loading("导出中..", {
  174. nzDuration: 0,
  175. }).messageId;
  176. let postData:any = {
  177. showParentDept: this.parent==1 ? 'true' : undefined,
  178. deptId: this.deptId || undefined,
  179. buildingId: this.fieldConfig.fields.buildingId || undefined,
  180. startDate: this.dateRange[0] || undefined,
  181. endDate: this.dateRange[1] || undefined,
  182. hosId: this.getHosId,
  183. groupId: this.fieldConfig.fields.userId ? undefined : (this.fieldConfig.fields.groupId || undefined),
  184. userId: this.fieldConfig.fields.userId || undefined,
  185. statisticsTypeId: this.fieldConfig.fields.statisticsTypeId || undefined,
  186. taskTypeId: this.fieldConfig.fields.taskTypeId || undefined,
  187. };
  188. if (this.sortCurrentKey && this.sortCurrentValue) {
  189. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  190. }
  191. this.mainService
  192. .postExportCustom("itsm/exportMergeTitle", "deptTransOrderQc", postData)
  193. .subscribe((data) => {
  194. this.message.remove(this.excelExportLoading);
  195. this.excelExportLoading = false;
  196. this.message.success('导出成功');
  197. var file = new Blob([data], {
  198. type: "application/vnd.ms-excel",
  199. });
  200. //trick to download store a file having its URL
  201. var fileURL = URL.createObjectURL(file);
  202. var a = document.createElement("a");
  203. a.href = fileURL;
  204. a.target = "_blank";
  205. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  206. document.body.appendChild(a);
  207. a.click();
  208. },(err) => {
  209. this.message.remove(this.excelExportLoading);
  210. this.excelExportLoading = false;
  211. this.message.error('导出失败');
  212. });
  213. }
  214. // 重置
  215. reset(){
  216. this.sortCurrentKey = "";
  217. this.sortCurrentValue = "";
  218. this.sortCurrent = {};
  219. 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')]
  220. this.deptId = undefined;
  221. this.fieldConfig.fields = {groupId: undefined, userId: undefined, statisticsTypeId: undefined, taskTypeId: undefined, buildingId: undefined};
  222. this.search();
  223. }
  224. // 楼栋搜索
  225. changeBuildingInp(e) {
  226. this.searchTimer(this.getBuildingList, e);
  227. }
  228. // 防抖
  229. isLoading = false;
  230. searchTimer(fun, e) {
  231. this.isLoading = true;
  232. this.searchTimerSubject.next([fun, e]);
  233. }
  234. openChangeBuilding(flag){
  235. flag && this.getBuildingList();
  236. }
  237. // 科室搜索
  238. changeInp(e) {
  239. this.searchTimer(this.getDeparts, e);
  240. }
  241. // 获取所有科室
  242. alldepart:any;
  243. getDeparts(dept?) {
  244. let data = {
  245. department: {
  246. statisticalHosId: this.getHosId,
  247. dept: dept,
  248. searchType: 1,
  249. },
  250. idx: 0,
  251. sum: 20,
  252. };
  253. this.mainService
  254. .getFetchDataList("data", "department", data)
  255. .subscribe((data) => {
  256. this.isLoading = false;
  257. this.alldepart = data.list;
  258. });
  259. }
  260. // 获取报修科室列表
  261. buildingList:any[] = [];
  262. getBuildingList(keyword?) {
  263. let data = {
  264. building: {
  265. simpleQuery: true,
  266. buildingName: keyword,
  267. statisticalHosId:this.getHosId,
  268. },
  269. idx: 0,
  270. sum: 20,
  271. };
  272. this.isLoading = true;
  273. this.mainService
  274. .getFetchDataList("data", "building", data)
  275. .subscribe((data) => {
  276. this.isLoading = false;
  277. this.buildingList = data.list;
  278. });
  279. }
  280. // 详细搜索
  281. fieldConfig:any = {
  282. fields: {groupId: undefined, userId: undefined, statisticsTypeId: undefined, taskTypeId: undefined, buildingId: undefined},
  283. config: {groupAndUser: true, statisticsType: true, taskType: true, building: true},
  284. }
  285. showSearchMore:boolean = false;
  286. showMore(){
  287. this.showSearchMore = true;
  288. }
  289. cancelEvent(){
  290. this.showSearchMore = false;
  291. }
  292. submitEvent(fields){
  293. this.showSearchMore = false;
  294. this.fieldConfig.fields = fields;
  295. console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
  296. this.search();
  297. this.onResize();
  298. }
  299. }