incident-handle.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
  2. import { MainService } from '../../../services/main.service';
  3. import { Router } from '@angular/router';
  4. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  5. import { NzMessageService } from 'ng-zorro-antd';
  6. import { ToolService } from 'src/app/services/tool.service';
  7. import { forkJoin } from 'rxjs';
  8. import { IncidentHandleInfoComponent } from '../incident-handle-info/incident-handle-info.component';
  9. import { IncidentHandleInfoSimpleComponent } from '../incident-handle-info-simple/incident-handle-info-simple.component';
  10. import cloneDeep from 'lodash-es/cloneDeep'
  11. import { HttpClient, HttpRequest, HttpResponse } from '@angular/common/http';
  12. import { filter } from 'rxjs/operators';
  13. @Component({
  14. selector: 'app-incident-handle',
  15. templateUrl: './incident-handle.component.html',
  16. styleUrls: ['./incident-handle.component.less']
  17. })
  18. export class IncidentHandleComponent implements OnInit {
  19. @ViewChild("osComponentRef1", {
  20. read: OverlayScrollbarsComponent,
  21. static: false,
  22. })
  23. osComponentRef1: OverlayScrollbarsComponent;
  24. @ViewChild("osComponentRef2", {
  25. read: OverlayScrollbarsComponent,
  26. static: false,
  27. })
  28. osComponentRef2: OverlayScrollbarsComponent;
  29. @ViewChild("osComponentRef3", {
  30. read: OverlayScrollbarsComponent,
  31. static: false,
  32. })
  33. osComponentRef3: OverlayScrollbarsComponent;
  34. @ViewChild(IncidentHandleInfoComponent, { static: false }) incidentHandleInfoComponent: IncidentHandleInfoComponent;
  35. @ViewChild(IncidentHandleInfoSimpleComponent, { static: false }) incidentHandleInfoSimpleComponent: IncidentHandleInfoSimpleComponent;
  36. @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  37. @Output() confirmModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  38. @Input() id: any;
  39. constructor(
  40. private mainService: MainService,
  41. private router: Router,
  42. private message: NzMessageService,
  43. private tool: ToolService,
  44. private http: HttpClient,
  45. ) { }
  46. isLoading = false;
  47. hosId:any;
  48. tabs:any[] = [
  49. { name: '处理信息', value: 1 },
  50. // { name: '汇总单', value: 2 },
  51. ]
  52. // 点击tab
  53. activeTabValue:any = 1;
  54. clickTbab(item){
  55. this.activeTabValue = item.value;
  56. }
  57. ngOnInit() {
  58. this.hosId = this.tool.getCurrentHospital().id;
  59. this.getDetail();
  60. }
  61. // 关闭弹窗
  62. hideModal() {
  63. this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  64. }
  65. // 是否进入汇总单
  66. isInSummaryOrder(){
  67. return this.incidentData.duty && this.itsmSummarySheet.value == 1 && (this.incidentData.handlingPersonnelUser.id == this.tool.getCurrentUserId());
  68. }
  69. // 获取院区配置信息
  70. itsmSummarySheet:any = {};//是否需要填写汇总单
  71. itsmSimpleHandle:any = {};//是否简单处理
  72. getHospitalConfig() {
  73. let postData = {
  74. idx: 0,
  75. sum: 9999,
  76. hospitalConfig: {
  77. model: "itsm",
  78. hosId: this.hosId,
  79. },
  80. }
  81. this.mainService
  82. .getFetchDataList("simple/data", "hospitalConfig", postData)
  83. .subscribe((result) => {
  84. let list = result.list || [];
  85. this.itsmSummarySheet = list.find(v => v.key == 'itsmSummarySheet') || {};
  86. this.itsmSimpleHandle = list.find(v => v.key == 'itsmSimpleHandle') || {};
  87. console.log(this.itsmSummarySheet)
  88. if(this.isInSummaryOrder()){
  89. let summary = this.tabs.some(v => v.value == 2);
  90. console.log(summary)
  91. !summary && this.tabs.push({ name: '汇总单', value: 2 });
  92. }
  93. });
  94. }
  95. // 获取详情数据
  96. incidentData:any;
  97. maskFlag:any = false;
  98. getDetail() {
  99. this.maskFlag = this.message.loading("正在加载中..", {
  100. nzDuration: 0,
  101. }).messageId;
  102. this.mainService
  103. .getFetchData("simple/data", "incident", this.id)
  104. .subscribe((result) => {
  105. this.message.remove(this.maskFlag);
  106. this.maskFlag = false;
  107. this.incidentData = result.data || {};
  108. this.getDictionaryList();
  109. this.getHospitalConfig();
  110. });
  111. }
  112. //获取知识库状态/类型
  113. knowageLoading:boolean = false;
  114. getDictionaryList() {
  115. this.knowageLoading = true;
  116. let solutionStatus$ = this.mainService.getDictionary('list', 'solution_status', true);
  117. let solutionType$ = this.mainService.getDictionary('list', 'solution_type', true);
  118. forkJoin(solutionStatus$, solutionType$).subscribe((data:any[]) => {
  119. this.knowageLoading = false;
  120. let solutionStatusList = data[0] || [];
  121. let solutionTypeList = data[1] || [];
  122. this.solutionStatus = solutionStatusList.find(item => item.value == 3);
  123. console.log('this.solutionStatus:', this.solutionStatus)
  124. this.solutionType = solutionTypeList.find(item => item.value == 1);
  125. console.log('this.solutionType:', this.solutionType)
  126. })
  127. }
  128. solutionStatus;//知识库状态
  129. solutionType;//知识库类型
  130. // 修改故障现象
  131. changeCategoryHs(categoryId){
  132. this.getKnowledgeList(categoryId);
  133. }
  134. // 获取知识库
  135. knowageList:any[] = [];
  136. getKnowledgeList(categoryId) {
  137. if(!(categoryId && this.solutionStatus && this.solutionType)){
  138. this.knowageLoading = false;
  139. this.knowageList = [];
  140. return;
  141. }
  142. this.knowageLoading = true;
  143. let postData:any = {
  144. idx: 0,
  145. sum: 9999,
  146. solution: {
  147. categoryId,
  148. status: this.solutionStatus,
  149. type: this.solutionType,
  150. },
  151. };
  152. this.mainService
  153. .getFetchDataList('simple/data', 'solution', postData)
  154. .subscribe((result) => {
  155. this.knowageLoading = false;
  156. if(result.status == 200){
  157. this.knowageList = result.list || [];
  158. }else{
  159. this.message.error(result.msg || '请求数据失败!');
  160. }
  161. });
  162. }
  163. // 知识库查看-知道了
  164. coopData:any = {};
  165. isShowKnowledge:boolean = false;
  166. showKnowledgeModal(data) {
  167. this.coopData = data || {};
  168. this.isShowKnowledge = true;
  169. }
  170. cancelKnowledgeModal(flag) {
  171. this.isShowKnowledge = false;
  172. }
  173. // 图片上传
  174. uploadImages(file, id){
  175. const formData = new FormData();
  176. formData.append('file', file);
  177. formData.append('fileName', file.name);
  178. const req = new HttpRequest('Post', this.mainService.returnUploadUrl('incident', id), formData, {
  179. reportProgress: true
  180. });
  181. return this.http.request(req).pipe(filter(e => e instanceof HttpResponse)).toPromise();
  182. }
  183. // 附件上传
  184. uploadFiles(file, id){
  185. const formData = new FormData();
  186. formData.append('file', file);
  187. formData.append('fileName', file.name);
  188. const req = new HttpRequest('Post', this.mainService.returnUploadUrl('handleAttachment', id), formData, {
  189. reportProgress: true
  190. });
  191. return this.http.request(req).pipe(filter(e => e instanceof HttpResponse)).toPromise();
  192. }
  193. // 引入知识库
  194. solutionId;//引用的知识库Id
  195. importKnowage(item){
  196. console.log(item)
  197. this.incidentData = {...this.incidentData, handleDescription: `引用知识库解决,知识库编号:${item.solutionNumber}`};
  198. this.solutionId = item.id;
  199. }
  200. // 表单提交
  201. submitForm() {
  202. console.log(this.itsmSimpleHandle.value)
  203. if(this.itsmSimpleHandle.value == 0){
  204. // 详细处理
  205. console.log(this.incidentHandleInfoComponent)
  206. // return;
  207. if(!this.incidentHandleInfoComponent.incidentDataCopy.handleDescription){
  208. this.message.warning('请选择解决方案!');
  209. return;
  210. }
  211. if(!this.incidentHandleInfoComponent.incidentDataCopy.category){
  212. this.message.warning('请选择故障现象!');
  213. return;
  214. }
  215. if(!this.incidentHandleInfoComponent.incidentDataCopy.handleCategory){
  216. this.message.warning('请选择处理方式!');
  217. return;
  218. }
  219. if(!this.incidentHandleInfoComponent.incidentDataCopy.closecode){
  220. this.message.warning('请选择处理结果!');
  221. return;
  222. }
  223. this.maskFlag = this.message.loading("正在加载中..", {
  224. nzDuration: 0,
  225. }).messageId;
  226. let incidentDataCopy = cloneDeep(this.incidentHandleInfoComponent.incidentDataCopy);
  227. // 图片上传
  228. if(this.incidentHandleInfoComponent.fileList.length){
  229. console.log(this.incidentHandleInfoComponent.fileList.map(v => v.originFileObj));
  230. this.incidentHandleInfoComponent.fileList.map(v => v.originFileObj).forEach(async file => {
  231. await this.uploadImages(file, incidentDataCopy.id);
  232. })
  233. }
  234. // return;
  235. // 附件上传
  236. if(this.incidentHandleInfoComponent.fileList2.length){
  237. console.log(this.incidentHandleInfoComponent.fileList2.map(v => v.originFileObj));
  238. this.incidentHandleInfoComponent.fileList2.map(v => v.originFileObj).forEach(async file => {
  239. await this.uploadFiles(file, incidentDataCopy.id);
  240. })
  241. }
  242. // return;
  243. let postData = {
  244. solutionId: this.solutionId,
  245. incident: {
  246. ...incidentDataCopy,
  247. handleCategory: incidentDataCopy.handleCategory ? { id: incidentDataCopy.handleCategory }: undefined,
  248. closecode: incidentDataCopy.closecode ? { id: incidentDataCopy.closecode }: undefined,
  249. synergetic: incidentDataCopy.synergetic.length ? incidentDataCopy.synergetic.map(v => ({id: v})): undefined,
  250. category: incidentDataCopy.category ? { id: incidentDataCopy.category }: undefined,
  251. },
  252. }
  253. console.log(postData);
  254. // return;
  255. this.mainService
  256. .flowPost("incident/task/doing", postData)
  257. .subscribe((result) => {
  258. this.message.remove(this.maskFlag);
  259. this.maskFlag = false;
  260. this.confirmModelHs.emit();
  261. if (result.state == 200) {
  262. this.message.success('处理成功');
  263. } else {
  264. this.message.error('处理失败');
  265. }
  266. });
  267. }else if(this.itsmSimpleHandle.value == 1){
  268. // 简单处理
  269. console.log(this.incidentHandleInfoSimpleComponent)
  270. // return;
  271. if(!this.incidentHandleInfoSimpleComponent.incidentDataCopy.handleCategory){
  272. this.message.warning('请选择处理方式!');
  273. return;
  274. }
  275. this.maskFlag = this.message.loading("正在加载中..", {
  276. nzDuration: 0,
  277. }).messageId;
  278. let incidentDataCopy = cloneDeep(this.incidentHandleInfoSimpleComponent.incidentDataCopy);
  279. // 图片上传
  280. if(this.incidentHandleInfoSimpleComponent.fileList.length){
  281. console.log(this.incidentHandleInfoSimpleComponent.fileList.map(v => v.originFileObj));
  282. this.incidentHandleInfoSimpleComponent.fileList.map(v => v.originFileObj).forEach(async file => {
  283. await this.uploadImages(file, incidentDataCopy.id);
  284. })
  285. }
  286. // return;
  287. let postData = {
  288. incident: {
  289. ...incidentDataCopy,
  290. handleCategory: incidentDataCopy.handleCategory ? { id: incidentDataCopy.handleCategory }: undefined,
  291. synergetic: incidentDataCopy.synergetic.length ? incidentDataCopy.synergetic.map(v => ({id: v})): undefined,
  292. },
  293. }
  294. console.log(postData);
  295. this.mainService
  296. .flowPost("incident/task/doing", postData)
  297. .subscribe((result) => {
  298. this.message.remove(this.maskFlag);
  299. this.maskFlag = false;
  300. this.confirmModelHs.emit();
  301. if (result.state == 200) {
  302. this.message.success('处理成功');
  303. } else {
  304. this.message.error('处理失败');
  305. }
  306. });
  307. }
  308. }
  309. }