import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {  Response } from '@angular/http';
import { Storage } from '@ionic/storage';
import { OutGoingReportEditPage } from '../outGoingReportEdit/outGoingReportEdit';
import {AppService} from "../../../../service/appHttpService";

@IonicPage()
@Component({
  selector: 'page-outGoingReport',
  templateUrl: 'outGoingReport.html'
})

export class OutGoingReportPage {

  PremanagerList: Array<String> = [];
  type: number;

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public appService: AppService,
    public storage: Storage
  ) {
    this.type = this.navParams.get("type");
  }

  //刷新
  doRefresh(refresher) {
    setTimeout(() => {
      if (this.type == 1) {
        this.initPremanagerList();
      } else if (this.type == 2) {
        this.initPremanagerListAboutNot();
      }
      refresher.complete();
    }, 2000);
  }

  
  //报备
  goReport(item) {
    this.storage.remove("temp_userpre");
    this.storage.remove("managerId");
    this.storage.remove("city");
    this.storage.remove("cityList");

    this.storage.set('premanager', item);
    this.navCtrl.push('OutGoingReportEditPage');
  }
  //修改报备
  // editReport(item){
  //   this.navCtrl.push('OutGoingReportEditPage');
  // }

  ionViewDidLoad() {
    if (this.type == 1) {
      this.initPremanagerList();
      this.addRecodings();
    } else if (this.type == 2) {
      this.initPremanagerListAboutNot();
    }
  }
  //初始化列表,全部报备
  initPremanagerList(): void {
    this.appService.ObserverHttpGet("/wisdomgroup/modules/premanager/findNeedPremanager", null)
      .subscribe((res: Response) => {
        let data = res.json();
        this.PremanagerList = data;
      }, error => {
      }
      );
  }

  //初始化列表，尚未报备
  initPremanagerListAboutNot(): void {
    this.appService.ObserverHttpGet("/wisdomgroup/modules/premanager/findNeedPremanagerAboutNot", null)
      .subscribe((res: Response) => {
        let data = res.json();
        this.PremanagerList = data;
      }, error => {
      }
      );
  }

   //跳转到报备查看详情页面
   goDetail(report){      
        this.navCtrl.push("OutGoingReportViewPage",{premanager:report});
   }

  goBack(){
    this.navCtrl.popToRoot();
  }

  //增加阅读记录
  addRecodings(){
    this.appService.ObserverHttpGet("/wisdomgroup/modules/premanager/addRecodings", null)
    .subscribe((res: Response) => {
     
    }, error => {
    }
    );
  }
}
