incident-handle-info.component.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import { Component, OnInit, Input, Output, EventEmitter, ViewChild, OnChanges, SimpleChanges } from '@angular/core';
  2. import { MainService } from '../../../services/main.service';
  3. import { Router } from '@angular/router';
  4. import { ToolService } from 'src/app/services/tool.service';
  5. import { UploadFile } from 'ng-zorro-antd';
  6. import { Subject } from 'rxjs';
  7. import { debounceTime } from 'rxjs/operators';
  8. import cloneDeep from 'lodash-es/cloneDeep'
  9. import { HttpClient } from '@angular/common/http';
  10. @Component({
  11. selector: 'app-incident-handle-info',
  12. templateUrl: './incident-handle-info.component.html',
  13. styleUrls: ['./incident-handle-info.component.less']
  14. })
  15. export class IncidentHandleInfoComponent implements OnInit, OnChanges {
  16. @Input() incidentData:any = {};
  17. @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  18. @Output() confirmModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  19. @Output() changeCategoryHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  20. constructor(
  21. private mainService: MainService,
  22. private router: Router,
  23. public tool: ToolService,
  24. private http: HttpClient,
  25. ) { }
  26. incidentDataCopy:any = {};
  27. changeInpSubject = new Subject(); //防抖
  28. ngOnChanges(changes: SimpleChanges){
  29. console.log('changes:', changes)
  30. // 引入知识库
  31. if(changes.incidentData && !changes.incidentData.firstChange && changes.incidentData.currentValue){
  32. this.incidentDataCopy.handleDescription = changes.incidentData.currentValue.handleDescription;
  33. }
  34. }
  35. ngOnInit() {
  36. console.log('ngOnInit')
  37. //防抖
  38. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  39. if(v[0] === 'synergetic'){
  40. this.getSynergeticList(v[1]);
  41. }else if(v[0] === 'assetId'){
  42. this.getAssetList(v[1]);
  43. }else if(v[0] === 'category'){
  44. this.getIncidentCategoryList(v[1]);
  45. }
  46. });
  47. this.init();
  48. }
  49. init(){
  50. console.log('初始化')
  51. this.hosId = this.tool.getCurrentHospital().id;
  52. console.log('this.incidentData:', this.incidentData)
  53. this.incidentDataCopy = cloneDeep(this.incidentData);
  54. this.incidentDataCopy.synergetic = [];
  55. if(this.incidentDataCopy.category){
  56. this.incidentDataCopy.category = this.incidentDataCopy.category.id;
  57. }
  58. if(this.incidentDataCopy.transSolution === undefined){
  59. this.incidentDataCopy.transSolution = 0;
  60. }
  61. console.log('this.incidentDataCopy:', this.incidentDataCopy)
  62. this.getHospitalConfig();
  63. this.getHandleCategorys();
  64. this.getClosecodes();
  65. this.getSynergeticList();
  66. this.getAssetList();
  67. this.getIncidentCategoryList();
  68. }
  69. // 修改故障现象
  70. changeCategory(id){
  71. this.changeCategoryHs.emit(id);
  72. }
  73. // 边输边搜节流阀
  74. changeInp(model, e) {
  75. this.isLoading = true;
  76. this.changeInpSubject.next([model, e]);
  77. }
  78. // 关闭弹窗
  79. hideModal() {
  80. this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  81. }
  82. // 获取处理方式列表
  83. handleCategoryList:any[] = [];
  84. getHandleCategorys(){
  85. this.mainService.getDictionary("list", "incident_handle_type").subscribe((data) => {
  86. this.handleCategoryList = data || [];
  87. console.log(this.incidentDataCopy)
  88. if(!this.incidentDataCopy.handleCategory){
  89. let handleCategory = this.handleCategoryList.find(v => v.value == '1');
  90. this.incidentDataCopy.handleCategory = handleCategory ? handleCategory.id : undefined;
  91. }
  92. });
  93. }
  94. // 获取处理结果列表
  95. closecodeList:any[] = [];
  96. getClosecodes(){
  97. this.mainService.getDictionary("list", "incident_closecode").subscribe((data) => {
  98. this.closecodeList = data || [];
  99. console.log(this.incidentDataCopy)
  100. if(!this.incidentDataCopy.closecode){
  101. let closecode = this.closecodeList.find(v => v.value == '1');
  102. this.incidentDataCopy.closecode = closecode ? closecode.id : undefined;
  103. }
  104. });
  105. }
  106. // 获取协同人员
  107. hosId:any;
  108. isLoading = false;
  109. synergeticList: any = [];
  110. getSynergeticList(keyword = '') {
  111. let postData = {
  112. user: {
  113. hospital: { id: this.incidentDataCopy.duty.id },
  114. name: keyword,
  115. simpleQuery: true,
  116. roleCodes: 'first-line support',
  117. engineer: 1,
  118. },
  119. idx: 0,
  120. sum: 20,
  121. };
  122. this.mainService
  123. .getFetchDataList("simple/data", "user", postData)
  124. .subscribe((data) => {
  125. this.synergeticList = data.list;
  126. this.isLoading = false;
  127. });
  128. }
  129. // 获取故障现象
  130. incidentCategoryList:any[] = [];
  131. handleInfoLoading:boolean = false;
  132. getIncidentCategoryList(keyword = ''){
  133. let { hospital, type } = this.tool.getHospitalOrDuty();
  134. if(type === 'hospital' || type === 'department'){
  135. this.incidentCategoryList = [];
  136. this.incidentDataCopy.category = null;
  137. return;
  138. };
  139. let postData = {
  140. category: {
  141. category: keyword,
  142. selectType: 'mutlQuery',
  143. hierarchy: 3,
  144. dutyIds: type === 'duty' ? hospital.id.toString() : undefined,
  145. },
  146. };
  147. this.handleInfoLoading = true;
  148. this.mainService.incidentPost("listIncidentCategory", postData).subscribe(res => {
  149. this.handleInfoLoading = false;
  150. this.incidentCategoryList = res.data || [];
  151. if(this.incidentDataCopy.category){
  152. let obj = this.incidentCategoryList.find(v => v.id == this.incidentDataCopy.category);
  153. this.incidentDataCopy.category = obj ? obj.id : undefined;
  154. this.changeCategoryHs.emit(this.incidentDataCopy.category);
  155. }
  156. })
  157. }
  158. // 获取院区配置信息
  159. itsmIncidentAsset:any = {};//是否事件关联资产
  160. getHospitalConfig() {
  161. let postData = {
  162. idx: 0,
  163. sum: 9999,
  164. hospitalConfig: {
  165. model: "itsm",
  166. hosId: this.hosId,
  167. },
  168. }
  169. this.mainService
  170. .getFetchDataList("simple/data", "hospitalConfig", postData)
  171. .subscribe((result) => {
  172. let list = result.list || [];
  173. this.itsmIncidentAsset = list.find(v => v.key == 'itsmIncidentAsset') || {};
  174. });
  175. }
  176. // 获取资产列表
  177. assetList: any = [];
  178. getAssetList(keyword = '') {
  179. let postData = {
  180. asset: {
  181. hosId: this.hosId,
  182. name: keyword,
  183. },
  184. idx: 0,
  185. sum: 20,
  186. };
  187. this.mainService
  188. .getFetchDataList("simple/data", "asset", postData)
  189. .subscribe((data) => {
  190. this.assetList = data.list;
  191. });
  192. }
  193. // 图片相关
  194. showUploadList = {
  195. showPreviewIcon: true,
  196. showRemoveIcon: true,
  197. hidePreviewIconInNonImage: true
  198. };
  199. fileList = [
  200. // {
  201. // uid: -1,
  202. // name: 'xxx.png',
  203. // status: '1',
  204. // url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
  205. // }
  206. ];
  207. previewImage: string | undefined = '';
  208. previewVisible = false;
  209. handlePreview = (file: UploadFile) => {
  210. console.log('file1:', file)
  211. this.previewImage = file.url || file.thumbUrl;
  212. this.previewVisible = true;
  213. };
  214. beforeUpload = (file: UploadFile): boolean => {
  215. console.log('file2:', file)
  216. this.fileList = [...this.fileList, file];
  217. setTimeout(async () => {
  218. file.url = await this.getBase64(file);
  219. }, 0);
  220. console.log('this.fileList:', this.fileList)
  221. return true;
  222. };
  223. // customReq = (item: UploadXHRArgs) => {
  224. // console.log(item);
  225. // // Create a FormData here to store files and other parameters.
  226. // const formData = new FormData();
  227. // // tslint:disable-next-line:no-any
  228. // formData.append('file', item.file as any);
  229. // formData.append('filename', item.file.name);
  230. // const req = new HttpRequest('POST', item.action!, formData, {
  231. // reportProgress: true,
  232. // withCredentials: true
  233. // });
  234. // // Always returns a `Subscription` object. nz-upload would automatically unsubscribe it at correct time.
  235. // return this.http.request(req).subscribe(
  236. // // tslint:disable-next-line no-any
  237. // (event: HttpEvent<any>) => {
  238. // if (event.type === HttpEventType.UploadProgress) {
  239. // if (event.total! > 0) {
  240. // // tslint:disable-next-line:no-any
  241. // (event as any).percent = (event.loaded / event.total!) * 100;
  242. // }
  243. // item.onProgress!(event, item.file!);
  244. // } else if (event instanceof HttpResponse) {
  245. // item.onSuccess!(event.body, item.file!, event);
  246. // }
  247. // },
  248. // err => {
  249. // item.onError!(err, item.file!);
  250. // }
  251. // );
  252. // };
  253. getBase64(file: any): Promise<any> {
  254. return new Promise((resolve, reject) => {
  255. const reader = new FileReader();
  256. reader.readAsDataURL(file);
  257. reader.onload = () => resolve(reader.result);
  258. reader.onerror = error => reject(error);
  259. });
  260. }
  261. // 临时上传图片
  262. temporarilyUrl = this.mainService.returnUploadUrl('temporarily', 0);
  263. // 上传附件---start
  264. // model-取消
  265. maskFlag:boolean = false;
  266. isShow = false;
  267. hideExcelImport() {
  268. this.isShow = false;
  269. }
  270. // 触发
  271. excelImport() {
  272. this.isShow = true;
  273. }
  274. submitExcelImport({fileList}){
  275. this.isShow = false;
  276. console.log(fileList);
  277. }
  278. // 上传附件---end
  279. fileList2:any[] = [];
  280. }