import { Component, OnInit, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { Router } from '@angular/router';
import { MyService } from '../my.service';
declare var wx: any;
@Component({
  selector: 'ydlife-my-center-home',
  templateUrl: './my-center-home.component.html',
  styleUrls: ['./my-center-home.component.scss'],
})
export class MyCenterHomeComponent implements OnInit {
  public searchText:string;
  public featureLists = [
    {key:'00',name:'产品库',icon:'productLibary',link:'/product',isOpen:true},
    {key:'01',name:'计划书',icon:'proposals',link:'',isOpen:false},
    {key:'02',name:'我的保单',icon:'policyLists',link:'/salesDetail',isOpen:true},
    {key:'03',name:'续期管理',icon:'renewalManagement',link:'/renewal_reminder',isOpen:true},
    {key:'04',name:'成交客户',icon:'customers',link:'/customer',isOpen:true},
    {key:'05',name:'我的增员',icon:'increaseStaff',link:'/business',isOpen:true},
    {key:'06',name:'银盾学院',icon:'ydCollege',link:'',isOpen:false},
    {key:'07',name:'更多功能',icon:'more',link:'',isOpen:true}
  ]
  public bannerLists = {
    data: [],
    imgHeight: '145px'
  };
  public hotProductLists = [];
  public onlineProductLists = [];
  state = {
    modal1: false,
  };
  onClose(key) {
    this.state[key] = false;
  }

  submit(value) {
    if(value.trim()){
      this.router.navigate(['/product',{queryName:value.trim()}])
    }
  }

  clear(value) {
    this.searchText = '';
  }
  // 点击模块导航
  featureSelect(item){
    if(item.isOpen){
      this.router.navigate([item.link]);
    }else{
      this.state.modal1 = true;
    }
    
  }
  // 获取轮播图
  filePathQuery(){
    this.myService.filePath(6,0,7,null,null).subscribe(res=>{
      if(res['success']){
        this.bannerLists.data = [];
        for(let item of res['data']['fileUploadItemList']){
          this.bannerLists.data.push(item.filePath)
        }
      }
    })
  }
  // 模糊查询产品
  queryproductlistbytag(tagId,dataName){
    this.myService.queryproductlistbytag({mdTagId:tagId}).subscribe(res=>{
      if(res['success']){
        this[dataName] = res['data']['plans']
      }
    })
  }
  constructor(private myService:MyService,private router:Router){}
  ngOnInit(): void {
    this.filePathQuery()
    // 查询互联网产品
    this.queryproductlistbytag(272,'onlineProductLists');
    // 查询热销产品
    this.queryproductlistbytag(119,'hotProductLists');
  }
  
}



