order-management.component.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { MainService } from "../../services/main.service";
  4. import { ToolService } from "../../services/tool.service";
  5. import { Subject } from "rxjs";
  6. import { debounceTime } from "rxjs/operators";
  7. @Component({
  8. selector: "app-order-management",
  9. templateUrl: "./order-management.component.html",
  10. styleUrls: ["./order-management.component.less"],
  11. })
  12. export class OrderManagementComponent implements OnInit {
  13. constructor(
  14. public route: ActivatedRoute,
  15. private router: Router,
  16. private mainService: MainService,
  17. private tool: ToolService
  18. ) {}
  19. searchTimerSubject = new Subject();
  20. ngOnInit() {
  21. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  22. let fun = v[0];
  23. fun.call(this, v[1]);
  24. });
  25. this.initOrderType();
  26. this.coopBtns = this.tool.initCoopBtns(this.route);
  27. if (this.coopBtns.deleted) {
  28. //是否显示已删除
  29. this.checkOptionsOne.push({
  30. label: "已删除",
  31. value: "3",
  32. checked: false,
  33. });
  34. }
  35. this.getAllHos();
  36. this.getGdStates();
  37. }
  38. loginUser: any = localStorage.getItem("user")
  39. ? JSON.parse(localStorage.getItem("user")).user
  40. : null; //登录人信息
  41. listOfData: any[] = []; //表格数据
  42. modal: boolean = false; //回复模态框
  43. coopId: string; //表格中执行操作的id
  44. hospital: string; //选中院区
  45. gdcode: string = ""; //工单单号
  46. association: number; //工单类型
  47. allAssociation: any = []; //当前院区所有工单类型
  48. department: any; //所属科室
  49. alldepart: any = []; //当前院区所属科室
  50. worker: number; //选择执行支助人员
  51. tasktype: number; //选择任务类型
  52. allWorker: any = []; //当前院区执行支助人员列表
  53. allTasktype: any = []; //当前院区任务类型列表
  54. gdState: number; //选择工单状态
  55. specialCloseFlag: any; //特殊情况关闭
  56. dateRange: any = []; //发起时间
  57. gdStates: any; //工单状态列表
  58. pageIndex: number = 1; //页码
  59. listLength: number = 10; //总条数
  60. pageSize: number = 10; //每页条数
  61. promptContent: string; //操作提示框提示信息
  62. ifSuccess: boolean; //操作成功/失败
  63. promptInfo: string; //操作结果提示信息
  64. promptModalShow: boolean; //操作提示框是否展示
  65. btnLoading: boolean = false; //提交按钮loading状态
  66. checkOptionsOne: Array<any> = [
  67. { label: "超时工单", value: "0", checked: false },
  68. { label: "异常工单", value: "1", checked: false },
  69. { label: "24小时未完成", value: "2", checked: false },
  70. ]; //工单异常状态
  71. // 初始化工单异常状态选中状态
  72. initOrderType() {
  73. let that = this;
  74. console.log(that.route);
  75. if (that.route.snapshot.fragment == "yc") {
  76. that.checkOptionsOne[1].checked = true;
  77. }
  78. }
  79. // 初始化增删改按钮
  80. coopBtns: any = {};
  81. // 搜索
  82. search() {
  83. this.pageIndex = 1;
  84. this.getList();
  85. }
  86. // 重置
  87. reset() {
  88. this.pageIndex = 1;
  89. this.association = null;
  90. this.worker = null;
  91. this.tasktype = null;
  92. if (this.loginUser.usertype.value != 1) {
  93. // 人员类型不是护士
  94. this.department = null;
  95. }
  96. this.gdcode = "";
  97. this.gdState = null;
  98. this.specialCloseFlag = null;
  99. this.dateRange = [];
  100. this.changeDate();
  101. this.getList();
  102. }
  103. // 获取院区
  104. getAllHos() {
  105. this.hospital = this.tool.getCurrentHospital().id + "";
  106. this.changeHos();
  107. }
  108. // 修改院区获取对应科室,工单类型,执行支助人员
  109. changeHos() {
  110. this.department = null;
  111. this.worker = null;
  112. this.tasktype = null;
  113. this.association = null;
  114. this.getDeparts();
  115. this.getAssociation();
  116. this.getAllWorker();
  117. this.getAllTasktype();
  118. }
  119. // 获取关联类型
  120. getAssociation() {
  121. let that = this;
  122. console.log(that.mainService.getDictionary("list", "association_types"));
  123. that.mainService
  124. .getDictionary("list", "association_types")
  125. .subscribe((data) => {
  126. that.allAssociation = data;
  127. });
  128. }
  129. // 获取支助人员
  130. getAllWorker(e?, those?) {
  131. let that = those || this;
  132. let postData = {
  133. user: {
  134. name: e || "",
  135. hospital: { id: that.hospital },
  136. usertype: { id: 106 }, //支助人员
  137. },
  138. idx: 0,
  139. sum: 20,
  140. };
  141. that.isLoading = true;
  142. that.mainService
  143. .getFetchDataList("data", "user", postData)
  144. .subscribe((data) => {
  145. that.allWorker = data.list;
  146. that.isLoading = false;
  147. });
  148. }
  149. // 获取任务类型
  150. getAllTasktype(e?, those?) {
  151. let that = those || this;
  152. let postData: any = {
  153. idx: 0,
  154. sum: 10,
  155. taskType: {
  156. taskName: e || "",
  157. hosIds: that.hospital,
  158. simpleQuery: true,
  159. },
  160. };
  161. if (that.association) {
  162. postData.taskType.associationType = { id: that.association };
  163. }
  164. that.isLoading = true;
  165. that.mainService
  166. .getFetchDataList("configuration", "taskType", postData)
  167. .subscribe((data) => {
  168. that.allTasktype = data.list;
  169. that.isLoading = false;
  170. });
  171. }
  172. // 选择工单类型
  173. selectAssociation(e) {
  174. this.association = e;
  175. this.changeTasktype("");
  176. this.tasktype = null;
  177. }
  178. // 表格数据
  179. loading1 = false;
  180. getList() {
  181. var that = this;
  182. let data: any = {
  183. idx: that.pageIndex - 1,
  184. sum: that.pageSize,
  185. workOrder: {
  186. worker: { id: that.worker },
  187. gdState: { id: that.gdState },
  188. gdcode: this.gdcode,
  189. specialCloseFlag: that.specialCloseFlag,
  190. createDept: that.department,
  191. hosId: that.hospital,
  192. abnormityType: that.checkOptionsOne[1].checked ? 1 : 0,
  193. timeOut: that.checkOptionsOne[0].checked ? 1 : 0,
  194. },
  195. };
  196. if (that.checkOptionsOne[3]) {
  197. if (that.checkOptionsOne[3].checked) {
  198. data.workOrder.deleteFlag = 1;
  199. } else {
  200. delete data.workOrder.deleteFlag;
  201. }
  202. }
  203. if (that.association) {
  204. data.workOrder.taskType = {
  205. associationType: { id: that.association },
  206. };
  207. }
  208. if (that.tasktype) {
  209. data.workOrder.serTaskTypes = that.tasktype;
  210. }
  211. if (!data.workOrder.worker.id) {
  212. delete data.workOrder.worker;
  213. }
  214. if (!data.workOrder.gdState.id) {
  215. delete data.workOrder.gdState;
  216. }
  217. if (
  218. data.workOrder.specialCloseFlag === undefined ||
  219. data.workOrder.specialCloseFlag === null
  220. ) {
  221. delete data.workOrder.specialCloseFlag;
  222. }
  223. if (!data.workOrder.createDept) {
  224. delete data.workOrder.createDept;
  225. }
  226. delete data.workOrder.overdueTime24;
  227. delete data.workOrder.startTime1;
  228. delete data.workOrder.endTime1;
  229. if (that.checkOptionsOne[2].checked) {
  230. data.workOrder.overdueTime24 = true;
  231. } else if (that.startDate && that.endDate) {
  232. data.workOrder.startTime1 = that.startDate;
  233. data.workOrder.endTime1 = that.endDate;
  234. }
  235. that.mapOfCheckedId = {};
  236. that.checkedDepIds = [];
  237. that.isAllDisplayDataChecked = false;
  238. that.loading1 = true;
  239. that.mainService
  240. .getFetchDataList("data", "workOrder", data)
  241. .subscribe((result) => {
  242. that.loading1 = false;
  243. that.listOfData = result.list;
  244. that.listLength = result.totalNum;
  245. });
  246. }
  247. // 获取所有科室
  248. getDeparts(dept?) {
  249. let data = {
  250. department: {
  251. hospital: { id: this.hospital },
  252. dept: dept,
  253. },
  254. idx: 0,
  255. sum: 20,
  256. };
  257. this.isLoading = true;
  258. this.mainService
  259. .getFetchDataList("data", "department", data)
  260. .subscribe((data) => {
  261. this.alldepart = data.list;
  262. this.isLoading = false;
  263. if (dept === undefined && this.loginUser.usertype.value == 1) {
  264. // 初次渲染,人员类型是护士,则回显申请科室,并禁用
  265. this.alldepart = [this.loginUser.dept];
  266. this.department = this.loginUser.dept.id;
  267. this.getList();
  268. }else{
  269. this.getList();
  270. }
  271. });
  272. }
  273. // 获取工单状态
  274. getGdStates() {
  275. var that = this;
  276. that.mainService.getDictionary("list", "gdstate").subscribe((data) => {
  277. that.gdStates = data;
  278. });
  279. }
  280. // 表格筛选
  281. log(value: object[]): void {
  282. console.log(value);
  283. this.getList();
  284. }
  285. // 日期选择
  286. startDate: string; //发起时间开始
  287. endDate: string; //发起时间结束
  288. changeDate(result?): void {
  289. if (!result) {
  290. this.startDate = this.endDate = "";
  291. return;
  292. }
  293. this.startDate =
  294. result[0].getFullYear() +
  295. "-" +
  296. (result[0].getMonth() + 1) +
  297. "-" +
  298. result[0].getDate() +
  299. " " +
  300. "00:00:00";
  301. this.endDate =
  302. result[1].getFullYear() +
  303. "-" +
  304. (result[1].getMonth() + 1) +
  305. "-" +
  306. result[1].getDate() +
  307. " " +
  308. "23:59:59";
  309. }
  310. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  311. showPromptModal(con, success, promptInfo?) {
  312. this.promptModalShow = false;
  313. this.promptContent = con;
  314. this.ifSuccess = success;
  315. this.promptInfo = promptInfo;
  316. setTimeout(() => {
  317. this.promptModalShow = true;
  318. }, 100);
  319. this.getList();
  320. }
  321. // 查看
  322. detail(e, id) {
  323. e.stopPropagation();
  324. this.router.navigateByUrl("/main/orderManagement/orderDetail/" + id);
  325. }
  326. // 批量删除
  327. showDelModals(e) {
  328. let ids = this.checkedDepIds.join(",");
  329. this.showDelModal(e, ids);
  330. }
  331. //删除
  332. loading3 = false;
  333. delModal: boolean = false; //删除模态框
  334. showDelModal(e, id) {
  335. e.stopPropagation();
  336. this.delModal = true;
  337. this.coopId = id + "";
  338. }
  339. hideDelModal() {
  340. this.delModal = false;
  341. }
  342. confirmDel() {
  343. this.loading3 = true;
  344. this.mainService[this.coopId.includes(",") ? "delOrders" : "delOrder"](
  345. this.coopId
  346. ).subscribe((data) => {
  347. this.loading3 = false;
  348. this.delModal = false;
  349. if (data.status == 200) {
  350. if (
  351. this.listOfData.length == 1 &&
  352. this.pageIndex == Math.ceil(this.listLength / this.pageSize)
  353. ) {
  354. this.listLength--;
  355. this.pageIndex = Math.ceil(this.listLength / this.pageSize);
  356. }
  357. this.showPromptModal("删除", true, "");
  358. } else {
  359. this.showPromptModal("删除", false, data.msg);
  360. }
  361. });
  362. }
  363. // 导出
  364. loading2 = false;
  365. export() {
  366. let that = this;
  367. let postData: any = {
  368. idx: that.pageIndex - 1,
  369. sum: that.pageSize,
  370. workOrder: {
  371. worker: { id: that.worker },
  372. gdState: { id: that.gdState },
  373. createDept: that.department,
  374. hosId: that.hospital,
  375. abnormityType: that.checkOptionsOne[1].checked ? 1 : 0,
  376. timeOut: that.checkOptionsOne[0].checked ? 1 : 0,
  377. },
  378. };
  379. if (that.association) {
  380. postData.workOrder.taskType = {
  381. associationType: { id: that.association },
  382. };
  383. }
  384. if (that.tasktype) {
  385. postData.workOrder.serTaskTypes = that.tasktype;
  386. }
  387. if (!postData.workOrder.worker.id) {
  388. delete postData.workOrder.worker;
  389. }
  390. if (!postData.workOrder.gdState.id) {
  391. delete postData.workOrder.gdState;
  392. }
  393. if (!postData.workOrder.createDept) {
  394. delete postData.workOrder.createDept;
  395. }
  396. delete postData.workOrder.overdueTime24;
  397. delete postData.workOrder.startTime1;
  398. delete postData.workOrder.endTime1;
  399. if (that.checkOptionsOne[2].checked) {
  400. postData.workOrder.overdueTime24 = true;
  401. } else if (that.startDate && that.endDate) {
  402. postData.workOrder.startTime1 = that.startDate;
  403. postData.workOrder.endTime1 = that.endDate;
  404. }
  405. this.loading2 = true;
  406. that.mainService.dataExport("workOrder", postData).subscribe(
  407. (data) => {
  408. this.loading2 = false;
  409. this.showPromptModal("导出", true, "");
  410. var file = new Blob([data], {
  411. type: "application/vnd.ms-excel",
  412. });
  413. //trick to download store a file having its URL
  414. var fileURL = URL.createObjectURL(file);
  415. var a = document.createElement("a");
  416. a.href = fileURL;
  417. a.target = "_blank";
  418. a.download = "工单列表.xls";
  419. document.body.appendChild(a);
  420. a.click();
  421. },
  422. (err) => {
  423. this.loading2 = false;
  424. this.showPromptModal("导出", false, "");
  425. }
  426. );
  427. }
  428. // 申请科室边输边搜节流阀
  429. isLoading = false;
  430. changeInp(e) {
  431. this.searchTimer(this.getDeparts, e);
  432. }
  433. // 用户输入搜索支助人员
  434. changeUser(e) {
  435. this.searchTimer(this.getAllWorker, e);
  436. }
  437. // 用户输入搜索任务类型
  438. changeTasktype(e) {
  439. this.searchTimer(this.getAllTasktype, e);
  440. }
  441. // 边输入边搜索节流阀
  442. searchTimer(fun, e) {
  443. this.isLoading = true;
  444. this.searchTimerSubject.next([fun, e]);
  445. }
  446. // 截取意见内容(ie内核截取)
  447. spliceContent(con) {
  448. if (con.length >= 41 && navigator.userAgent.indexOf("Trident") > -1) {
  449. return con.slice(0, 20) + "...";
  450. } else {
  451. return con;
  452. }
  453. }
  454. // 选中表格单列
  455. mapOfCheckedId: { [key: string]: boolean } = {};
  456. checkedDepIds = []; //已选中单列id
  457. refreshStatus(): void {
  458. let listOfData = this.listOfData.filter(
  459. (item) => item.gdState.value != 6 && item.gdState.value != 7
  460. );
  461. this.isAllDisplayDataChecked = listOfData.every(
  462. (item) => this.mapOfCheckedId[item.id]
  463. );
  464. let arr = [];
  465. for (var k in this.mapOfCheckedId) {
  466. if (this.mapOfCheckedId[k]) {
  467. arr.push(Number(k));
  468. }
  469. }
  470. this.checkedDepIds = arr;
  471. }
  472. // 整行操作
  473. selectedListData(data) {
  474. if (data.gdState.value == 6 || data.gdState.value == 7) {
  475. return;
  476. }
  477. this.mapOfCheckedId[data.id] = !this.mapOfCheckedId[data.id];
  478. this.refreshStatus();
  479. }
  480. // 全选
  481. isAllDisplayDataChecked = false; //当前页是否全选
  482. checkAll(value: boolean): void {
  483. this.listOfData.forEach((item) => {
  484. if (item.gdState.value != 6 && item.gdState.value != 7) {
  485. this.mapOfCheckedId[item.id] = value;
  486. }
  487. });
  488. this.refreshStatus();
  489. }
  490. }