123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- import { Component, OnInit } from "@angular/core";
- import { ActivatedRoute, Router } from "@angular/router";
- import { differenceInCalendarDays, endOfMonth, endOfYear, format, startOfMonth, startOfYear, startOfDay, endOfDay } from "date-fns";
- import { MainService } from "../../services/main.service";
- import { DateService } from "../../services/date.service";
- import { MyServiceService } from "../../services/my-service.service";
- import { ToolService } from "../../services/tool.service";
- import { NzMessageService } from 'ng-zorro-antd';
- @Component({
- selector: "app-medical-waste-hospital-statistics",
- templateUrl: "./medical-waste-hospital-statistics.component.html",
- styleUrls: ["./medical-waste-hospital-statistics.component.less"],
- })
- export class MedicalWasteHospitalStatisticsComponent implements OnInit {
- constructor(
- private route: ActivatedRoute,
- private router: Router,
- private mainService: MainService,
- private dateService: DateService,
- private myService: MyServiceService,
- private message: NzMessageService,
- private tool: ToolService
- ) {}
- ngOnInit() {
- this.coopBtns = this.tool.initCoopBtns(this.route);
- this.getAllHos();
- this.changeDateRange(this.defRange);
- // this.search();
- }
- dataType:string = 'outbound';
- checkOptionsOne: Array<any> = [
- { label: "回收重量", value: "recovery", checked: true },
- { label: "出库总重量", value: "outbound", checked: false },
- ];
- dateType: string = "day"; //选中时间维度
- dateTypes: any = [
- {
- label: "按天统计",
- value: "day",
- },
- {
- label: "按月统计",
- value: "month",
- },
- {
- label: "按年统计",
- value: "year",
- },
- ]; //时间维度
- defRange = "1"; //默认上周
- defRanges = [
- {
- label: "上周",
- id: 1,
- },
- {
- label: "上月",
- id: 2,
- },
- {
- label: "上年",
- id: 3,
- },
- ]; //时间默认区间
- heads: any[] = []; //表头数据
- listOfData: any[] = []; //表格数据
- pageIndex: number = 1; //表格当前页码
- pageSize: number = 10; //表格每页展示条数
- listLength: number = 10; //表格总数据量
- alldepart: any = []; //当前院区所属科室
- dateRange: any = []; //发起时间区间 天
- monthRangeStart: any; //发起时间 月 起
- monthRangeEnd: any; //发起时间 月 止
- yearRangeStart: any; //发起时间 年 起
- yearRangeEnd: any; //发起时间 年 止
- promptContent: string; //操作提示框提示信息
- ifSuccess: boolean; //操作成功/失败
- promptInfo: string; //操作结果提示信息
- promptModalShow: boolean; //操作提示框是否展示
- // 初始化增删改按钮
- coopBtns: any = {};
- searchData: any = {}; // 综合统计页面带过来的参数
- getSearchData() {
- let that = this;
- let sub = that.myService.getMsg().subscribe((msg) => {
- // 从综合报表跳转过来
- that.searchData = msg;
- console.log(that.searchData);
- console.log(66);
- sub.unsubscribe(); //取消订阅,否则订阅函数会累加执行
- that.hospital = that.searchData["hosId"];
- that.changeDate(that.searchData["range"]);
- that.defRange = that.searchData["defRange"];
- that.search();
- });
- that.changeDateRange(that.defRange);
- that.search();
- }
- // 搜索
- search(num?: number) {
- if (this.hospital) {
- this.searchData["hosId"] = this.hospital;
- }
- if (this.startDate) {
- this.searchData["dateRange"] = {
- start: this.startDate,
- end: this.endDate,
- };
- }
- if (num !== undefined) {
- this.getList(num, this.sortCurrentKey, this.sortCurrentValue);
- } else {
- this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
- }
- }
- // 导出
- loading2 = false;
- export() {
- let that = this;
- let postData: any = {
- startTime: this.startDate,
- endTime: this.endDate,
- hosId: that.hospital,
- type: this.dateType,
- dataType: this.dataType || undefined,
- };
- if (this.sortCurrentKey && this.sortCurrentValue) {
- postData.sort =
- this.sortCurrentValue === "ascend"
- ? this.sortCurrentKey
- : `${this.sortCurrentKey} desc`;
- }
- this.loading2 = true;
- that.mainService.exportReport("medicalWasteHospital", postData).subscribe(
- (data) => {
- this.loading2 = false;
- this.showPromptModal("导出", true, "");
- var file = new Blob([data], {
- type: "application/vnd.ms-excel",
- });
- //trick to download store a file having its URL
- var fileURL = URL.createObjectURL(file);
- var a = document.createElement("a");
- a.href = fileURL;
- a.target = "_blank";
- a.download = "全院统计.xls";
- document.body.appendChild(a);
- a.click();
- },
- (err) => {
- this.loading2 = false;
- this.showPromptModal("导出", false, "");
- }
- );
- }
- // 重置
- reset() {
- this.dataType = 'outbound';
- this.sortCurrentKey = "";
- this.sortCurrentValue = "";
- this.sortCurrent = {
- deptNum: null,
- clothesTypeNum: null,
- getOrder: null,
- sendOrder: null,
- sendClothesNum: null,
- price: null,
- };
- this.changeDateType("day");
- }
- // 医废类型-图表
- pieChartOption;
- pieChartHandler(datas) {
- console.log(datas)
- let labels = [];
- let nums = [];
- if (datas.length) {
- datas.forEach((e) => {
- labels.push(e[0]);
- nums.push({
- name: e[0],
- value: e[1],
- label: {
- position: e[1] >= 0 ? 'bottom' : 'top',
- }
- });
- });
- }
- this.pieChartOption = {
- color: ["#6c63f0", "#b750be", "#3aacff", "#ed589d", "#fb466c", "#00d6f6"],
- tooltip: {
- trigger: "item",
- axisPointer: {
- // 坐标轴指示器,坐标轴触发有效
- type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
- },
- formatter: '{b}: {c}kg'
- },
- legend: {
- orient: 'vertical',
- right: 20,
- top: 'center'
- },
- grid: {
- left: "9px",
- right: "9px",
- bottom: "20px",
- top: "20px",
- containLabel: true,
- },
- series: [
- {
- type: 'pie',
- radius: '50%',
- data: nums,
- emphasis: {
- itemStyle: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- },
- label: {
- show: true,
- formatter: "{b} {d}%"
- },
- },
- ],
- };
- }
- // 回收及出库重量-图表
- barChartOption;
- barChartHandler(datas) {
- console.log(datas)
- let labels = [];
- let nums = [];
- if (datas.length) {
- datas.forEach((e) => {
- labels.push(e[0]);
- nums.push({
- name: e[0],
- value: e[1],
- label: {
- position: 'top',
- },
- itemStyle: {
- color: e[0] === '回收' ? '#3588fa' : '#00d6f6'
- }
- });
- });
- }
- this.barChartOption = {
- tooltip: {
- trigger: "axis",
- axisPointer: {
- // 坐标轴指示器,坐标轴触发有效
- type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
- },
- formatter: '{b}: {c}kg'
- },
- grid: {
- left: "9px",
- right: "9px",
- bottom: "20px",
- top: "20px",
- containLabel: true,
- },
- xAxis: [
- {
- type: "category",
- data: labels,
- axisTick: {
- alignWithLabel: true,
- },
- },
- ],
- yAxis: [
- {
- type: "value",
- axisLabel: {
- formatter: "{value}kg",
- },
- nameTextStyle: {
- align: "left",
- },
- },
- ],
- series: [
- {
- name: "",
- type: "bar",
- barWidth: "35",
- data: nums,
- label: {
- show: true,
- color: '#000',
- formatter: '{c}kg'
- },
- },
- ],
- };
- }
- // 表格数据
- loading1 = false;
- pieChart: any = [];
- barChart: any = [];
- getList(num?: number, field?: string, sort?: string) {
- let maskFlag = this.message.loading("正在加载中..", {
- nzDuration: 0,
- }).messageId;
- this.pageIndex = num;
- let postData: any = {
- idx: this.pageIndex - 1,
- sum: this.pageSize,
- startTime: this.searchData.dateRange.start,
- endTime: this.searchData.dateRange.end,
- hosId: this.searchData.hosId,
- type: this.dateType,
- dataType: this.dataType || undefined,
- };
- if (field && sort) {
- postData.sort = sort === "ascend" ? field : `${field} desc`;
- }
- this.loading1 = true;
- this.mainService
- .postCustom("report/medicalWaste", "hospital", postData)
- .subscribe((result) => {
- this.message.remove(maskFlag);
- this.loading1 = false;
- this.heads = result.heads || [];
- this.listOfData = result.list || [];
- this.listLength = result.totalNum;
- this.pieChart = result.pieChart || [];
- this.pieChartHandler(this.pieChart);
- this.barChart = result.barChart || [];
- this.barChartHandler(this.barChart);
- });
- }
- // 获取院区
- hospital: string; //选中院区
- getAllHos() {
- this.hospital = this.tool.getCurrentHospital().id + "";
- }
- onCalendarChangeDate(dateArr){
- console.log(dateArr)
- if(dateArr.length == 2){
- let dateStart = new Date(dateArr[0]);
- let dateEnd = new Date(dateArr[1]);
- dateStart.setHours(0,0,0);
- dateEnd.setHours(23,59,59);
- this.dateRange = [dateStart,dateEnd];
- }
- }
- // 修改时间展示维度
- changeDateType(res) {
- console.log(res, this.dateType);
- this.dateType = res;
- this.searchData["type"] = res;
- console.log(this.searchData);
- switch (res) {
- case "day":
- this.defRanges = [
- {
- label: "上周",
- id: 1,
- },
- {
- label: "上月",
- id: 2,
- },
- {
- label: "上年",
- id: 3,
- },
- ]; //时间默认区间
- this.defRange = "1"; //默认上周
- this.changeDateRange("1");
- break;
- case "month":
- this.defRanges = [
- {
- label: "上月",
- id: 2,
- },
- {
- label: "上年",
- id: 3,
- },
- ]; //时间默认区间
- this.defRange = "2"; //上月
- this.changeDateRange("2");
- break;
- case "year":
- this.defRanges = [
- {
- label: "上年",
- id: 3,
- },
- ]; //时间默认区间
- this.defRange = "3"; //默认上周
- this.changeDateRange("3");
- break;
- }
- }
- // 禁选日期
- disabledDate = (current: Date): boolean => {
- // Can not select days before today and today
- return differenceInCalendarDays(current, this.today) > 0;
- };
- // 禁选月份开始
- disabledMonthStart = (current: Date): boolean => {
- // Can not select days before today and today
- let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
- let staEnd = differenceInCalendarDays(current, this.monthRangeEnd) > 0;
- return cur || staEnd;
- };
- // 禁选月份结束
- disabledMonthEnd = (current: Date): boolean => {
- // Can not select days before today and today
- let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
- let staEnd = differenceInCalendarDays(this.monthRangeStart, current) > 0;
- return cur || staEnd;
- };
- // 禁选年份开始
- disabledYearStart = (current: Date): boolean => {
- // Can not select days before today and today
- let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
- let staEnd = differenceInCalendarDays(current, this.yearRangeEnd) > 0;
- return cur || staEnd;
- };
- // 禁选年份结束
- disabledYearEnd = (current: Date): boolean => {
- // Can not select days before today and today
- let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
- let staEnd = differenceInCalendarDays(this.yearRangeStart, current) > 0;
- return cur || staEnd;
- };
- // 日期选择 日
- startDate: string; //发起时间开始
- endDate: string; //发起时间结束
- changeDate(result?): void {
- console.log(this.dateRange);
- console.log(result);
- this.dateRange = result;
- if (!this.quick) {
- // 不是快捷选择
- this.defRange = null;
- }
- if (!result || !result.length) {
- this.startDate = this.endDate = "";
- return;
- }
- this.startDate = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss');
- this.endDate = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss');
- }
- // 月份选择
- changeMonthStart(result?) {
- console.log(result);
- this.monthRangeStart = result;
- if (!this.quick) {
- // 不是快捷选择
- this.defRange = null;
- }
- if (!result) {
- this.startDate = this.endDate = "";
- return;
- }
- this.startDate = format(startOfMonth(result), 'yyyy-MM-dd HH:mm:ss');
- // this.endDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
- }
- changeMonthEnd(result?) {
- console.log(result);
- this.monthRangeEnd = result;
- if (!this.quick) {
- // 不是快捷选择
- this.defRange = null;
- }
- if (!result) {
- this.startDate = this.endDate = "";
- return;
- }
- // this.startDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
- this.endDate = format(endOfMonth(result), 'yyyy-MM-dd HH:mm:ss');
- }
- // 年份选择
- changeYearStart(result?) {
- console.log(result);
- this.yearRangeStart = result;
- if (!this.quick) {
- // 不是快捷选择
- this.defRange = null;
- }
- if (!result) {
- this.startDate = this.endDate = "";
- return;
- }
- this.startDate = format(startOfYear(result), 'yyyy-MM-dd HH:mm:ss');
- // this.endDate = result.getFullYear() + '-01-01';
- }
- changeYearEnd(result?) {
- console.log(result);
- this.yearRangeEnd = result;
- if (!this.quick) {
- // 不是快捷选择
- this.defRange = null;
- }
- if (!result) {
- this.startDate = this.endDate = "";
- return;
- }
- this.endDate = format(endOfYear(result), 'yyyy-MM-dd HH:mm:ss');
- }
- // 日期选择 快速修改时间区间
- today = new Date();
- quick: boolean = false;
- changeDateRange(res) {
- console.log(res);
- this.quick = true;
- switch (res) {
- case "1":
- // 上周
- let lastweekstartdate = this.dateService.date().lastWeekStartDate;
- let lastweekenddate = this.dateService.date().lastWeekEndDate;
- console.log(lastweekstartdate, lastweekenddate);
- this.changeDate([lastweekstartdate, lastweekenddate]);
- break;
- case "2":
- // 上月
- let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
- let lastmonthenddate = this.dateService.date().lastMonthEndDate;
- console.log(lastmonthstartdate, lastmonthenddate);
- this.changeDate([lastmonthstartdate, lastmonthenddate]);
- this.changeMonthStart(lastmonthstartdate);
- this.changeMonthEnd(lastmonthenddate);
- break;
- case "3":
- // 上年
- let lastyearstartdate = this.dateService.date().lastYearStartDate;
- let lastyearenddate = this.dateService.date().lastYearEndDate;
- console.log(lastyearstartdate, lastyearenddate);
- this.changeDate([lastyearstartdate, lastyearenddate]);
- this.changeMonthStart(lastyearstartdate);
- this.changeMonthEnd(lastyearenddate);
- this.changeYearStart(lastyearstartdate);
- this.changeYearEnd(lastyearenddate);
- break;
- }
- this.quick = false;
- this.search();
- }
- // 更多
- toMore(type) {
- let sendData = this.searchData;
- console.log(sendData);
- this.myService.sendMsg(sendData);
- this.router.navigateByUrl("/main/" + type);
- }
- // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
- showPromptModal(con, success, promptInfo?) {
- this.promptModalShow = false;
- this.promptContent = con;
- this.ifSuccess = success;
- this.promptInfo = promptInfo;
- setTimeout(() => {
- this.promptModalShow = true;
- }, 100);
- }
- // 跳转详情
- toDetail(e, data){
- e.stopPropagation();
- console.log(data);
- window.open(`${location.origin}/spreadSheet/#/quiltWashingHospital/${data.date}/${this.dateType}`);
- }
- // 边输入边搜索节流阀
- isLoading: boolean = false;
- searchTimer(fun, e, those) {
- let that = this;
- that.isLoading = true;
- fun(e, those);
- }
- // 列表排序
- sortCurrent = {
- deptNum: null,
- clothesTypeNum: null,
- getOrder: null,
- sendOrder: null,
- sendClothesNum: null,
- price: null,
- };
- sortCurrentKey: string = "";
- sortCurrentValue: string | null = "";
- sort(e) {
- const { key, value } = e;
- this.sortCurrentKey = key;
- this.sortCurrentValue = value;
- this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
- }
- }
|