tripartite-company-statistics.component.ts 9.0 KB

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