import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { AppEnvironment } from 'src/environments/AppEnvironment';

@Component({
  selector: 'app-image-list',
  templateUrl: './app-image-list.component.html',
  styleUrls: ['./app-image-list.component.scss'],
})
export class AppImageListComponent implements OnInit {

  public $items: any[] = [];

  @Input() public title:string;

  /**
  * 基础路径
  */
  url: String = AppEnvironment.BaseUrl + AppEnvironment.ExportFile +"/";

  @Input()
  set items(val: any[]) {
      if (val && val instanceof Array) {
          if (!Object.is(JSON.stringify(this.$items), JSON.stringify(val))) {
              this.$items = val;
              if(this.$items.length >0){
                this.$items.forEach((item:any) =>{
                  item.image =JSON.parse(item.image);
                })
              }
          }
      }
  }

  @Output()
  itemClick: EventEmitter<any> = new EventEmitter();

  constructor() { }

  ngOnInit() {}

  public onClick(item: any): void {
    this.itemClick.emit(item);
}

}
