medical-waste-personnel-statistics.component.ts 15 KB

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