quilt-washing-trend-analysis.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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-trend-analysis",
  10. templateUrl: "./quilt-washing-trend-analysis.component.html",
  11. styleUrls: ["./quilt-washing-trend-analysis.component.less"],
  12. })
  13. export class QuiltWashingTrendAnalysisComponent 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. deptNum: null,
  155. clothesTypeNum: null,
  156. getOrder: null,
  157. sendOrder: null,
  158. sendClothesNum: null,
  159. price: null,
  160. };
  161. this.search();
  162. }
  163. // 表格数据
  164. loading1 = false;
  165. getList(num?: number, field?: string, sort?: string) {
  166. this.pageIndex = num;
  167. let postData: any = {
  168. idx: this.pageIndex - 1,
  169. sum: this.pageSize,
  170. startTime: this.searchData.dateRange.start,
  171. endTime: this.searchData.dateRange.end,
  172. hosId: this.searchData.hosId,
  173. type: this.dateType,
  174. };
  175. if (field && sort) {
  176. postData.sort = sort === "ascend" ? field : `${field} desc`;
  177. }
  178. this.loading1 = true;
  179. this.mainService
  180. .postCustom("report/clothes", "hospital", postData)
  181. .subscribe((result) => {
  182. this.loading1 = false;
  183. this.listOfData = result.list || [];
  184. this.listLength = result.totalNum;
  185. });
  186. }
  187. // 获取院区
  188. hospital: string; //选中院区
  189. getAllHos() {
  190. this.hospital = this.tool.getCurrentHospital().id + "";
  191. }
  192. // 修改时间展示维度
  193. changeDateType(res) {
  194. console.log(res, this.dateType);
  195. this.dateType = res;
  196. this.searchData["type"] = res;
  197. console.log(this.searchData);
  198. switch (res) {
  199. case "day":
  200. this.defRanges = [
  201. {
  202. label: "上周",
  203. id: 1,
  204. },
  205. {
  206. label: "上月",
  207. id: 2,
  208. },
  209. {
  210. label: "上年",
  211. id: 3,
  212. },
  213. ]; //时间默认区间
  214. this.defRange = "1"; //默认上周
  215. this.changeDateRange("1");
  216. break;
  217. case "month":
  218. this.defRanges = [
  219. {
  220. label: "上月",
  221. id: 2,
  222. },
  223. {
  224. label: "上年",
  225. id: 3,
  226. },
  227. ]; //时间默认区间
  228. this.defRange = "2"; //上月
  229. this.changeDateRange("2");
  230. break;
  231. case "year":
  232. this.defRanges = [
  233. {
  234. label: "上年",
  235. id: 3,
  236. },
  237. ]; //时间默认区间
  238. this.defRange = "3"; //默认上周
  239. this.changeDateRange("3");
  240. break;
  241. }
  242. }
  243. // 禁选日期
  244. disabledDate = (current: Date): boolean => {
  245. // Can not select days before today and today
  246. return differenceInCalendarDays(current, this.today) > 0;
  247. };
  248. // 禁选月份开始
  249. disabledMonthStart = (current: Date): boolean => {
  250. // Can not select days before today and today
  251. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  252. let staEnd = differenceInCalendarDays(current, this.monthRangeEnd) > 0;
  253. return cur || staEnd;
  254. };
  255. // 禁选月份结束
  256. disabledMonthEnd = (current: Date): boolean => {
  257. // Can not select days before today and today
  258. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  259. let staEnd = differenceInCalendarDays(this.monthRangeStart, current) > 0;
  260. return cur || staEnd;
  261. };
  262. // 禁选年份开始
  263. disabledYearStart = (current: Date): boolean => {
  264. // Can not select days before today and today
  265. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  266. let staEnd = differenceInCalendarDays(current, this.yearRangeEnd) > 0;
  267. return cur || staEnd;
  268. };
  269. // 禁选年份结束
  270. disabledYearEnd = (current: Date): boolean => {
  271. // Can not select days before today and today
  272. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  273. let staEnd = differenceInCalendarDays(this.yearRangeStart, current) > 0;
  274. return cur || staEnd;
  275. };
  276. // 日期选择 日
  277. startDate: string; //发起时间开始
  278. endDate: string; //发起时间结束
  279. changeDate(result?): void {
  280. console.log(this.dateRange);
  281. console.log(result);
  282. this.dateRange = result;
  283. if (!this.quick) {
  284. // 不是快捷选择
  285. this.defRange = null;
  286. }
  287. if (!result || !result.length) {
  288. this.startDate = this.endDate = "";
  289. return;
  290. }
  291. this.startDate =
  292. result[0].getFullYear() +
  293. "-" +
  294. (result[0].getMonth() + 1) +
  295. "-" +
  296. result[0].getDate();
  297. this.endDate =
  298. result[1].getFullYear() +
  299. "-" +
  300. (result[1].getMonth() + 1) +
  301. "-" +
  302. result[1].getDate();
  303. }
  304. // 月份选择
  305. changeMonthStart(result?) {
  306. console.log(result);
  307. this.monthRangeStart = result;
  308. if (!this.quick) {
  309. // 不是快捷选择
  310. this.defRange = null;
  311. }
  312. if (!result) {
  313. this.startDate = this.endDate = "";
  314. return;
  315. }
  316. this.startDate = format(startOfMonth(result), 'yyyy-MM-dd');
  317. // this.endDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  318. }
  319. changeMonthEnd(result?) {
  320. console.log(result);
  321. this.monthRangeEnd = result;
  322. if (!this.quick) {
  323. // 不是快捷选择
  324. this.defRange = null;
  325. }
  326. if (!result) {
  327. this.startDate = this.endDate = "";
  328. return;
  329. }
  330. // this.startDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  331. this.endDate = format(endOfMonth(result), 'yyyy-MM-dd');
  332. }
  333. // 年份选择
  334. changeYearStart(result?) {
  335. console.log(result);
  336. this.yearRangeStart = result;
  337. if (!this.quick) {
  338. // 不是快捷选择
  339. this.defRange = null;
  340. }
  341. if (!result) {
  342. this.startDate = this.endDate = "";
  343. return;
  344. }
  345. this.startDate = format(startOfYear(result), 'yyyy-MM-dd');
  346. // this.endDate = result.getFullYear() + '-01-01';
  347. }
  348. changeYearEnd(result?) {
  349. console.log(result);
  350. this.yearRangeEnd = result;
  351. if (!this.quick) {
  352. // 不是快捷选择
  353. this.defRange = null;
  354. }
  355. if (!result) {
  356. this.startDate = this.endDate = "";
  357. return;
  358. }
  359. this.endDate = format(endOfYear(result), 'yyyy-MM-dd');
  360. }
  361. // 日期选择 快速修改时间区间
  362. today = new Date();
  363. quick: boolean = false;
  364. changeDateRange(res) {
  365. console.log(res);
  366. this.quick = true;
  367. switch (res) {
  368. case "1":
  369. // 上周
  370. let lastweekstartdate = this.dateService.date().lastWeekStartDate;
  371. let lastweekenddate = this.dateService.date().lastWeekEndDate;
  372. console.log(lastweekstartdate, lastweekenddate);
  373. this.changeDate([lastweekstartdate, lastweekenddate]);
  374. break;
  375. case "2":
  376. // 上月
  377. let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
  378. let lastmonthenddate = this.dateService.date().lastMonthEndDate;
  379. console.log(lastmonthstartdate, lastmonthenddate);
  380. this.changeDate([lastmonthstartdate, lastmonthenddate]);
  381. this.changeMonthStart(lastmonthstartdate);
  382. this.changeMonthEnd(lastmonthenddate);
  383. break;
  384. case "3":
  385. // 上年
  386. let lastyearstartdate = this.dateService.date().lastYearStartDate;
  387. let lastyearenddate = this.dateService.date().lastYearEndDate;
  388. console.log(lastyearstartdate, lastyearenddate);
  389. this.changeDate([lastyearstartdate, lastyearenddate]);
  390. this.changeMonthStart(lastyearstartdate);
  391. this.changeMonthEnd(lastyearenddate);
  392. this.changeYearStart(lastyearstartdate);
  393. this.changeYearEnd(lastyearenddate);
  394. break;
  395. }
  396. this.quick = false;
  397. this.search();
  398. }
  399. // 更多
  400. toMore(type) {
  401. let sendData = this.searchData;
  402. console.log(sendData);
  403. this.myService.sendMsg(sendData);
  404. this.router.navigateByUrl("/main/" + type);
  405. }
  406. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  407. showPromptModal(con, success, promptInfo?) {
  408. this.promptModalShow = false;
  409. this.promptContent = con;
  410. this.ifSuccess = success;
  411. this.promptInfo = promptInfo;
  412. setTimeout(() => {
  413. this.promptModalShow = true;
  414. }, 100);
  415. }
  416. // 边输入边搜索节流阀
  417. isLoading: boolean = false;
  418. searchTimer(fun, e, those) {
  419. let that = this;
  420. that.isLoading = true;
  421. fun(e, those);
  422. }
  423. // 列表排序
  424. sortCurrent = {
  425. deptNum: null,
  426. clothesTypeNum: null,
  427. getOrder: null,
  428. sendOrder: null,
  429. sendClothesNum: null,
  430. price: null,
  431. };
  432. sortCurrentKey: string = "";
  433. sortCurrentValue: string | null = "";
  434. sort(e) {
  435. const { key, value } = e;
  436. this.sortCurrentKey = key;
  437. this.sortCurrentValue = value;
  438. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  439. }
  440. }