incident-handle-info-simple.component.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 { NzMessageService, UploadFile, UploadXHRArgs } from 'ng-zorro-antd';
  6. import cloneDeep from 'lodash-es/cloneDeep'
  7. import { debounceTime } from 'rxjs/operators';
  8. import { Subject } from 'rxjs';
  9. import { HttpClient, HttpEvent, HttpResponse, HttpEventType, HttpRequest } from '@angular/common/http';
  10. @Component({
  11. selector: 'app-incident-handle-info-simple',
  12. templateUrl: './incident-handle-info-simple.component.html',
  13. styleUrls: ['./incident-handle-info-simple.component.less']
  14. })
  15. export class IncidentHandleInfoSimpleComponent 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. constructor(
  20. private mainService: MainService,
  21. private router: Router,
  22. public tool: ToolService,
  23. private message: NzMessageService,
  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 && changes.incidentData.previousValue && !changes.incidentData.previousValue.id){
  32. this.init();
  33. }
  34. if(changes.incidentData && changes.incidentData.firstChange && changes.incidentData.currentValue && !changes.incidentData.previousValue){
  35. this.init();
  36. }
  37. }
  38. ngOnInit() {
  39. //防抖
  40. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  41. if(v[0] === 'synergetic'){
  42. this.getSynergeticList(v[1]);
  43. }else if(v[0] === 'assetId'){
  44. this.getAssetProductList(v[1]);
  45. }
  46. });
  47. }
  48. init(){
  49. console.log('初始化')
  50. this.hosId = this.tool.getCurrentHospital().id;
  51. this.incidentDataCopy = cloneDeep(this.incidentData);
  52. this.incidentDataCopy.synergetic = [];
  53. this.getHandleCategorys();
  54. this.getSynergeticList();
  55. this.getAssetProductList();
  56. }
  57. // 边输边搜节流阀
  58. changeInp(model, e) {
  59. this.isLoading = true;
  60. this.changeInpSubject.next([model, e]);
  61. }
  62. // 关闭弹窗
  63. hideModal() {
  64. this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  65. }
  66. // 获取处理方式列表
  67. handleCategoryList:any[] = [];
  68. getHandleCategorys(){
  69. this.mainService.getDictionary("list", "incident_handle_type").subscribe((data) => {
  70. this.handleCategoryList = data || [];
  71. console.log(this.incidentDataCopy)
  72. if(!this.incidentDataCopy.handleCategory){
  73. let handleCategory = this.handleCategoryList.find(v => v.value == '1');
  74. this.incidentDataCopy.handleCategory = handleCategory ? handleCategory.id : undefined;
  75. }
  76. });
  77. }
  78. // 获取协同人员
  79. hosId:any;
  80. isLoading = false;
  81. synergeticList: any = [];
  82. getSynergeticList(keyword = '') {
  83. let postData = {
  84. user: {
  85. hospital: { id: this.hosId },
  86. name: keyword,
  87. simpleQuery: true,
  88. roleCodes: 'first-line support',
  89. engineer: 1,
  90. },
  91. idx: 0,
  92. sum: 20,
  93. };
  94. this.mainService
  95. .getFetchDataList("simple/data", "user", postData)
  96. .subscribe((data) => {
  97. this.synergeticList = data.list;
  98. this.isLoading = false;
  99. });
  100. }
  101. // 获取资产列表
  102. assetProducList: any = [];
  103. getAssetProductList(keyword = '') {
  104. let postData = {
  105. assetProduct: {
  106. hosId: this.hosId,
  107. name: keyword,
  108. },
  109. idx: 0,
  110. sum: 20,
  111. };
  112. this.mainService
  113. .getFetchDataList("simple/data", "assetProduct", postData)
  114. .subscribe((data) => {
  115. this.assetProducList = data.list;
  116. });
  117. }
  118. // 图片相关
  119. showUploadList = {
  120. showPreviewIcon: true,
  121. showRemoveIcon: true,
  122. hidePreviewIconInNonImage: true
  123. };
  124. fileList = [
  125. // {
  126. // uid: -1,
  127. // name: 'xxx.png',
  128. // status: '1',
  129. // url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
  130. // }
  131. ];
  132. previewImage: string | undefined = '';
  133. previewVisible = false;
  134. handlePreview = (file: UploadFile) => {
  135. console.log('file1:', file)
  136. this.previewImage = file.url || file.thumbUrl;
  137. this.previewVisible = true;
  138. };
  139. beforeUpload = (file: UploadFile): boolean => {
  140. console.log('file2:', file)
  141. this.fileList = [...this.fileList, file];
  142. setTimeout(async () => {
  143. file.url = await this.getBase64(file);
  144. }, 0);
  145. console.log('this.fileList:', this.fileList)
  146. return true;
  147. };
  148. // customReq = (item: UploadXHRArgs) => {
  149. // console.log(item);
  150. // // Create a FormData here to store files and other parameters.
  151. // const formData = new FormData();
  152. // // tslint:disable-next-line:no-any
  153. // formData.append('file', item.file as any);
  154. // formData.append('filename', item.file.name);
  155. // const req = new HttpRequest('POST', item.action!, formData, {
  156. // reportProgress: true,
  157. // withCredentials: true
  158. // });
  159. // // Always returns a `Subscription` object. nz-upload would automatically unsubscribe it at correct time.
  160. // return this.http.request(req).subscribe(
  161. // // tslint:disable-next-line no-any
  162. // (event: HttpEvent<any>) => {
  163. // if (event.type === HttpEventType.UploadProgress) {
  164. // if (event.total! > 0) {
  165. // // tslint:disable-next-line:no-any
  166. // (event as any).percent = (event.loaded / event.total!) * 100;
  167. // }
  168. // item.onProgress!(event, item.file!);
  169. // } else if (event instanceof HttpResponse) {
  170. // item.onSuccess!(event.body, item.file!, event);
  171. // }
  172. // },
  173. // err => {
  174. // item.onError!(err, item.file!);
  175. // }
  176. // );
  177. // };
  178. getBase64(file: any): Promise<any> {
  179. return new Promise((resolve, reject) => {
  180. const reader = new FileReader();
  181. reader.readAsDataURL(file);
  182. reader.onload = () => resolve(reader.result);
  183. reader.onerror = error => reject(error);
  184. });
  185. }
  186. // 临时上传图片
  187. temporarilyUrl = this.mainService.returnUploadUrl('temporarily', 0);
  188. }