quilt-washing-personnel-statistics.component.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. import { Subject } from 'rxjs';
  9. import { debounceTime } from 'rxjs/operators';
  10. @Component({
  11. selector: "app-quilt-washing-personnel-statistics",
  12. templateUrl: "./quilt-washing-personnel-statistics.component.html",
  13. styleUrls: ["./quilt-washing-personnel-statistics.component.less"],
  14. })
  15. export class QuiltWashingPersonnelStatisticsComponent 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("clothesPersonal", 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.changeDateType("day");
  203. this.changeDateRange("1");
  204. this.sortCurrentKey = "";
  205. this.sortCurrentValue = "";
  206. this.sortCurrent = {
  207. totalTrip: null,
  208. totalOrder: null,
  209. getTrip: null,
  210. getOrder: null,
  211. sendTrip: null,
  212. sendOrder: null,
  213. };
  214. this.searchDto = {
  215. group: null,
  216. user: null,
  217. }
  218. this.search();
  219. }
  220. // 表格数据
  221. loading1 = false;
  222. getList(num?: number, field?: string, sort?: string) {
  223. this.pageIndex = num;
  224. let postData: any = {
  225. idx: this.pageIndex - 1,
  226. sum: this.pageSize,
  227. startTime: this.searchData.dateRange.start,
  228. endTime: this.searchData.dateRange.end,
  229. hosId: this.searchData.hosId,
  230. type: this.dateType,
  231. userId: this.searchDto.user || undefined,
  232. groupId: this.searchDto.group || undefined,
  233. };
  234. if (field && sort) {
  235. postData.sort = sort === "ascend" ? field : `${field} desc`;
  236. }
  237. this.loading1 = true;
  238. this.mainService
  239. .postCustom("report/clothes", "personal", postData)
  240. .subscribe((result) => {
  241. this.loading1 = false;
  242. this.listOfData = result.list || [];
  243. this.listLength = result.totalNum;
  244. });
  245. }
  246. // 获取院区
  247. hospital: string; //选中院区
  248. getAllHos() {
  249. this.hospital = this.tool.getCurrentHospital().id + "";
  250. this.getGroupList(this.hospital);
  251. this.getUserList();
  252. }
  253. onCalendarChangeDate(dateArr){
  254. console.log(dateArr)
  255. if(dateArr.length == 2){
  256. let dateStart = new Date(dateArr[0]);
  257. let dateEnd = new Date(dateArr[1]);
  258. dateStart.setHours(0,0,0);
  259. dateEnd.setHours(23,59,59);
  260. this.dateRange = [dateStart,dateEnd];
  261. }
  262. }
  263. // 修改时间展示维度
  264. changeDateType(res) {
  265. console.log(res, this.dateType);
  266. this.dateType = res;
  267. this.searchData["type"] = res;
  268. console.log(this.searchData);
  269. switch (res) {
  270. case "day":
  271. this.defRanges = [
  272. {
  273. label: "上周",
  274. id: 1,
  275. },
  276. {
  277. label: "上月",
  278. id: 2,
  279. },
  280. {
  281. label: "上年",
  282. id: 3,
  283. },
  284. ]; //时间默认区间
  285. this.defRange = "1"; //默认上周
  286. this.changeDateRange("1");
  287. break;
  288. case "month":
  289. this.defRanges = [
  290. {
  291. label: "上月",
  292. id: 2,
  293. },
  294. {
  295. label: "上年",
  296. id: 3,
  297. },
  298. ]; //时间默认区间
  299. this.defRange = "2"; //上月
  300. this.changeDateRange("2");
  301. break;
  302. case "year":
  303. this.defRanges = [
  304. {
  305. label: "上年",
  306. id: 3,
  307. },
  308. ]; //时间默认区间
  309. this.defRange = "3"; //默认上周
  310. this.changeDateRange("3");
  311. break;
  312. }
  313. }
  314. // 禁选日期
  315. disabledDate = (current: Date): boolean => {
  316. // Can not select days before today and today
  317. return differenceInCalendarDays(current, this.today) > 0;
  318. };
  319. // 禁选月份开始
  320. disabledMonthStart = (current: Date): boolean => {
  321. // Can not select days before today and today
  322. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  323. let staEnd = differenceInCalendarDays(current, this.monthRangeEnd) > 0;
  324. return cur || staEnd;
  325. };
  326. // 禁选月份结束
  327. disabledMonthEnd = (current: Date): boolean => {
  328. // Can not select days before today and today
  329. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  330. let staEnd = differenceInCalendarDays(this.monthRangeStart, current) > 0;
  331. return cur || staEnd;
  332. };
  333. // 禁选年份开始
  334. disabledYearStart = (current: Date): boolean => {
  335. // Can not select days before today and today
  336. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  337. let staEnd = differenceInCalendarDays(current, this.yearRangeEnd) > 0;
  338. return cur || staEnd;
  339. };
  340. // 禁选年份结束
  341. disabledYearEnd = (current: Date): boolean => {
  342. // Can not select days before today and today
  343. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  344. let staEnd = differenceInCalendarDays(this.yearRangeStart, current) > 0;
  345. return cur || staEnd;
  346. };
  347. // 日期选择 日
  348. startDate: string; //发起时间开始
  349. endDate: string; //发起时间结束
  350. changeDate(result?): void {
  351. console.log(this.dateRange);
  352. console.log(result);
  353. this.dateRange = result;
  354. if (!this.quick) {
  355. // 不是快捷选择
  356. this.defRange = null;
  357. }
  358. if (!result || !result.length) {
  359. this.startDate = this.endDate = "";
  360. return;
  361. }
  362. this.startDate = format(result[0], 'yyyy-MM-dd HH:mm:ss');
  363. this.endDate = format(result[1], 'yyyy-MM-dd HH:mm:ss');
  364. }
  365. // 月份选择
  366. changeMonthStart(result?) {
  367. console.log(result);
  368. this.monthRangeStart = result;
  369. if (!this.quick) {
  370. // 不是快捷选择
  371. this.defRange = null;
  372. }
  373. if (!result) {
  374. this.startDate = this.endDate = "";
  375. return;
  376. }
  377. this.startDate = format(startOfMonth(result), 'yyyy-MM-dd HH:mm:ss');
  378. // this.endDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  379. }
  380. changeMonthEnd(result?) {
  381. console.log(result);
  382. this.monthRangeEnd = result;
  383. if (!this.quick) {
  384. // 不是快捷选择
  385. this.defRange = null;
  386. }
  387. if (!result) {
  388. this.startDate = this.endDate = "";
  389. return;
  390. }
  391. // this.startDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  392. this.endDate = format(endOfMonth(result), 'yyyy-MM-dd HH:mm:ss');
  393. }
  394. // 年份选择
  395. changeYearStart(result?) {
  396. console.log(result);
  397. this.yearRangeStart = result;
  398. if (!this.quick) {
  399. // 不是快捷选择
  400. this.defRange = null;
  401. }
  402. if (!result) {
  403. this.startDate = this.endDate = "";
  404. return;
  405. }
  406. this.startDate = format(startOfYear(result), 'yyyy-MM-dd HH:mm:ss');
  407. // this.endDate = result.getFullYear() + '-01-01';
  408. }
  409. changeYearEnd(result?) {
  410. console.log(result);
  411. this.yearRangeEnd = result;
  412. if (!this.quick) {
  413. // 不是快捷选择
  414. this.defRange = null;
  415. }
  416. if (!result) {
  417. this.startDate = this.endDate = "";
  418. return;
  419. }
  420. this.endDate = format(endOfYear(result), 'yyyy-MM-dd HH:mm:ss');
  421. }
  422. // 日期选择 快速修改时间区间
  423. today = new Date();
  424. quick: boolean = false;
  425. changeDateRange(res) {
  426. console.log(res);
  427. this.quick = true;
  428. switch (res) {
  429. case "1":
  430. // 上周
  431. let lastweekstartdate = this.dateService.date().lastWeekStartDate;
  432. let lastweekenddate = this.dateService.date().lastWeekEndDate;
  433. console.log(lastweekstartdate, lastweekenddate);
  434. this.changeDate([lastweekstartdate, lastweekenddate]);
  435. break;
  436. case "2":
  437. // 上月
  438. let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
  439. let lastmonthenddate = this.dateService.date().lastMonthEndDate;
  440. console.log(lastmonthstartdate, lastmonthenddate);
  441. this.changeDate([lastmonthstartdate, lastmonthenddate]);
  442. this.changeMonthStart(lastmonthstartdate);
  443. this.changeMonthEnd(lastmonthenddate);
  444. break;
  445. case "3":
  446. // 上年
  447. let lastyearstartdate = this.dateService.date().lastYearStartDate;
  448. let lastyearenddate = this.dateService.date().lastYearEndDate;
  449. console.log(lastyearstartdate, lastyearenddate);
  450. this.changeDate([lastyearstartdate, lastyearenddate]);
  451. this.changeMonthStart(lastyearstartdate);
  452. this.changeMonthEnd(lastyearenddate);
  453. this.changeYearStart(lastyearstartdate);
  454. this.changeYearEnd(lastyearenddate);
  455. break;
  456. }
  457. this.quick = false;
  458. this.search();
  459. }
  460. // 更多
  461. toMore(type) {
  462. let sendData = this.searchData;
  463. console.log(sendData);
  464. this.myService.sendMsg(sendData);
  465. this.router.navigateByUrl("/main/" + type);
  466. }
  467. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  468. showPromptModal(con, success, promptInfo?) {
  469. this.promptModalShow = false;
  470. this.promptContent = con;
  471. this.ifSuccess = success;
  472. this.promptInfo = promptInfo;
  473. setTimeout(() => {
  474. this.promptModalShow = true;
  475. }, 100);
  476. }
  477. // 边输入边搜索节流阀
  478. isLoading: boolean = false;
  479. searchTimer(fun, e) {
  480. this.isLoading = true;
  481. this.searchTimerSubject.next([fun, e]);
  482. }
  483. // 列表排序
  484. sortCurrent = {
  485. totalTrip: null,
  486. totalOrder: null,
  487. getTrip: null,
  488. getOrder: null,
  489. sendTrip: null,
  490. sendOrder: null,
  491. };
  492. sortCurrentKey: string = "";
  493. sortCurrentValue: string | null = "";
  494. sort(e) {
  495. const { key, value } = e;
  496. this.sortCurrentKey = key;
  497. this.sortCurrentValue = value;
  498. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  499. }
  500. }