quilt-washing-hospital-statistics.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { differenceInCalendarDays, endOfMonth, endOfYear, format, startOfMonth, startOfYear } from "date-fns";
  4. import { MainService } from "../../services/main.service";
  5. import { DateService } from "../../services/date.service";
  6. import { MyServiceService } from "../../services/my-service.service";
  7. import { ToolService } from "../../services/tool.service";
  8. @Component({
  9. selector: "app-quilt-washing-hospital-statistics",
  10. templateUrl: "./quilt-washing-hospital-statistics.component.html",
  11. styleUrls: ["./quilt-washing-hospital-statistics.component.less"],
  12. })
  13. export class QuiltWashingHospitalStatisticsComponent implements OnInit {
  14. constructor(
  15. private route: ActivatedRoute,
  16. private router: Router,
  17. private mainService: MainService,
  18. private dateService: DateService,
  19. private myService: MyServiceService,
  20. private tool: ToolService
  21. ) {}
  22. ngOnInit() {
  23. this.coopBtns = this.tool.initCoopBtns(this.route);
  24. this.getAllHos();
  25. this.changeDateRange(this.defRange);
  26. this.search();
  27. }
  28. dateType: string = "day"; //选中时间维度
  29. dateTypes: any = [
  30. {
  31. label: "按天统计",
  32. value: "day",
  33. },
  34. {
  35. label: "按月统计",
  36. value: "month",
  37. },
  38. {
  39. label: "按年统计",
  40. value: "year",
  41. },
  42. ]; //时间维度
  43. defRange = "1"; //默认上周
  44. defRanges = [
  45. {
  46. label: "上周",
  47. id: 1,
  48. },
  49. {
  50. label: "上月",
  51. id: 2,
  52. },
  53. {
  54. label: "上年",
  55. id: 3,
  56. },
  57. ]; //时间默认区间
  58. listOfData: any[] = []; //表格数据
  59. pageIndex: number = 1; //表格当前页码
  60. pageSize: number = 10; //表格每页展示条数
  61. listLength: number = 10; //表格总数据量
  62. alldepart: any = []; //当前院区所属科室
  63. dateRange: any = []; //发起时间区间 天
  64. monthRangeStart: any; //发起时间 月 起
  65. monthRangeEnd: any; //发起时间 月 止
  66. yearRangeStart: any; //发起时间 年 起
  67. yearRangeEnd: any; //发起时间 年 止
  68. promptContent: string; //操作提示框提示信息
  69. ifSuccess: boolean; //操作成功/失败
  70. promptInfo: string; //操作结果提示信息
  71. promptModalShow: boolean; //操作提示框是否展示
  72. // 初始化增删改按钮
  73. coopBtns: any = {};
  74. searchData: any = {}; // 综合统计页面带过来的参数
  75. getSearchData() {
  76. let that = this;
  77. let sub = that.myService.getMsg().subscribe((msg) => {
  78. // 从综合报表跳转过来
  79. that.searchData = msg;
  80. console.log(that.searchData);
  81. console.log(66);
  82. sub.unsubscribe(); //取消订阅,否则订阅函数会累加执行
  83. that.hospital = that.searchData["hosId"];
  84. that.changeDate(that.searchData["range"]);
  85. that.defRange = that.searchData["defRange"];
  86. that.search();
  87. });
  88. that.changeDateRange(that.defRange);
  89. that.search();
  90. }
  91. // 搜索
  92. search(num?: number) {
  93. if (this.hospital) {
  94. this.searchData["hosId"] = this.hospital;
  95. }
  96. if (this.startDate) {
  97. this.searchData["dateRange"] = {
  98. start: this.startDate + " " + "00:00:00",
  99. end: this.endDate + " " + "23:59:59",
  100. };
  101. }
  102. if (num !== undefined) {
  103. this.getList(num, this.sortCurrentKey, this.sortCurrentValue);
  104. } else {
  105. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  106. }
  107. }
  108. // 导出
  109. loading2 = false;
  110. export() {
  111. let that = this;
  112. let postData: any = {
  113. startTime: this.startDate + " " + "00:00:00",
  114. endTime: this.endDate + " " + "23:59:59",
  115. hosId: that.hospital,
  116. type: this.dateType,
  117. };
  118. if (this.sortCurrentKey && this.sortCurrentValue) {
  119. postData.sort =
  120. this.sortCurrentValue === "ascend"
  121. ? this.sortCurrentKey
  122. : `${this.sortCurrentKey} desc`;
  123. }
  124. this.loading2 = true;
  125. that.mainService.exportReport("clothesHos", postData).subscribe(
  126. (data) => {
  127. this.loading2 = false;
  128. this.showPromptModal("导出", true, "");
  129. var file = new Blob([data], {
  130. type: "application/vnd.ms-excel",
  131. });
  132. //trick to download store a file having its URL
  133. var fileURL = URL.createObjectURL(file);
  134. var a = document.createElement("a");
  135. a.href = fileURL;
  136. a.target = "_blank";
  137. a.download = "全员统计.xls";
  138. document.body.appendChild(a);
  139. a.click();
  140. },
  141. (err) => {
  142. this.loading2 = false;
  143. this.showPromptModal("导出", false, "");
  144. }
  145. );
  146. }
  147. // 重置
  148. reset() {
  149. this.changeDateType("day");
  150. this.changeDateRange("1");
  151. this.sortCurrentKey = "";
  152. this.sortCurrentValue = "";
  153. this.sortCurrent = {
  154. source1: null,
  155. source2: null,
  156. source3: null,
  157. source4: null,
  158. };
  159. this.search();
  160. }
  161. // 表格数据
  162. loading1 = false;
  163. getList(num?: number, field?: string, sort?: string) {
  164. this.pageIndex = num;
  165. let postData: any = {
  166. idx: this.pageIndex - 1,
  167. sum: this.pageSize,
  168. startTime: this.searchData.dateRange.start,
  169. endTime: this.searchData.dateRange.end,
  170. hosId: this.searchData.hosId,
  171. type: this.dateType,
  172. };
  173. if (field && sort) {
  174. postData.sort = sort === "ascend" ? field : `${field} desc`;
  175. }
  176. this.loading1 = true;
  177. this.mainService
  178. .postCustom("report/clothes", "hospital", postData)
  179. .subscribe((result) => {
  180. this.loading1 = false;
  181. this.listOfData = result.list || [];
  182. this.listLength = result.totalNum;
  183. });
  184. }
  185. // 获取院区
  186. hospital: string; //选中院区
  187. getAllHos() {
  188. this.hospital = this.tool.getCurrentHospital().id + "";
  189. }
  190. // 修改时间展示维度
  191. changeDateType(res) {
  192. console.log(res, this.dateType);
  193. this.dateType = res;
  194. this.searchData["type"] = res;
  195. console.log(this.searchData);
  196. switch (res) {
  197. case "day":
  198. this.defRanges = [
  199. {
  200. label: "上周",
  201. id: 1,
  202. },
  203. {
  204. label: "上月",
  205. id: 2,
  206. },
  207. {
  208. label: "上年",
  209. id: 3,
  210. },
  211. ]; //时间默认区间
  212. this.defRange = "1"; //默认上周
  213. this.changeDateRange("1");
  214. break;
  215. case "month":
  216. this.defRanges = [
  217. {
  218. label: "上月",
  219. id: 2,
  220. },
  221. {
  222. label: "上年",
  223. id: 3,
  224. },
  225. ]; //时间默认区间
  226. this.defRange = "2"; //上月
  227. this.changeDateRange("2");
  228. break;
  229. case "year":
  230. this.defRanges = [
  231. {
  232. label: "上年",
  233. id: 3,
  234. },
  235. ]; //时间默认区间
  236. this.defRange = "3"; //默认上周
  237. this.changeDateRange("3");
  238. break;
  239. }
  240. }
  241. // 禁选日期
  242. disabledDate = (current: Date): boolean => {
  243. // Can not select days before today and today
  244. return differenceInCalendarDays(current, this.today) > 0;
  245. };
  246. // 禁选月份开始
  247. disabledMonthStart = (current: Date): boolean => {
  248. // Can not select days before today and today
  249. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  250. let staEnd = differenceInCalendarDays(current, this.monthRangeEnd) > 0;
  251. return cur || staEnd;
  252. };
  253. // 禁选月份结束
  254. disabledMonthEnd = (current: Date): boolean => {
  255. // Can not select days before today and today
  256. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  257. let staEnd = differenceInCalendarDays(this.monthRangeStart, current) > 0;
  258. return cur || staEnd;
  259. };
  260. // 禁选年份开始
  261. disabledYearStart = (current: Date): boolean => {
  262. // Can not select days before today and today
  263. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  264. let staEnd = differenceInCalendarDays(current, this.yearRangeEnd) > 0;
  265. return cur || staEnd;
  266. };
  267. // 禁选年份结束
  268. disabledYearEnd = (current: Date): boolean => {
  269. // Can not select days before today and today
  270. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  271. let staEnd = differenceInCalendarDays(this.yearRangeStart, current) > 0;
  272. return cur || staEnd;
  273. };
  274. // 日期选择 日
  275. startDate: string; //发起时间开始
  276. endDate: string; //发起时间结束
  277. changeDate(result?): void {
  278. console.log(this.dateRange);
  279. console.log(result);
  280. this.dateRange = result;
  281. if (!this.quick) {
  282. // 不是快捷选择
  283. this.defRange = null;
  284. }
  285. if (!result || !result.length) {
  286. this.startDate = this.endDate = "";
  287. return;
  288. }
  289. this.startDate =
  290. result[0].getFullYear() +
  291. "-" +
  292. (result[0].getMonth() + 1) +
  293. "-" +
  294. result[0].getDate();
  295. this.endDate =
  296. result[1].getFullYear() +
  297. "-" +
  298. (result[1].getMonth() + 1) +
  299. "-" +
  300. result[1].getDate();
  301. }
  302. // 月份选择
  303. changeMonthStart(result?) {
  304. console.log(result);
  305. this.monthRangeStart = result;
  306. if (!this.quick) {
  307. // 不是快捷选择
  308. this.defRange = null;
  309. }
  310. if (!result) {
  311. this.startDate = this.endDate = "";
  312. return;
  313. }
  314. this.startDate = format(startOfMonth(result), 'yyyy-MM-dd');
  315. // this.endDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  316. }
  317. changeMonthEnd(result?) {
  318. console.log(result);
  319. this.monthRangeEnd = result;
  320. if (!this.quick) {
  321. // 不是快捷选择
  322. this.defRange = null;
  323. }
  324. if (!result) {
  325. this.startDate = this.endDate = "";
  326. return;
  327. }
  328. // this.startDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  329. this.endDate = format(endOfMonth(result), 'yyyy-MM-dd');
  330. }
  331. // 年份选择
  332. changeYearStart(result?) {
  333. console.log(result);
  334. this.yearRangeStart = result;
  335. if (!this.quick) {
  336. // 不是快捷选择
  337. this.defRange = null;
  338. }
  339. if (!result) {
  340. this.startDate = this.endDate = "";
  341. return;
  342. }
  343. this.startDate = format(startOfYear(result), 'yyyy-MM-dd');
  344. // this.endDate = result.getFullYear() + '-01-01';
  345. }
  346. changeYearEnd(result?) {
  347. console.log(result);
  348. this.yearRangeEnd = result;
  349. if (!this.quick) {
  350. // 不是快捷选择
  351. this.defRange = null;
  352. }
  353. if (!result) {
  354. this.startDate = this.endDate = "";
  355. return;
  356. }
  357. this.endDate = format(endOfYear(result), 'yyyy-MM-dd');
  358. }
  359. // 日期选择 快速修改时间区间
  360. today = new Date();
  361. quick: boolean = false;
  362. changeDateRange(res) {
  363. console.log(res);
  364. this.quick = true;
  365. switch (res) {
  366. case "1":
  367. // 上周
  368. let lastweekstartdate = this.dateService.date().lastWeekStartDate;
  369. let lastweekenddate = this.dateService.date().lastWeekEndDate;
  370. console.log(lastweekstartdate, lastweekenddate);
  371. this.changeDate([lastweekstartdate, lastweekenddate]);
  372. break;
  373. case "2":
  374. // 上月
  375. let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
  376. let lastmonthenddate = this.dateService.date().lastMonthEndDate;
  377. console.log(lastmonthstartdate, lastmonthenddate);
  378. this.changeDate([lastmonthstartdate, lastmonthenddate]);
  379. this.changeMonthStart(lastmonthstartdate);
  380. this.changeMonthEnd(lastmonthenddate);
  381. break;
  382. case "3":
  383. // 上年
  384. let lastyearstartdate = this.dateService.date().lastYearStartDate;
  385. let lastyearenddate = this.dateService.date().lastYearEndDate;
  386. console.log(lastyearstartdate, lastyearenddate);
  387. this.changeDate([lastyearstartdate, lastyearenddate]);
  388. this.changeMonthStart(lastyearstartdate);
  389. this.changeMonthEnd(lastyearenddate);
  390. this.changeYearStart(lastyearstartdate);
  391. this.changeYearEnd(lastyearenddate);
  392. break;
  393. }
  394. this.quick = false;
  395. this.search();
  396. }
  397. // 更多
  398. toMore(type) {
  399. let sendData = this.searchData;
  400. console.log(sendData);
  401. this.myService.sendMsg(sendData);
  402. this.router.navigateByUrl("/main/" + type);
  403. }
  404. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  405. showPromptModal(con, success, promptInfo?) {
  406. this.promptModalShow = false;
  407. this.promptContent = con;
  408. this.ifSuccess = success;
  409. this.promptInfo = promptInfo;
  410. setTimeout(() => {
  411. this.promptModalShow = true;
  412. }, 100);
  413. }
  414. // 边输入边搜索节流阀
  415. isLoading: boolean = false;
  416. searchTimer(fun, e, those) {
  417. let that = this;
  418. that.isLoading = true;
  419. fun(e, those);
  420. }
  421. // 列表排序
  422. sortCurrent = {
  423. source1: null,
  424. source2: null,
  425. source3: null,
  426. source4: null,
  427. };
  428. sortCurrentKey: string = "";
  429. sortCurrentValue: string | null = "";
  430. sort(e) {
  431. const { key, value } = e;
  432. this.sortCurrentKey = key;
  433. this.sortCurrentValue = value;
  434. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  435. }
  436. }