123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523 |
- import { Component, OnInit } from "@angular/core";
- import { ActivatedRoute, Router } from "@angular/router";
- import { differenceInCalendarDays, endOfMonth, endOfYear, format, startOfMonth, startOfYear } 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 { Subject } from 'rxjs';
- import { debounceTime } from 'rxjs/operators';
- @Component({
- selector: "app-quilt-washing-personnel-statistics",
- templateUrl: "./quilt-washing-personnel-statistics.component.html",
- styleUrls: ["./quilt-washing-personnel-statistics.component.less"],
- })
- export class QuiltWashingPersonnelStatisticsComponent implements OnInit {
- constructor(
- private route: ActivatedRoute,
- private router: Router,
- private mainService: MainService,
- private dateService: DateService,
- private myService: MyServiceService,
- private tool: ToolService
- ) {}
- searchTimerSubject = new Subject();
- ngOnInit() {
- this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
- let fun = v[0];
- fun.call(this, v[1]);
- });
- this.coopBtns = this.tool.initCoopBtns(this.route);
- this.getAllHos();
- this.changeDateRange(this.defRange);
- // this.search();
- }
- 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,
- },
- ]; //时间默认区间
- 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; //操作提示框是否展示
- searchDto: any = {
- group: null,
- user: null,
- }
- // 初始化增删改按钮
- 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();
- }
- // 获取分组
- groupList: any = []; //分组
- getGroupList(id) {
- let groupData = {
- group2: {
- hospitals: id,
- type:1
- },
- idx: 0,
- sum: 9999,
- };
- this.mainService
- .getFetchDataList("data", "group2", groupData)
- .subscribe((result) => {
- this.groupList = result.list;
- });
- }
- // 边输边搜节流阀
- changeInp(e) {
- this.searchTimer(this.getUserList, e);
- }
- // 获取人员
- userList: any = []; //人员
- getUserList(keyword = '') {
- let postData = {
- user: {
- hospital: { id: this.hospital },
- name: keyword
- },
- idx: 0,
- sum: 10,
- };
- this.isLoading = true;
- this.mainService
- .getFetchDataList("data", "user", postData)
- .subscribe((result) => {
- this.isLoading = false;
- this.userList = result.list;
- });
- }
- // 搜索
- 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,
- userId: this.searchDto.user || undefined,
- groupId: this.searchDto.group || undefined,
- };
- if (this.sortCurrentKey && this.sortCurrentValue) {
- postData.sort =
- this.sortCurrentValue === "ascend"
- ? this.sortCurrentKey
- : `${this.sortCurrentKey} desc`;
- }
- this.loading2 = true;
- that.mainService.exportReport("clothesPersonal", 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.changeDateType("day");
- this.changeDateRange("1");
- this.sortCurrentKey = "";
- this.sortCurrentValue = "";
- this.sortCurrent = {
- totalTrip: null,
- totalOrder: null,
- getTrip: null,
- getOrder: null,
- sendTrip: null,
- sendOrder: null,
- };
- this.searchDto = {
- group: null,
- user: null,
- }
- this.search();
- }
- // 表格数据
- loading1 = false;
- getList(num?: number, field?: string, sort?: string) {
- 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,
- userId: this.searchDto.user || undefined,
- groupId: this.searchDto.group || undefined,
- };
- if (field && sort) {
- postData.sort = sort === "ascend" ? field : `${field} desc`;
- }
- this.loading1 = true;
- this.mainService
- .postCustom("report/clothes", "personal", postData)
- .subscribe((result) => {
- this.loading1 = false;
- this.listOfData = result.list || [];
- this.listLength = result.totalNum;
- });
- }
- // 获取院区
- hospital: string; //选中院区
- getAllHos() {
- this.hospital = this.tool.getCurrentHospital().id + "";
- this.getGroupList(this.hospital);
- this.getUserList();
- }
- 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(result[0], 'yyyy-MM-dd HH:mm:ss');
- this.endDate = format(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);
- }
- // 边输入边搜索节流阀
- isLoading: boolean = false;
- searchTimer(fun, e) {
- this.isLoading = true;
- this.searchTimerSubject.next([fun, e]);
- }
- // 列表排序
- sortCurrent = {
- totalTrip: null,
- totalOrder: null,
- getTrip: null,
- getOrder: null,
- sendTrip: null,
- sendOrder: 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);
- }
- }
|