department-phone-statistics.component.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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-department-phone-statistics",
  11. templateUrl: "./department-phone-statistics.component.html",
  12. styleUrls: ["./department-phone-statistics.component.less"],
  13. })
  14. export class DepartmentPhoneStatisticsComponent 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. deptId;//科室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.buildingDTO || this.fieldConfig.fields.floorDTO || this.fieldConfig.fields.deptTypeDTO;
  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. startDate: this.customChangeDateComponent.startDate || undefined,
  107. endDate: this.customChangeDateComponent.endDate || undefined,
  108. hosId: this.getHosId,
  109. deptId: this.deptId || undefined,
  110. buildingId: this.fieldConfig.fields.buildingId || undefined,
  111. placeId: this.fieldConfig.fields.floorId || undefined,
  112. deptTypeId: this.fieldConfig.fields.deptTypeId || undefined,
  113. };
  114. if (field && sort) {
  115. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  116. }
  117. this.loading1 = true;
  118. this.mainService
  119. .postCustom("itsm/report", "phoneDept", postData)
  120. .subscribe((result) => {
  121. this.loading1 = false;
  122. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  123. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  124. this.listLength = result.totalCount;
  125. });
  126. }
  127. // 列表排序
  128. sortCurrent:any = {};
  129. sortCurrentKey: string = "";
  130. sortCurrentValue: string | null = "";
  131. sort(e) {
  132. const { key, value } = e;
  133. this.sortCurrentKey = key;
  134. this.sortCurrentValue = value;
  135. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  136. }
  137. // 搜索
  138. search() {
  139. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  140. }
  141. // 日期选择
  142. dateRange: any = [];
  143. // 导出
  144. excelExportLoading:any = false;
  145. excelExport(){
  146. this.excelExportLoading = this.message.loading("导出中..", {
  147. nzDuration: 0,
  148. }).messageId;
  149. let postData:any = {
  150. startDate: this.customChangeDateComponent.startDate || undefined,
  151. endDate: this.customChangeDateComponent.endDate || undefined,
  152. hosId: this.getHosId,
  153. deptId: this.deptId || undefined,
  154. buildingId: this.fieldConfig.fields.buildingId || undefined,
  155. placeId: this.fieldConfig.fields.floorId || undefined,
  156. deptTypeId: this.fieldConfig.fields.deptTypeId || undefined,
  157. };
  158. if (this.sortCurrentKey && this.sortCurrentValue) {
  159. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  160. }
  161. this.mainService
  162. .postExportCustom("itsm/export", "phoneDept", postData)
  163. .subscribe((data) => {
  164. this.message.remove(this.excelExportLoading);
  165. this.excelExportLoading = false;
  166. this.message.success('导出成功');
  167. var file = new Blob([data], {
  168. type: "application/vnd.ms-excel",
  169. });
  170. //trick to download store a file having its URL
  171. var fileURL = URL.createObjectURL(file);
  172. var a = document.createElement("a");
  173. a.href = fileURL;
  174. a.target = "_blank";
  175. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  176. document.body.appendChild(a);
  177. a.click();
  178. },(err) => {
  179. this.message.remove(this.excelExportLoading);
  180. this.excelExportLoading = false;
  181. this.message.error('导出失败');
  182. });
  183. }
  184. // 重置
  185. reset(){
  186. this.sortCurrentKey = "";
  187. this.sortCurrentValue = "";
  188. this.sortCurrent = {};
  189. this.dateRange = []
  190. this.deptId = undefined;
  191. this.fieldConfig.fields = {buildingId: undefined, floorId: undefined, deptTypeId: undefined};
  192. this.customChangeDateComponent.resetByDate();
  193. this.search();
  194. }
  195. // 科室搜索
  196. changeDeptInp(e) {
  197. this.searchTimer(this.getDeptList, e);
  198. }
  199. // 防抖
  200. isLoading = false;
  201. searchTimer(fun, e) {
  202. this.isLoading = true;
  203. this.searchTimerSubject.next([fun, e]);
  204. }
  205. openChangeDept(flag){
  206. flag && this.getDeptList();
  207. }
  208. // 获取科室列表
  209. deptList:any[] = [];
  210. getDeptList(keyword?) {
  211. let data = {
  212. department: {
  213. statisticalHosId: this.getHosId,
  214. dept: keyword,
  215. searchType: 1,
  216. },
  217. idx: 0,
  218. sum: 20,
  219. };
  220. this.isLoading = true;
  221. this.mainService
  222. .getFetchDataList("data", "department", data)
  223. .subscribe((data) => {
  224. this.isLoading = false;
  225. this.deptList = data.list;
  226. });
  227. }
  228. // 详细搜索
  229. fieldConfig:any = {
  230. fields: {buildingId: undefined, floorId: undefined, deptTypeId: undefined},
  231. config: {buildingAndFloor: true, deptType: true},
  232. }
  233. showSearchMore:boolean = false;
  234. showMore(){
  235. this.showSearchMore = true;
  236. }
  237. cancelEvent(){
  238. this.showSearchMore = false;
  239. }
  240. submitEvent(fields){
  241. this.showSearchMore = false;
  242. this.fieldConfig.fields = fields;
  243. console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
  244. this.search();
  245. this.onResize();
  246. }
  247. }