123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- import { Component, OnInit, Input, Output, EventEmitter, ViewChild, OnChanges, SimpleChanges } from '@angular/core';
- import { MainService } from '../../../services/main.service';
- import { Router } from '@angular/router';
- import { ToolService } from 'src/app/services/tool.service';
- import { NzMessageService, UploadFile, UploadXHRArgs } from 'ng-zorro-antd';
- import cloneDeep from 'lodash-es/cloneDeep'
- import { debounceTime } from 'rxjs/operators';
- import { Subject } from 'rxjs';
- import { HttpClient, HttpEvent, HttpResponse, HttpEventType, HttpRequest } from '@angular/common/http';
- @Component({
- selector: 'app-incident-handle-info-simple',
- templateUrl: './incident-handle-info-simple.component.html',
- styleUrls: ['./incident-handle-info-simple.component.less']
- })
- export class IncidentHandleInfoSimpleComponent implements OnInit, OnChanges {
- @Input() incidentData:any = {};
- @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
- @Output() confirmModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
- constructor(
- private mainService: MainService,
- private router: Router,
- public tool: ToolService,
- private message: NzMessageService,
- private http: HttpClient,
- ) { }
- incidentDataCopy:any = {};
- changeInpSubject = new Subject(); //防抖
- ngOnChanges(changes: SimpleChanges){
- console.log('changes:', changes)
- // 初始化
- if(changes.incidentData && !changes.incidentData.firstChange && changes.incidentData.currentValue && changes.incidentData.previousValue && !changes.incidentData.previousValue.id){
- this.init();
- }
- if(changes.incidentData && changes.incidentData.firstChange && changes.incidentData.currentValue && !changes.incidentData.previousValue){
- this.init();
- }
- }
- ngOnInit() {
- //防抖
- this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
- if(v[0] === 'synergetic'){
- this.getSynergeticList(v[1]);
- }else if(v[0] === 'assetId'){
- this.getAssetProductList(v[1]);
- }
- });
- }
- init(){
- console.log('初始化')
- this.hosId = this.tool.getCurrentHospital().id;
- this.incidentDataCopy = cloneDeep(this.incidentData);
- this.incidentDataCopy.synergetic = [];
- this.getHandleCategorys();
- this.getSynergeticList();
- this.getAssetProductList();
- }
- // 边输边搜节流阀
- changeInp(model, e) {
- this.isLoading = true;
- this.changeInpSubject.next([model, e]);
- }
- // 关闭弹窗
- hideModal() {
- this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
- }
- // 获取处理方式列表
- handleCategoryList:any[] = [];
- getHandleCategorys(){
- this.mainService.getDictionary("list", "incident_handle_type").subscribe((data) => {
- this.handleCategoryList = data || [];
- console.log(this.incidentDataCopy)
- if(!this.incidentDataCopy.handleCategory){
- let handleCategory = this.handleCategoryList.find(v => v.value == '1');
- this.incidentDataCopy.handleCategory = handleCategory ? handleCategory.id : undefined;
- }
- });
- }
- // 获取协同人员
- hosId:any;
- isLoading = false;
- synergeticList: any = [];
- getSynergeticList(keyword = '') {
- let postData = {
- user: {
- hospital: { id: this.hosId },
- name: keyword,
- simpleQuery: true,
- roleCodes: 'first-line support',
- engineer: 1,
- },
- idx: 0,
- sum: 20,
- };
- this.mainService
- .getFetchDataList("simple/data", "user", postData)
- .subscribe((data) => {
- this.synergeticList = data.list;
- this.isLoading = false;
- });
- }
- // 获取资产列表
- assetProducList: any = [];
- getAssetProductList(keyword = '') {
- let postData = {
- assetProduct: {
- hosId: this.hosId,
- name: keyword,
- },
- idx: 0,
- sum: 20,
- };
- this.mainService
- .getFetchDataList("simple/data", "assetProduct", postData)
- .subscribe((data) => {
- this.assetProducList = data.list;
- });
- }
- // 图片相关
- showUploadList = {
- showPreviewIcon: true,
- showRemoveIcon: true,
- hidePreviewIconInNonImage: true
- };
- fileList = [
- // {
- // uid: -1,
- // name: 'xxx.png',
- // status: '1',
- // url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
- // }
- ];
- previewImage: string | undefined = '';
- previewVisible = false;
- handlePreview = (file: UploadFile) => {
- console.log('file1:', file)
- this.previewImage = file.url || file.thumbUrl;
- this.previewVisible = true;
- };
- beforeUpload = (file: UploadFile): boolean => {
- console.log('file2:', file)
- this.fileList = [...this.fileList, file];
- setTimeout(async () => {
- file.url = await this.getBase64(file);
- }, 0);
- console.log('this.fileList:', this.fileList)
- return true;
- };
- // customReq = (item: UploadXHRArgs) => {
- // console.log(item);
- // // Create a FormData here to store files and other parameters.
- // const formData = new FormData();
- // // tslint:disable-next-line:no-any
- // formData.append('file', item.file as any);
- // formData.append('filename', item.file.name);
- // const req = new HttpRequest('POST', item.action!, formData, {
- // reportProgress: true,
- // withCredentials: true
- // });
- // // Always returns a `Subscription` object. nz-upload would automatically unsubscribe it at correct time.
- // return this.http.request(req).subscribe(
- // // tslint:disable-next-line no-any
- // (event: HttpEvent<any>) => {
- // if (event.type === HttpEventType.UploadProgress) {
- // if (event.total! > 0) {
- // // tslint:disable-next-line:no-any
- // (event as any).percent = (event.loaded / event.total!) * 100;
- // }
- // item.onProgress!(event, item.file!);
- // } else if (event instanceof HttpResponse) {
- // item.onSuccess!(event.body, item.file!, event);
- // }
- // },
- // err => {
- // item.onError!(err, item.file!);
- // }
- // );
- // };
- getBase64(file: any): Promise<any> {
- return new Promise((resolve, reject) => {
- const reader = new FileReader();
- reader.readAsDataURL(file);
- reader.onload = () => resolve(reader.result);
- reader.onerror = error => reject(error);
- });
- }
- // 临时上传图片
- temporarilyUrl = this.mainService.returnUploadUrl('temporarily', 0);
- }
|