inspect-active.component.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { MainService } from "../../services/main.service";
  4. import { DateService } from "../../services/date.service";
  5. import { MyServiceService } from "../../services/my-service.service";
  6. import { ToolService } from "../../services/tool.service";
  7. import { Subject } from "rxjs";
  8. import { debounceTime } from "rxjs/operators";
  9. import { differenceInCalendarDays } from "date-fns";
  10. @Component({
  11. selector: "app-inspect-active",
  12. templateUrl: "./inspect-active.component.html",
  13. styleUrls: ["./inspect-active.component.less"],
  14. })
  15. export class InspectActiveComponent 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. this.getAllWorker(v);
  28. });
  29. this.getSearchData();
  30. this.coopBtns = this.tool.initCoopBtns(this.route);
  31. this.getAllHos();
  32. }
  33. defRange = "1"; //默认上周
  34. defRanges = [
  35. {
  36. label: "上周",
  37. id: 1,
  38. },
  39. {
  40. label: "上月",
  41. id: 2,
  42. },
  43. {
  44. label: "上年",
  45. id: 3,
  46. },
  47. ]; //时间默认区间
  48. listOfData: any[] = []; //表格数据
  49. pageIndex: number = 1; //表格当前页码
  50. pageSize: number = 10; //表格每页展示条数
  51. listLength: number = 10; //表格总数据量
  52. dateRange: any = []; //发起时间区间 天
  53. promptContent: string; //操作提示框提示信息
  54. ifSuccess: boolean; //操作成功/失败
  55. promptInfo: string; //操作结果提示信息
  56. promptModalShow: boolean; //操作提示框是否展示
  57. // 只能选择今天之前的日期
  58. disabledDate = (current: Date): boolean => {
  59. return differenceInCalendarDays(current, new Date()) > -1;
  60. };
  61. // 初始化增删改按钮
  62. coopBtns: any = {};
  63. searchData: any = {}; // 综合统计页面带过来的参数
  64. getSearchData() {
  65. let that = this;
  66. let sub = that.myService.getMsg().subscribe((msg) => {
  67. // 从综合报表跳转过来
  68. that.searchData = msg;
  69. console.log(that.searchData);
  70. console.log(66);
  71. sub.unsubscribe(); //取消订阅,否则订阅函数会累加执行
  72. that.hospital = that.searchData["hosId"];
  73. that.changeDate(that.searchData["range"]);
  74. that.defRange = that.searchData["defRange"];
  75. that.search();
  76. });
  77. // 不是从综合报表页面跳转过来的
  78. setTimeout(() => {
  79. if (!sub["isStopped"]) {
  80. that.changeDateRange(that.defRange);
  81. that.search();
  82. }
  83. }, 100);
  84. }
  85. // 搜索
  86. search(num?: number) {
  87. if (this.hospital) {
  88. this.searchData["hosId"] = this.hospital;
  89. }
  90. if (this.startDate) {
  91. this.searchData["dateRange"] = {
  92. start: this.startDate + " " + "00:00:00",
  93. end: this.endDate + " " + "23:59:59",
  94. };
  95. }
  96. if (num !== undefined) {
  97. this.getList(num);
  98. } else {
  99. this.getList();
  100. }
  101. }
  102. // 导出
  103. loading2 = false;
  104. export() {
  105. let postData: any = {
  106. type: "total",
  107. hosId: this.hospital,
  108. startTime: this.startDate + " " + "00:00:00",
  109. endTime: this.endDate + " " + "23:59:59",
  110. };
  111. if (this.dept !== 0) {
  112. postData.deptId = this.dept;
  113. }
  114. this.loading2 = true;
  115. this.mainService.exportReport("deptInspect", postData).subscribe(
  116. (data) => {
  117. this.loading2 = false;
  118. this.showPromptModal("导出", true, "");
  119. var file = new Blob([data], {
  120. type: "application/vnd.ms-excel",
  121. });
  122. //trick to download store a file having its URL
  123. var fileURL = URL.createObjectURL(file);
  124. var a = document.createElement("a");
  125. a.href = fileURL;
  126. a.target = "_blank";
  127. a.download = "人员检查主动服务统计.xls";
  128. document.body.appendChild(a);
  129. a.click();
  130. },
  131. (err) => {
  132. this.loading2 = false;
  133. this.showPromptModal("导出", false, "");
  134. }
  135. );
  136. }
  137. // 重置
  138. reset() {
  139. this.changeDateRange("1");
  140. this.dept = 0;
  141. this.search();
  142. }
  143. // 表格数据
  144. loading1 = false;
  145. getList(num?: number) {
  146. if (num !== undefined) {
  147. this.pageIndex = num;
  148. }
  149. let postData: any = {
  150. type: "total",
  151. idx: this.pageIndex - 1,
  152. sum: this.pageSize,
  153. startTime: this.searchData.dateRange.start,
  154. endTime: this.searchData.dateRange.end,
  155. hosId: this.searchData.hosId,
  156. };
  157. if (this.dept !== 0) {
  158. postData.deptId = this.dept;
  159. }
  160. this.loading1 = true;
  161. this.mainService
  162. .postReportCount("deptInspect", postData)
  163. .subscribe((result) => {
  164. this.loading1 = false;
  165. this.listOfData = result.list || [];
  166. this.listLength = result.totalNum;
  167. });
  168. }
  169. // 获取院区/分组
  170. hospital: string; //选中院区
  171. depts: any = []; //配送人员列表
  172. getAllHos() {
  173. this.hospital = this.tool.getCurrentHospital().id + "";
  174. this.getAllWorker();
  175. }
  176. // 用户输入搜索科室
  177. changeDept(e = "") {
  178. this.isLoading = true;
  179. this.searchTimerSubject.next(e);
  180. }
  181. // 获取护理单元科室列表
  182. dept: number = 0; //选中的科室
  183. isLoading = false;
  184. getAllWorker(e: any = "") {
  185. let postData = {
  186. department: {
  187. dept: e || "",
  188. hospital: { id: this.hospital },
  189. type: { id: "281" }, //护理单元
  190. },
  191. idx: 0,
  192. sum: 10,
  193. };
  194. this.isLoading = true;
  195. this.mainService
  196. .getFetchDataList("data", "department", postData)
  197. .subscribe((data) => {
  198. this.depts = data.list;
  199. this.isLoading = false;
  200. });
  201. }
  202. // 日期选择 日
  203. startDate: string; //发起时间开始
  204. endDate: string; //发起时间结束
  205. changeDate(result?): void {
  206. console.log(this.dateRange);
  207. console.log(result);
  208. this.dateRange = result;
  209. if (!this.quick) {
  210. // 不是快捷选择
  211. this.defRange = null;
  212. }
  213. if (!result || !result.length) {
  214. this.startDate = this.endDate = "";
  215. return;
  216. }
  217. this.startDate =
  218. result[0].getFullYear() +
  219. "-" +
  220. (result[0].getMonth() + 1) +
  221. "-" +
  222. result[0].getDate();
  223. this.endDate =
  224. result[1].getFullYear() +
  225. "-" +
  226. (result[1].getMonth() + 1) +
  227. "-" +
  228. result[1].getDate();
  229. this.search();
  230. }
  231. // 修改搜索条件科室
  232. searchDept(e) {
  233. this.dept = e;
  234. this.search();
  235. }
  236. // 日期选择 快速修改时间区间
  237. nowdate = new Date();
  238. quick: boolean = false;
  239. changeDateRange(res) {
  240. this.defRange = res;
  241. console.log(res);
  242. this.quick = true;
  243. switch (res) {
  244. case "1":
  245. // 上周
  246. let lastweekstartdate = this.dateService.date().lastWeekStartDate;
  247. let lastweekenddate = this.dateService.date().lastWeekEndDate;
  248. console.log(lastweekstartdate, lastweekenddate);
  249. this.changeDate([lastweekstartdate, lastweekenddate]);
  250. break;
  251. case "2":
  252. // 上月
  253. let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
  254. let lastmonthenddate = this.dateService.date().lastMonthEndDate;
  255. console.log(lastmonthstartdate, lastmonthenddate);
  256. this.changeDate([lastmonthstartdate, lastmonthenddate]);
  257. break;
  258. case "3":
  259. // 上年
  260. let lastyearstartdate = this.dateService.date().lastYearStartDate;
  261. let lastyearenddate = this.dateService.date().lastYearEndDate;
  262. console.log(lastyearstartdate, lastyearenddate);
  263. this.changeDate([lastyearstartdate, lastyearenddate]);
  264. break;
  265. }
  266. this.quick = false;
  267. }
  268. // 更多
  269. toMore(type) {
  270. let sendData = this.searchData;
  271. console.log(sendData);
  272. this.myService.sendMsg(sendData);
  273. this.router.navigateByUrl("/main/" + type);
  274. }
  275. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  276. showPromptModal(con, success, promptInfo?) {
  277. this.promptModalShow = false;
  278. this.promptContent = con;
  279. this.ifSuccess = success;
  280. this.promptInfo = promptInfo;
  281. setTimeout(() => {
  282. this.promptModalShow = true;
  283. }, 100);
  284. }
  285. // 边输入边搜索节流阀
  286. searchTimer(fun, e, those) {
  287. fun(e, those);
  288. }
  289. // 截取意见内容(ie内核截取)
  290. spliceContent(con) {
  291. if (con.length >= 41 && navigator.userAgent.indexOf("Trident") > -1) {
  292. return con.slice(0, 20) + "...";
  293. } else {
  294. return con;
  295. }
  296. }
  297. //获取配送人员工单详情列表
  298. personDetail(deptId) {
  299. let startDate = this.startDate + " " + "00:00:00";
  300. let endDate = this.endDate + " " + "23:59:59";
  301. this.router.navigateByUrl(
  302. `/main/inspectActive/inspectActiveDetail/${deptId}/${startDate}/${endDate}`
  303. );
  304. }
  305. }