medical-waste-hospital-statistics.component.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { differenceInCalendarDays, endOfMonth, endOfYear, format, startOfMonth, startOfYear, startOfDay, endOfDay } 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 { NzMessageService } from 'ng-zorro-antd';
  9. @Component({
  10. selector: "app-medical-waste-hospital-statistics",
  11. templateUrl: "./medical-waste-hospital-statistics.component.html",
  12. styleUrls: ["./medical-waste-hospital-statistics.component.less"],
  13. })
  14. export class MedicalWasteHospitalStatisticsComponent implements OnInit {
  15. constructor(
  16. private route: ActivatedRoute,
  17. private router: Router,
  18. private mainService: MainService,
  19. private dateService: DateService,
  20. private myService: MyServiceService,
  21. private message: NzMessageService,
  22. private tool: ToolService
  23. ) {}
  24. ngOnInit() {
  25. this.coopBtns = this.tool.initCoopBtns(this.route);
  26. this.getAllHos();
  27. this.changeDateRange(this.defRange);
  28. // this.search();
  29. }
  30. dataType:string = 'outbound';
  31. checkOptionsOne: Array<any> = [
  32. { label: "回收重量", value: "recovery", checked: true },
  33. { label: "出库总重量", value: "outbound", checked: false },
  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. heads: any[] = []; //表头数据
  66. listOfData: any[] = []; //表格数据
  67. pageIndex: number = 1; //表格当前页码
  68. pageSize: number = 10; //表格每页展示条数
  69. listLength: number = 10; //表格总数据量
  70. alldepart: any = []; //当前院区所属科室
  71. dateRange: any = []; //发起时间区间 天
  72. monthRangeStart: any; //发起时间 月 起
  73. monthRangeEnd: any; //发起时间 月 止
  74. yearRangeStart: any; //发起时间 年 起
  75. yearRangeEnd: any; //发起时间 年 止
  76. promptContent: string; //操作提示框提示信息
  77. ifSuccess: boolean; //操作成功/失败
  78. promptInfo: string; //操作结果提示信息
  79. promptModalShow: boolean; //操作提示框是否展示
  80. // 初始化增删改按钮
  81. coopBtns: any = {};
  82. searchData: any = {}; // 综合统计页面带过来的参数
  83. getSearchData() {
  84. let that = this;
  85. let sub = that.myService.getMsg().subscribe((msg) => {
  86. // 从综合报表跳转过来
  87. that.searchData = msg;
  88. console.log(that.searchData);
  89. console.log(66);
  90. sub.unsubscribe(); //取消订阅,否则订阅函数会累加执行
  91. that.hospital = that.searchData["hosId"];
  92. that.changeDate(that.searchData["range"]);
  93. that.defRange = that.searchData["defRange"];
  94. that.search();
  95. });
  96. that.changeDateRange(that.defRange);
  97. that.search();
  98. }
  99. // 搜索
  100. search(num?: number) {
  101. if (this.hospital) {
  102. this.searchData["hosId"] = this.hospital;
  103. }
  104. if (this.startDate) {
  105. this.searchData["dateRange"] = {
  106. start: this.startDate,
  107. end: this.endDate,
  108. };
  109. }
  110. if (num !== undefined) {
  111. this.getList(num, this.sortCurrentKey, this.sortCurrentValue);
  112. } else {
  113. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  114. }
  115. }
  116. // 导出
  117. loading2 = false;
  118. export() {
  119. let that = this;
  120. let postData: any = {
  121. startTime: this.startDate,
  122. endTime: this.endDate,
  123. hosId: that.hospital,
  124. type: this.dateType,
  125. dataType: this.dataType || undefined,
  126. };
  127. if (this.sortCurrentKey && this.sortCurrentValue) {
  128. postData.sort =
  129. this.sortCurrentValue === "ascend"
  130. ? this.sortCurrentKey
  131. : `${this.sortCurrentKey} desc`;
  132. }
  133. this.loading2 = true;
  134. that.mainService.exportReport("medicalWasteHospital", postData).subscribe(
  135. (data) => {
  136. this.loading2 = false;
  137. this.showPromptModal("导出", true, "");
  138. var file = new Blob([data], {
  139. type: "application/vnd.ms-excel",
  140. });
  141. //trick to download store a file having its URL
  142. var fileURL = URL.createObjectURL(file);
  143. var a = document.createElement("a");
  144. a.href = fileURL;
  145. a.target = "_blank";
  146. a.download = "全院统计.xls";
  147. document.body.appendChild(a);
  148. a.click();
  149. },
  150. (err) => {
  151. this.loading2 = false;
  152. this.showPromptModal("导出", false, "");
  153. }
  154. );
  155. }
  156. // 重置
  157. reset() {
  158. this.dataType = 'outbound';
  159. this.sortCurrentKey = "";
  160. this.sortCurrentValue = "";
  161. this.sortCurrent = {
  162. deptNum: null,
  163. clothesTypeNum: null,
  164. getOrder: null,
  165. sendOrder: null,
  166. sendClothesNum: null,
  167. price: null,
  168. };
  169. this.changeDateType("day");
  170. }
  171. // 医废类型-图表
  172. pieChartOption;
  173. pieChartHandler(datas) {
  174. console.log(datas)
  175. let labels = [];
  176. let nums = [];
  177. if (datas.length) {
  178. datas.forEach((e) => {
  179. labels.push(e[0]);
  180. nums.push({
  181. name: e[0],
  182. value: e[1],
  183. label: {
  184. position: e[1] >= 0 ? 'bottom' : 'top',
  185. }
  186. });
  187. });
  188. }
  189. this.pieChartOption = {
  190. color: ["#6c63f0", "#b750be", "#3aacff", "#ed589d", "#fb466c", "#00d6f6"],
  191. tooltip: {
  192. trigger: "item",
  193. axisPointer: {
  194. // 坐标轴指示器,坐标轴触发有效
  195. type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
  196. },
  197. formatter: '{b}: {c}kg'
  198. },
  199. legend: {
  200. orient: 'vertical',
  201. right: 20,
  202. top: 'center'
  203. },
  204. grid: {
  205. left: "9px",
  206. right: "9px",
  207. bottom: "20px",
  208. top: "20px",
  209. containLabel: true,
  210. },
  211. series: [
  212. {
  213. type: 'pie',
  214. radius: '50%',
  215. data: nums,
  216. emphasis: {
  217. itemStyle: {
  218. shadowBlur: 10,
  219. shadowOffsetX: 0,
  220. shadowColor: 'rgba(0, 0, 0, 0.5)'
  221. }
  222. },
  223. label: {
  224. show: true,
  225. formatter: "{b} {d}%"
  226. },
  227. },
  228. ],
  229. };
  230. }
  231. // 回收及出库重量-图表
  232. barChartOption;
  233. barChartHandler(datas) {
  234. console.log(datas)
  235. let labels = [];
  236. let nums = [];
  237. if (datas.length) {
  238. datas.forEach((e) => {
  239. labels.push(e[0]);
  240. nums.push({
  241. name: e[0],
  242. value: e[1],
  243. label: {
  244. position: 'top',
  245. },
  246. itemStyle: {
  247. color: e[0] === '回收' ? '#3588fa' : '#00d6f6'
  248. }
  249. });
  250. });
  251. }
  252. this.barChartOption = {
  253. tooltip: {
  254. trigger: "axis",
  255. axisPointer: {
  256. // 坐标轴指示器,坐标轴触发有效
  257. type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
  258. },
  259. formatter: '{b}: {c}kg'
  260. },
  261. grid: {
  262. left: "9px",
  263. right: "9px",
  264. bottom: "20px",
  265. top: "20px",
  266. containLabel: true,
  267. },
  268. xAxis: [
  269. {
  270. type: "category",
  271. data: labels,
  272. axisTick: {
  273. alignWithLabel: true,
  274. },
  275. },
  276. ],
  277. yAxis: [
  278. {
  279. type: "value",
  280. axisLabel: {
  281. formatter: "{value}kg",
  282. },
  283. nameTextStyle: {
  284. align: "left",
  285. },
  286. },
  287. ],
  288. series: [
  289. {
  290. name: "",
  291. type: "bar",
  292. barWidth: "35",
  293. data: nums,
  294. label: {
  295. show: true,
  296. color: '#000',
  297. formatter: '{c}kg'
  298. },
  299. },
  300. ],
  301. };
  302. }
  303. // 表格数据
  304. loading1 = false;
  305. pieChart: any = [];
  306. barChart: any = [];
  307. getList(num?: number, field?: string, sort?: string) {
  308. let maskFlag = this.message.loading("正在加载中..", {
  309. nzDuration: 0,
  310. }).messageId;
  311. this.pageIndex = num;
  312. let postData: any = {
  313. idx: this.pageIndex - 1,
  314. sum: this.pageSize,
  315. startTime: this.searchData.dateRange.start,
  316. endTime: this.searchData.dateRange.end,
  317. hosId: this.searchData.hosId,
  318. type: this.dateType,
  319. dataType: this.dataType || undefined,
  320. };
  321. if (field && sort) {
  322. postData.sort = sort === "ascend" ? field : `${field} desc`;
  323. }
  324. this.loading1 = true;
  325. this.mainService
  326. .postCustom("report/medicalWaste", "hospital", postData)
  327. .subscribe((result) => {
  328. this.message.remove(maskFlag);
  329. this.loading1 = false;
  330. this.heads = result.heads || [];
  331. this.listOfData = result.list || [];
  332. this.listLength = result.totalNum;
  333. this.pieChart = result.pieChart || [];
  334. this.pieChartHandler(this.pieChart);
  335. this.barChart = result.barChart || [];
  336. this.barChartHandler(this.barChart);
  337. });
  338. }
  339. // 获取院区
  340. hospital: string; //选中院区
  341. getAllHos() {
  342. this.hospital = this.tool.getCurrentHospital().id + "";
  343. }
  344. onCalendarChangeDate(dateArr){
  345. console.log(dateArr)
  346. if(dateArr.length == 2){
  347. let dateStart = new Date(dateArr[0]);
  348. let dateEnd = new Date(dateArr[1]);
  349. dateStart.setHours(0,0,0);
  350. dateEnd.setHours(23,59,59);
  351. this.dateRange = [dateStart,dateEnd];
  352. }
  353. }
  354. // 修改时间展示维度
  355. changeDateType(res) {
  356. console.log(res, this.dateType);
  357. this.dateType = res;
  358. this.searchData["type"] = res;
  359. console.log(this.searchData);
  360. switch (res) {
  361. case "day":
  362. this.defRanges = [
  363. {
  364. label: "上周",
  365. id: 1,
  366. },
  367. {
  368. label: "上月",
  369. id: 2,
  370. },
  371. {
  372. label: "上年",
  373. id: 3,
  374. },
  375. ]; //时间默认区间
  376. this.defRange = "1"; //默认上周
  377. this.changeDateRange("1");
  378. break;
  379. case "month":
  380. this.defRanges = [
  381. {
  382. label: "上月",
  383. id: 2,
  384. },
  385. {
  386. label: "上年",
  387. id: 3,
  388. },
  389. ]; //时间默认区间
  390. this.defRange = "2"; //上月
  391. this.changeDateRange("2");
  392. break;
  393. case "year":
  394. this.defRanges = [
  395. {
  396. label: "上年",
  397. id: 3,
  398. },
  399. ]; //时间默认区间
  400. this.defRange = "3"; //默认上周
  401. this.changeDateRange("3");
  402. break;
  403. }
  404. }
  405. // 禁选日期
  406. disabledDate = (current: Date): boolean => {
  407. // Can not select days before today and today
  408. return differenceInCalendarDays(current, this.today) > 0;
  409. };
  410. // 禁选月份开始
  411. disabledMonthStart = (current: Date): boolean => {
  412. // Can not select days before today and today
  413. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  414. let staEnd = differenceInCalendarDays(current, this.monthRangeEnd) > 0;
  415. return cur || staEnd;
  416. };
  417. // 禁选月份结束
  418. disabledMonthEnd = (current: Date): boolean => {
  419. // Can not select days before today and today
  420. let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
  421. let staEnd = differenceInCalendarDays(this.monthRangeStart, current) > 0;
  422. return cur || staEnd;
  423. };
  424. // 禁选年份开始
  425. disabledYearStart = (current: Date): boolean => {
  426. // Can not select days before today and today
  427. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  428. let staEnd = differenceInCalendarDays(current, this.yearRangeEnd) > 0;
  429. return cur || staEnd;
  430. };
  431. // 禁选年份结束
  432. disabledYearEnd = (current: Date): boolean => {
  433. // Can not select days before today and today
  434. let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
  435. let staEnd = differenceInCalendarDays(this.yearRangeStart, current) > 0;
  436. return cur || staEnd;
  437. };
  438. // 日期选择 日
  439. startDate: string; //发起时间开始
  440. endDate: string; //发起时间结束
  441. changeDate(result?): void {
  442. console.log(this.dateRange);
  443. console.log(result);
  444. this.dateRange = result;
  445. if (!this.quick) {
  446. // 不是快捷选择
  447. this.defRange = null;
  448. }
  449. if (!result || !result.length) {
  450. this.startDate = this.endDate = "";
  451. return;
  452. }
  453. this.startDate = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss');
  454. this.endDate = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss');
  455. }
  456. // 月份选择
  457. changeMonthStart(result?) {
  458. console.log(result);
  459. this.monthRangeStart = result;
  460. if (!this.quick) {
  461. // 不是快捷选择
  462. this.defRange = null;
  463. }
  464. if (!result) {
  465. this.startDate = this.endDate = "";
  466. return;
  467. }
  468. this.startDate = format(startOfMonth(result), 'yyyy-MM-dd HH:mm:ss');
  469. // this.endDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  470. }
  471. changeMonthEnd(result?) {
  472. console.log(result);
  473. this.monthRangeEnd = result;
  474. if (!this.quick) {
  475. // 不是快捷选择
  476. this.defRange = null;
  477. }
  478. if (!result) {
  479. this.startDate = this.endDate = "";
  480. return;
  481. }
  482. // this.startDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
  483. this.endDate = format(endOfMonth(result), 'yyyy-MM-dd HH:mm:ss');
  484. }
  485. // 年份选择
  486. changeYearStart(result?) {
  487. console.log(result);
  488. this.yearRangeStart = result;
  489. if (!this.quick) {
  490. // 不是快捷选择
  491. this.defRange = null;
  492. }
  493. if (!result) {
  494. this.startDate = this.endDate = "";
  495. return;
  496. }
  497. this.startDate = format(startOfYear(result), 'yyyy-MM-dd HH:mm:ss');
  498. // this.endDate = result.getFullYear() + '-01-01';
  499. }
  500. changeYearEnd(result?) {
  501. console.log(result);
  502. this.yearRangeEnd = result;
  503. if (!this.quick) {
  504. // 不是快捷选择
  505. this.defRange = null;
  506. }
  507. if (!result) {
  508. this.startDate = this.endDate = "";
  509. return;
  510. }
  511. this.endDate = format(endOfYear(result), 'yyyy-MM-dd HH:mm:ss');
  512. }
  513. // 日期选择 快速修改时间区间
  514. today = new Date();
  515. quick: boolean = false;
  516. changeDateRange(res) {
  517. console.log(res);
  518. this.quick = true;
  519. switch (res) {
  520. case "1":
  521. // 上周
  522. let lastweekstartdate = this.dateService.date().lastWeekStartDate;
  523. let lastweekenddate = this.dateService.date().lastWeekEndDate;
  524. console.log(lastweekstartdate, lastweekenddate);
  525. this.changeDate([lastweekstartdate, lastweekenddate]);
  526. break;
  527. case "2":
  528. // 上月
  529. let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
  530. let lastmonthenddate = this.dateService.date().lastMonthEndDate;
  531. console.log(lastmonthstartdate, lastmonthenddate);
  532. this.changeDate([lastmonthstartdate, lastmonthenddate]);
  533. this.changeMonthStart(lastmonthstartdate);
  534. this.changeMonthEnd(lastmonthenddate);
  535. break;
  536. case "3":
  537. // 上年
  538. let lastyearstartdate = this.dateService.date().lastYearStartDate;
  539. let lastyearenddate = this.dateService.date().lastYearEndDate;
  540. console.log(lastyearstartdate, lastyearenddate);
  541. this.changeDate([lastyearstartdate, lastyearenddate]);
  542. this.changeMonthStart(lastyearstartdate);
  543. this.changeMonthEnd(lastyearenddate);
  544. this.changeYearStart(lastyearstartdate);
  545. this.changeYearEnd(lastyearenddate);
  546. break;
  547. }
  548. this.quick = false;
  549. this.search();
  550. }
  551. // 更多
  552. toMore(type) {
  553. let sendData = this.searchData;
  554. console.log(sendData);
  555. this.myService.sendMsg(sendData);
  556. this.router.navigateByUrl("/main/" + type);
  557. }
  558. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  559. showPromptModal(con, success, promptInfo?) {
  560. this.promptModalShow = false;
  561. this.promptContent = con;
  562. this.ifSuccess = success;
  563. this.promptInfo = promptInfo;
  564. setTimeout(() => {
  565. this.promptModalShow = true;
  566. }, 100);
  567. }
  568. // 跳转详情
  569. toDetail(e, data){
  570. e.stopPropagation();
  571. console.log(data);
  572. window.open(`${location.origin}/spreadSheet/#/quiltWashingHospital/${data.date}/${this.dateType}`);
  573. }
  574. // 边输入边搜索节流阀
  575. isLoading: boolean = false;
  576. searchTimer(fun, e, those) {
  577. let that = this;
  578. that.isLoading = true;
  579. fun(e, those);
  580. }
  581. // 列表排序
  582. sortCurrent = {
  583. deptNum: null,
  584. clothesTypeNum: null,
  585. getOrder: null,
  586. sendOrder: null,
  587. sendClothesNum: null,
  588. price: null,
  589. };
  590. sortCurrentKey: string = "";
  591. sortCurrentValue: string | null = "";
  592. sort(e) {
  593. const { key, value } = e;
  594. this.sortCurrentKey = key;
  595. this.sortCurrentValue = value;
  596. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  597. }
  598. }