user-business-statistics.component.ts 8.9 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-user-business-statistics",
  11. templateUrl: "./user-business-statistics.component.html",
  12. styleUrls: ["./user-business-statistics.component.less"],
  13. })
  14. export class UserBusinessStatisticsComponent 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. widthConfig: any[] = [];
  27. groupId;//分组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. this.initSessionData();
  35. this.getQueryParams();
  36. this.search();
  37. }
  38. ngAfterViewInit(){
  39. this.onResize();
  40. }
  41. tableHeight:number = 0;
  42. @HostListener('window:resize')
  43. onResize(): void {
  44. setTimeout(() => {
  45. 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 - 2;
  46. }, 0)
  47. }
  48. getQueryParams(){
  49. let queryParams = this.tabService.getQueryParams();
  50. this.tabService.clearQueryParams();
  51. if(queryParams.dateRange){
  52. this.dateRange = queryParams.dateRange;
  53. }
  54. }
  55. get getMoreFilter(){
  56. let flag = this.fieldConfig.fields.buildingDTO || this.fieldConfig.fields.deptDTO;
  57. return flag ? 37 : 0;
  58. }
  59. // 初始化缓存数据
  60. queryType:any;
  61. hosId:any;
  62. dutyId:any;
  63. parentDutyId:any;
  64. initSessionData(){
  65. let newStatistics = JSON.parse(sessionStorage.getItem('newStatistics'));
  66. let queryType:any = newStatistics.queryType;
  67. let hosId:any = newStatistics.hospitalId;
  68. let dutyId:any = newStatistics.dutyId;
  69. queryType = queryType ? +queryType : undefined;
  70. hosId = hosId ? +hosId : undefined;
  71. dutyId = dutyId ? +dutyId : undefined;
  72. this.queryType = queryType;
  73. if(queryType == 1){
  74. this.hosId = undefined;
  75. this.dutyId = undefined;
  76. this.parentDutyId = undefined;
  77. }else if(queryType == 2){
  78. this.hosId = hosId;
  79. this.dutyId = undefined;
  80. this.parentDutyId = undefined;
  81. }else if(queryType == 3){
  82. this.hosId = undefined;
  83. this.dutyId = dutyId;
  84. this.parentDutyId = undefined;
  85. }else if(queryType == 4){
  86. this.hosId = undefined;
  87. this.dutyId = undefined;
  88. this.parentDutyId = dutyId;
  89. }
  90. }
  91. get getHosId(){
  92. return this.parentDutyId || this.dutyId || this.hosId;
  93. }
  94. // 表格数据
  95. loading1 = false;
  96. dictionaryList: any[] = [];
  97. getList(num?: number, field?: string, sort?: string) {
  98. this.mainService.getDictionary('list', 'statistics_date_type').subscribe((data) => {
  99. let dictionaryList = data || [];
  100. let flag = dictionaryList.some((item) => item.value === 'dateOther');
  101. !flag && dictionaryList.push({id: 0, name: '其他', value: 'dateOther'});
  102. this.dictionaryList = dictionaryList;
  103. this.widthConfig = new Array(this.dictionaryList.length * 2 + 3).fill('100px').map((v, i) => { return i == 0 ? '150px' : '100px' });
  104. if (num !== undefined) {
  105. this.pageIndex = num;
  106. }
  107. let postData:any = {
  108. idx: this.pageIndex - 1,
  109. sum: this.pageSize,
  110. startDate: this.dateRange[0] || undefined,
  111. endDate: this.dateRange[1] || undefined,
  112. hosId: this.getHosId,
  113. buildingId: this.fieldConfig.fields.buildingId || undefined,
  114. deptId: this.fieldConfig.fields.deptId || undefined,
  115. groupId: this.groupId || undefined,
  116. };
  117. if (field && sort) {
  118. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  119. }
  120. this.loading1 = true;
  121. this.mainService
  122. .postCustom("itsm/report", "userTransOrder", postData)
  123. .subscribe((result) => {
  124. this.loading1 = false;
  125. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  126. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  127. this.listLength = result.totalCount;
  128. });
  129. });
  130. }
  131. // 列表排序
  132. sortCurrent:any = {};
  133. sortCurrentKey: string = "";
  134. sortCurrentValue: string | null = "";
  135. sort(e) {
  136. const { key, value } = e;
  137. this.sortCurrentKey = key;
  138. this.sortCurrentValue = value;
  139. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  140. }
  141. // 搜索
  142. search() {
  143. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  144. }
  145. // 日期选择
  146. 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')];
  147. changeDate(result?): void {
  148. result[0] = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss');
  149. result[1] = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss');
  150. this.dateRange = result;
  151. }
  152. onCalendarChangeDate(dateArr){
  153. console.log(dateArr)
  154. if(dateArr.length == 2){
  155. this.dateRange = [format(startOfDay(dateArr[0]), 'yyyy-MM-dd HH:mm:ss'), format(endOfDay(dateArr[1]), 'yyyy-MM-dd HH:mm:ss')];
  156. }
  157. }
  158. // 导出
  159. excelExportLoading:any = false;
  160. excelExport(){
  161. this.excelExportLoading = this.message.loading("导出中..", {
  162. nzDuration: 0,
  163. }).messageId;
  164. let postData:any = {
  165. startDate: this.dateRange[0] || undefined,
  166. endDate: this.dateRange[1] || undefined,
  167. hosId: this.getHosId,
  168. buildingId: this.fieldConfig.fields.buildingId || undefined,
  169. deptId: this.fieldConfig.fields.deptId || undefined,
  170. groupId: this.groupId || undefined,
  171. };
  172. if (this.sortCurrentKey && this.sortCurrentValue) {
  173. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  174. }
  175. this.mainService
  176. .postExportCustom("itsm/exportMergeTitle", "userTransOrder", postData)
  177. .subscribe((data) => {
  178. this.message.remove(this.excelExportLoading);
  179. this.excelExportLoading = false;
  180. this.message.success('导出成功');
  181. var file = new Blob([data], {
  182. type: "application/vnd.ms-excel",
  183. });
  184. //trick to download store a file having its URL
  185. var fileURL = URL.createObjectURL(file);
  186. var a = document.createElement("a");
  187. a.href = fileURL;
  188. a.target = "_blank";
  189. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  190. document.body.appendChild(a);
  191. a.click();
  192. },(err) => {
  193. this.message.remove(this.excelExportLoading);
  194. this.excelExportLoading = false;
  195. this.message.error('导出失败');
  196. });
  197. }
  198. // 重置
  199. reset(){
  200. this.sortCurrentKey = "";
  201. this.sortCurrentValue = "";
  202. this.sortCurrent = {};
  203. 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')]
  204. this.groupId = undefined;
  205. this.fieldConfig.fields = {buildingId: undefined, deptId: undefined};
  206. this.search();
  207. }
  208. // 分组搜索
  209. changeGroupInp(e) {
  210. this.searchTimer(this.getGroupList, e);
  211. }
  212. // 防抖
  213. isLoading = false;
  214. searchTimer(fun, e) {
  215. this.isLoading = true;
  216. this.searchTimerSubject.next([fun, e]);
  217. }
  218. openChangeGroup(flag){
  219. flag && this.getGroupList();
  220. }
  221. // 获取分组列表
  222. groupList:any[] = [];
  223. getGroupList(keyword?) {
  224. let data = {
  225. group2: {
  226. statisticalHosId: this.getHosId,
  227. groupName: keyword,
  228. },
  229. idx: 0,
  230. sum: 20,
  231. };
  232. this.isLoading = true;
  233. this.mainService
  234. .getFetchDataList("data", "group2", data)
  235. .subscribe((data) => {
  236. this.isLoading = false;
  237. this.groupList = data.list;
  238. });
  239. }
  240. // 详细搜索
  241. fieldConfig:any = {
  242. fields: {buildingId: undefined, deptId: undefined},
  243. config: {building: true, dept: 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. }