import {Component, ElementRef, Renderer2, ViewChild} from '@angular/core';
import {LoadingController, NavController, Slides} from 'ionic-angular';
import {HomeService} from "./home.service";
import {CommonService} from "../../core/common.service";
import {Storage} from "@ionic/storage";
import {MineService} from "../mine/mine.service";
import {TabService} from "../../core/tab.service";
import {InAppBrowser} from "@ionic-native/in-app-browser";
import {AppService} from "../../app/app.service";
import {StatusBar} from "@ionic-native/status-bar";
import {ContactPage} from "./contact/contact";
import {DoVerityPage} from "./do-verity/do-verity";
import {DoSupervisePage} from "./do-supervise/do-supervise";
import {DataReportPage} from "./data-report/data-report";
import {PersonPage} from "../mine/person/person";
import {GlobalData} from "../../core/GlobleData";
import {DatePipe} from "@angular/common";

@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {

    echartData;
    type = 'teacher';

    info = {
        new: 0,
    };
    yearmonth;

    unitsInfo;
    mineInfo;  //个人信息

    constructor(public navCtrl: NavController, public homeSer: HomeService, private loadCtrl: LoadingController,
                private commonSer: CommonService, private storage: Storage,
                private appSer: AppService, public statusBar: StatusBar,
                private globle: GlobalData,
                private datePipe: DatePipe,
                private mineSer: MineService, private tabSer: TabService, private inAppBrowser: InAppBrowser,
                private renderer: Renderer2) {
        this.mineInfo = this.globle.userObj;
        this.yearmonth = this.datePipe.transform(Date.now(), "yyyy-MM");
    }

    ionViewDidLoad() {
        this.getUnits();
    }

    //单位信息总览
    getUnits() {
        const data = {
            yearmonth: this.yearmonth,
        };
        this.homeSer.units(data).subscribe(
            (res) => {
                if (res) {
                    this.unitsInfo = res.list;
                    const ser = [
                        {name: "单位数", value: this.unitsInfo.hj.unitcount},
                        {name: "编制数", value: this.unitsInfo.hj.bianzhicount},
                        {name: "实有数", value: this.unitsInfo.hj.shiyoucount},
                    ];
                    this.echartData = {
                        grid: {
                            left: "8%",
                            right: "10%",
                            width: "90%",
                            height: "70%",
                            containLabel: true
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'cross',
                                crossStyle: {
                                    color: '#999'
                                }
                            }
                        },
                        legend: {
                            data: ['实际在编人员数', '编制数', '单位数']
                        },
                        xAxis: [
                            {
                                type: 'category',
                                data: ['9月', '10月', '11月'],
                                axisPointer: {
                                    type: 'shadow'
                                }
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value',
                                name: '人数',
                                axisLabel: {
                                    formatter: '{value} 人'
                                }
                            },
                            {
                                type: 'value',
                                name: '单位数',
                                axisLabel: {
                                    formatter: '{value} 个'
                                }
                            }
                        ],
                        series: [
                            {
                                name: '实际在编人员数',
                                type: 'bar',
                                data: [221345, 222456, 232345],
                                color: ['#5baad2']
                            },
                            {
                                name: '编制数',
                                type: 'bar',
                                data: [222345, 233456, 242567],
                                color: ['#6de0d2']
                            },
                            {
                                name: '单位数',
                                type: 'line',
                                yAxisIndex: 1,
                                data: [6271, 7913, 8776],
                                color: ['#feda66']
                            }
                        ]
                    };
                }
            }
        )
    }


    goToContact() {
        this.navCtrl.push(ContactPage);
    }

    //审核审批
    goToVerity() {
        this.navCtrl.push(DoVerityPage);
    }

    //办理督办
    goToSupervise() {
        this.navCtrl.push(DoSupervisePage);
    }

    //数据报表
    goToReport() {
        this.navCtrl.push(DataReportPage);
    }

    goToPersonInfo() {
        this.navCtrl.push(PersonPage)
    }
}
