import {Component} from '@angular/core';
import {IonicPage, ModalController, NavController, NavParams} from 'ionic-angular';
import {HomeService} from "../../home.service";
import {YearReportPage} from "../year-report/year-report";
import {DatePipe} from "@angular/common";
import {Detail3Page} from "../../../deal/detail3/detail3";
import {PersonInfoPage} from "../person-info/person-info";


@Component({
    selector: 'page-info-detail',
    templateUrl: 'info-detail.html',
})
export class InfoDetailPage {

    type = 1;
    infoObj;
    nowDate;

    personInfo;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private datePipe: DatePipe,
                private modalCtrl: ModalController,
                private homeSer: HomeService) {
        this.infoObj = this.navParams.get('obj');
        this.type = this.navParams.get('type');
        this.nowDate = this.datePipe.transform(Date.now(), 'yyyy年MM月');
    }

    ionViewDidLoad() {
        if(this.type == 1 || this.type == 0){
            this.getPersonInfo();
        }
    }

    goToYearReport(item) {
        if (item.is_public == '0') {
            return;
        }
        this.navCtrl.push(YearReportPage, {ndbg_id: item.ndbg_id, unit_id: this.infoObj.unit_id});
    }

    getPersonInfo() {
        const data = {
            unit_id: this.infoObj.unit_id
        }
        this.homeSer.statisticPerson(data).subscribe(
            (res) => {
                this.personInfo = res;
            }
        )
    }

    openDetail(title) {
        let modalCtrl = this.modalCtrl.create(PersonInfoPage, {item: this.personInfo, title: title}, {
            enterAnimation: 'modal-from-right-enter',
            leaveAnimation: 'modal-from-right-leave'
        });
        modalCtrl.present();
    }
}
