import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Params} from "@angular/router";
import {MerService} from "../../../services/mer.service";
import {environment} from "../../../../environments/environment";
import {NzBreadCrumbComponent, NzBreadCrumbItemComponent} from "ng-zorro-antd/breadcrumb";
import {NzTabComponent, NzTabSetComponent} from "ng-zorro-antd/tabs";
import {NzDescriptionsComponent, NzDescriptionsItemComponent} from "ng-zorro-antd/descriptions";
import {MerTypePipe} from "../../../pipes/mer/mer-type.pipe";
import {DatePipe, NgIf, NgStyle} from "@angular/common";
import {MerStatusPipe} from "../../../pipes/mer/mer-status.pipe";
import {NzModalComponent, NzModalModule} from "ng-zorro-antd/modal";

@Component({
  selector: 'app-mer-detail',
  standalone: true,
  imports: [
    NzBreadCrumbComponent,
    NzBreadCrumbItemComponent,
    NzTabSetComponent,
    NzTabComponent,
    NzDescriptionsComponent,
    NzDescriptionsItemComponent,
    MerTypePipe,
    DatePipe,
    MerStatusPipe,
    NgIf,
    NzModalComponent,
    NgStyle,
    NzModalModule
  ],
  templateUrl: './mer-detail.component.html',
  styleUrl: './mer-detail.component.less'
})
export class MerDetailComponent implements OnInit {

  previewVisible = false;
  previewImage;

  OBS_URL;
  dataObject = {
    merRegion: {},
    merIndustry: {},
    merContractFailMsg: {},
    merSettleAcct: {},
  };

  constructor(
    private activatedRoute: ActivatedRoute,
    private merService: MerService
  ) {
    this.OBS_URL =  environment.obsUrl;
  }

  ngOnInit(): void {
    this.activatedRoute.queryParams.subscribe((queryParams: Params) => {
      if (queryParams['merId'] != null && queryParams['merId'].length > 0) {
        this.merService.getMerDetail(queryParams['merId'], data => {
          if (data['return_code'] === '000000') {
            this.dataObject = data['return_data'];
            console.log(this.dataObject);
          }
        });
      }
    });
  }

  // 展示图片展示
  showPreview(url: string) {
    this.previewImage = url;
    this.previewVisible = true;
  }

  // 关闭图片展示
  closePreview() {
    this.previewImage = '';
    this.previewVisible = false;
  }
}
