incident-handle-order.component.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ViewEncapsulation } from '@angular/core';
  2. import { MainService } from '../../../services/main.service';
  3. import { Router } from '@angular/router';
  4. import { NzMessageService } from 'ng-zorro-antd';
  5. import { FormGroup, Validators, FormBuilder } from '@angular/forms';
  6. import { ToolService } from 'src/app/services/tool.service';
  7. import { Subject } from 'rxjs';
  8. import { debounceTime } from 'rxjs/operators';
  9. @Component({
  10. selector: 'app-incident-handle-order',
  11. templateUrl: './incident-handle-order.component.html',
  12. styleUrls: ['./incident-handle-order.component.less'],
  13. })
  14. export class IncidentHandleOrderComponent implements OnInit {
  15. @Input() id: any;
  16. constructor(
  17. private mainService: MainService,
  18. private router: Router,
  19. private message: NzMessageService,
  20. private tool: ToolService,
  21. private fb: FormBuilder,
  22. ) { }
  23. hosId:any;
  24. changeInpSubject = new Subject(); //防抖
  25. ngOnInit() {
  26. //防抖
  27. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  28. if(v[0] === 'consumable'){
  29. this.getConsumableList(v[1]);
  30. }
  31. });
  32. this.hosId = this.tool.getCurrentHospital().id;
  33. this.getSummaryList();
  34. this.getHospitalConfig();
  35. this.getWorkHourManagementList();
  36. }
  37. // 工时日志列表
  38. listLogOfData: any[] = []; //日志数据
  39. pageLogIndex: number = 1; //日志当前页码
  40. pageLogSize: number = 10; //日志每页展示条数
  41. listLogLength: number = 10; //日志总数据量
  42. loading2:boolean = false;
  43. getHourLogList() {
  44. let data = {
  45. idx: 0,
  46. sum: 99999,
  47. workHourManagementLog: {
  48. workHourId: this.itemData.id,
  49. repairSummaryId: this.summaryId
  50. },
  51. };
  52. this.loading2 = true;
  53. this.mainService
  54. .getFetchDataList("simple/data", "workHourManagementLog", data)
  55. .subscribe((data) => {
  56. this.loading2 = false;
  57. if (data.status == 200) {
  58. this.logModal = true
  59. this.listLogOfData = data.list;
  60. // this.listLogLength = data.totalNum;
  61. }else{
  62. this.message.error(data.msg || "请求数据失败");
  63. }
  64. });
  65. }
  66. // 耗材日志列表
  67. getConsumableLogList() {
  68. let data = {
  69. idx: 0,
  70. sum: 99999,
  71. assetConsumablesHistory: {
  72. assetConsumablesId: this.itemData.consumableId,
  73. repairSummaryId: this.summaryId
  74. },
  75. };
  76. this.loading2 = true;
  77. this.mainService
  78. .getFetchDataList("simple/data", "assetConsumablesHistory", data)
  79. .subscribe((data) => {
  80. this.loading2 = false;
  81. if (data.status == 200) {
  82. this.logModal = true
  83. this.listLogOfData = data.list;
  84. // this.listLogLength = data.totalNum;
  85. }else{
  86. this.message.error(data.msg || "请求数据失败");
  87. }
  88. });
  89. }
  90. // 查看日志
  91. itemData:any = {};
  92. logModal:boolean = false;
  93. operationType:any;
  94. logView(type, data){
  95. this.operationType = type;
  96. this.itemData = data;
  97. if(type==1){ //耗材
  98. this.getConsumableLogList()
  99. }else{ //日志
  100. this.getHourLogList()
  101. }
  102. }
  103. // 关闭日志
  104. hideModal() {
  105. this.logModal = false;
  106. }
  107. // ============耗材start=================
  108. // 新增耗材/工时弹框
  109. modelName = ""; //模态框名称
  110. modalConsumable: boolean = false; //新增/编辑模态框
  111. add: boolean; //true:新增;false:编辑
  112. addConsumable() {
  113. this.modelName = "新增";
  114. this.add = true; //新增
  115. this.modalConsumable = true;
  116. this.initConsumableForm();
  117. }
  118. //关闭新增/编辑弹框
  119. hideConsumableModal() {
  120. this.modalConsumable = false;
  121. }
  122. // 编辑
  123. coopData: any = {}; //当前操作列
  124. editConsumable(data) {
  125. console.log(data);
  126. this.modelName = "编辑";
  127. this.add = false;
  128. this.modalConsumable = true;
  129. this.initConsumableForm();
  130. this.coopData = data;
  131. this.validateConsumableForm.controls.consumablesId.setValue(data.consumableId);
  132. this.validateConsumableForm.controls.consumablesNum.setValue(data.consumablesNum);
  133. }
  134. // 新增/编辑表单提交
  135. btnLoading: boolean = false; //提交按钮loading状态
  136. submitConsumableForm(): void {
  137. for (const i in this.validateConsumableForm.controls) {
  138. this.validateConsumableForm.controls[i].markAsDirty();
  139. this.validateConsumableForm.controls[i].updateValueAndValidity();
  140. }
  141. if (this.validateConsumableForm.invalid) {
  142. return;
  143. }
  144. console.log(this.validateConsumableForm.value);
  145. this.btnLoading = true;
  146. let postData:any = {};
  147. if (this.add) {
  148. //增加
  149. postData = {
  150. "consumableList": [
  151. {
  152. "consumablesId": this.validateConsumableForm.value.consumablesId,
  153. "consumablesNum": this.validateConsumableForm.value.consumablesNum,
  154. }
  155. ],
  156. "summaryId": this.summaryId,
  157. };
  158. } else {
  159. //编辑
  160. postData = {
  161. "consumableList": [
  162. {
  163. "consumablesId": this.validateConsumableForm.value.consumablesId,
  164. "consumablesNum": this.validateConsumableForm.value.consumablesNum,
  165. }
  166. ],
  167. "modifyNum": "edit",
  168. "summaryId": this.summaryId,
  169. };
  170. }
  171. this.mainService
  172. .addSummaryDoc(postData)
  173. .subscribe((result) => {
  174. this.btnLoading = false;
  175. this.hideConsumableModal();
  176. let msg = "";
  177. if (this.add) {
  178. msg = "新增";
  179. } else {
  180. msg = "修改";
  181. }
  182. if (result.status == 200) {
  183. this.showPromptModal(msg, true, '');
  184. } else {
  185. this.showPromptModal(msg, false, result.msg);
  186. }
  187. });
  188. }
  189. // 初始化新增form表单
  190. validateConsumableForm: FormGroup; //新增/编辑表单
  191. initConsumableForm() {
  192. this.validateConsumableForm = this.fb.group({
  193. consumablesId: [null, [Validators.required]],
  194. consumablesNum: [1, [Validators.required]],
  195. });
  196. console.log(this.validateConsumableForm.controls)
  197. }
  198. // 边输边搜节流阀
  199. isLoading = false;
  200. changeInp(model, e) {
  201. this.isLoading = true;
  202. this.changeInpSubject.next([model, e]);
  203. }
  204. // 获取院区配置信息
  205. itsmZeroStock:any = {};//是否支持零库存
  206. itsmParentConsumable:any = {};//是否支持父级科室耗材
  207. getHospitalConfig() {
  208. let postData = {
  209. idx: 0,
  210. sum: 9999,
  211. hospitalConfig: {
  212. model: "itsm",
  213. hosId: this.hosId,
  214. },
  215. }
  216. this.mainService
  217. .getFetchDataList("simple/data", "hospitalConfig", postData)
  218. .subscribe((result) => {
  219. let list = result.list || [];
  220. this.itsmZeroStock = list.find(v => v.key == 'itsmZeroStock') || {};
  221. this.itsmParentConsumable = list.find(v => v.key == 'itsmParentConsumable') || {};
  222. this.getConsumableList();
  223. });
  224. }
  225. // 获取耗材
  226. consumableList: any = [];
  227. getConsumableList(keyword = '', isShowValue = false) {
  228. let postData:any = {
  229. consumable: {
  230. name: keyword,
  231. showZero: true,
  232. },
  233. idx: 0,
  234. sum: 20,
  235. };
  236. if(this.itsmParentConsumable.value == 1){
  237. postData.consumable.upHosId = this.hosId;
  238. }else{
  239. postData.consumable.hosId = this.hosId;
  240. }
  241. this.mainService
  242. .getFetchDataList("simple/data", "consumable", postData)
  243. .subscribe((data) => {
  244. this.isLoading = false;
  245. let consumableList = data.list || [];
  246. if(isShowValue && this.coopData && this.coopData.groupId){
  247. consumableList = consumableList.filter(v => v.id !== this.coopData.id)
  248. consumableList.unshift(this.coopData);
  249. }
  250. this.consumableList = consumableList;
  251. });
  252. }
  253. // ============耗材end=================
  254. // ============工时start=================
  255. // 新增耗材/工时弹框
  256. modalWorkHourManagement: boolean = false; //新增/编辑模态框
  257. addWorkHourManagement() {
  258. this.modelName = "新增";
  259. this.add = true; //新增
  260. this.modalWorkHourManagement = true;
  261. this.initWorkHourManagementForm();
  262. }
  263. //关闭新增/编辑弹框
  264. hideWorkHourManagementModal() {
  265. this.modalWorkHourManagement = false;
  266. }
  267. // 编辑
  268. editWorkHourManagement(data) {
  269. console.log(data);
  270. this.modelName = "编辑";
  271. this.add = false;
  272. this.modalWorkHourManagement = true;
  273. this.initWorkHourManagementForm();
  274. this.coopData = data;
  275. this.validateWorkHourManagementForm.controls.workHourId.setValue(data.id);
  276. this.validateWorkHourManagementForm.controls.workHourNum.setValue(data.workHourNum2);
  277. }
  278. // 新增/编辑表单提交
  279. submitWorkHourManagementForm(): void {
  280. for (const i in this.validateWorkHourManagementForm.controls) {
  281. this.validateWorkHourManagementForm.controls[i].markAsDirty();
  282. this.validateWorkHourManagementForm.controls[i].updateValueAndValidity();
  283. }
  284. if (this.validateWorkHourManagementForm.invalid) {
  285. return;
  286. }
  287. console.log(this.validateWorkHourManagementForm.value);
  288. this.btnLoading = true;
  289. let postData:any = {};
  290. if (this.add) {
  291. //增加
  292. // let workHourManagementList = this.summaryObj.workHourManagementList || [];
  293. // postData = {
  294. // "workHourManagementList": workHourManagementList.map(v => ({workHourId: v.id, workHourNum: v.workHourNum2 || 1})),
  295. // "summaryId": this.summaryId,
  296. // };
  297. // let index = postData.workHourManagementList.findIndex(v => v.workHourId == this.validateWorkHourManagementForm.value.workHourId.slice(-1)[0]);
  298. // if(index > -1){
  299. // postData.workHourManagementList[index].workHourNum += this.validateWorkHourManagementForm.value.workHourNum;
  300. // }else{
  301. // postData.workHourManagementList.push(
  302. // {
  303. // "workHourId": this.validateWorkHourManagementForm.value.workHourId.slice(-1)[0],
  304. // "workHourNum": this.validateWorkHourManagementForm.value.workHourNum,
  305. // }
  306. // );
  307. // }
  308. postData ={
  309. "workHourManagementList": [
  310. {
  311. "workHourId": this.validateWorkHourManagementForm.value.workHourId.slice(-1)[0],
  312. "workHourNum": this.validateWorkHourManagementForm.value.workHourNum,
  313. }
  314. ],
  315. "summaryId": this.summaryId,
  316. }
  317. } else {
  318. //编辑
  319. postData = {
  320. "workHourManagementList": [
  321. {
  322. "workHourId": this.coopData.id,
  323. "workHourNum": this.validateWorkHourManagementForm.value.workHourNum,
  324. }
  325. ],
  326. "modifyNum": "edit",
  327. "summaryId": this.summaryId,
  328. };
  329. }
  330. this.mainService
  331. .addSummaryDoc(postData)
  332. .subscribe((result) => {
  333. this.btnLoading = false;
  334. this.hideWorkHourManagementModal();
  335. let msg = "";
  336. if (this.add) {
  337. msg = "新增";
  338. } else {
  339. msg = "修改";
  340. }
  341. if (result.status == 200) {
  342. this.showPromptModal(msg, true, '');
  343. } else {
  344. this.showPromptModal(msg, false, result.msg);
  345. }
  346. });
  347. }
  348. // 初始化新增form表单
  349. validateWorkHourManagementForm: FormGroup; //新增/编辑表单
  350. initWorkHourManagementForm() {
  351. this.validateWorkHourManagementForm = this.fb.group({
  352. workHourId: [null, [Validators.required]],
  353. workHourNum: [1, [Validators.required]],
  354. });
  355. console.log(this.validateWorkHourManagementForm.controls)
  356. }
  357. // 获取工时
  358. workHourManagementList: any = [];
  359. getWorkHourManagementList() {
  360. let postData = {
  361. workHourManagement: {
  362. hosId: this.hosId,
  363. showSecond: 1,
  364. disableType:1
  365. },
  366. idx: 0,
  367. sum: 9999,
  368. };
  369. this.mainService
  370. .getFetchDataList("simple/data", "workHourManagement", postData)
  371. .subscribe((res) => {
  372. this.isLoading = false;
  373. let workHourManagementList = res.list || [];
  374. workHourManagementList = workHourManagementList.map(v => ({...v, parentId: v.parent ? v.parent.id : undefined, label: v.workName, value: v.id}));
  375. this.workHourManagementList = this.tool.tranListToTreeDataLeaf(workHourManagementList, undefined, "parentId");
  376. console.log(this.workHourManagementList);
  377. });
  378. }
  379. // ============工时end=================
  380. // 获取汇总单信息
  381. summaryObj:any = {
  382. consumableList: [],//耗材列表
  383. workHourManagementList: [],//工时列表
  384. };
  385. summaryId = undefined;//汇总单Id
  386. summaryLoading:boolean = false;
  387. getSummaryList() {
  388. this.summaryLoading = true;
  389. let postData = {
  390. "incidentId": this.id,
  391. };
  392. this.mainService
  393. .querySummaryDocNew(postData)
  394. .subscribe((res:any) => {
  395. this.summaryLoading = false;
  396. if(res.status == 200){
  397. this.summaryObj = {...{consumableList:[], workHourManagementList: []}, ...res };
  398. console.log(this.summaryObj)
  399. this.summaryId = res.summaryId;
  400. }else if(res.status == 201){
  401. // 事件第一次绑定汇总单
  402. this.summaryId = res.summaryId;
  403. }else{
  404. this.message.error(res.msg || '请求数据失败!');
  405. }
  406. });
  407. }
  408. delModal: boolean = false; //删除模态框
  409. tipsMsg1: string; //提示框信息
  410. tipsMsg2: string; //操作后信息
  411. confirmDelType: string; //确认的类型(启用/停用,删除)
  412. showDelModal(
  413. data,
  414. tipsMsg1: string,
  415. tipsMsg2: string,
  416. type: string,
  417. ) {
  418. this.confirmDelType = type;
  419. this.delModal = true;
  420. this.coopData = data;
  421. this.tipsMsg1 = tipsMsg1;
  422. this.tipsMsg2 = tipsMsg2;
  423. }
  424. // 隐藏删除框
  425. hideDelModal() {
  426. this.delModal = false;
  427. }
  428. // 确认删除
  429. confirmDel() {
  430. this.btnLoading = true;
  431. if (this.confirmDelType === "delConsumable") {
  432. //删除-耗材
  433. let postData = {
  434. "consumableList": [
  435. {
  436. "consumablesId": this.coopData.consumableId,
  437. "consumablesNum": this.coopData.consumablesNum,
  438. }
  439. ],
  440. "remove": "remove",
  441. "summaryId": this.summaryId,
  442. };
  443. this.mainService
  444. .addSummaryDoc(postData)
  445. .subscribe((data) => {
  446. this.btnLoading = false;
  447. this.delModal = false;
  448. if (data.status == 200) {
  449. this.showPromptModal(this.tipsMsg2, true, "");
  450. } else {
  451. this.showPromptModal(this.tipsMsg2, false, data.msg);
  452. }
  453. });
  454. }else if (this.confirmDelType === "delWorkHourManagement") {
  455. //删除-工时
  456. let postData = {
  457. "workHourManagementList": [
  458. {
  459. "workHourId": this.coopData.id,
  460. "workHourNum": this.coopData.workHourNum2,
  461. }
  462. ],
  463. "remove": "remove",
  464. "summaryId": this.summaryId,
  465. };
  466. this.mainService
  467. .addSummaryDoc(postData)
  468. .subscribe((data) => {
  469. this.btnLoading = false;
  470. this.delModal = false;
  471. if (data.status == 200) {
  472. this.showPromptModal(this.tipsMsg2, true, "");
  473. } else {
  474. this.showPromptModal(this.tipsMsg2, false, data.msg);
  475. }
  476. });
  477. }
  478. }
  479. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  480. promptContent: string; //操作提示框提示信息
  481. ifSuccess: boolean; //操作成功/失败
  482. promptInfo: string; //操作结果提示信息
  483. promptModalShow: boolean; //操作提示框是否展示
  484. showPromptModal(con, success, promptInfo?) {
  485. this.promptModalShow = false;
  486. this.promptContent = con;
  487. this.ifSuccess = success;
  488. this.promptInfo = promptInfo;
  489. setTimeout(() => {
  490. this.promptModalShow = true;
  491. }, 100);
  492. this.getSummaryList();
  493. }
  494. }