import {Component} from '@angular/core';
import {IonicPage, LoadingController, ModalController, NavController, NavParams} from 'ionic-angular';
import {HomeService} from "../home.service";
import {SearchPersonComponent} from "../../../components/search-person/search-person";
import {DealDetailPage} from "../../deal/deal-detail/deal-detail";
import {CommonService} from "../../../core/common.service";
import {GlobalData} from "../../../core/GlobleData";
import {DealService} from "../../deal/deal.service";
import {DatePipe} from "@angular/common";

@Component({
    selector: 'page-do-supervise',
    templateUrl: 'do-supervise.html',
})
export class DoSupervisePage {

    dbList;
    option = {
        type: '1',
        list: [  //默认事业单位
            {name: "事业单位", type: '1'},
            {name: "机关群团", type: '2'},
        ]
    };
    mineInfo;
    time = {
        one: null,
        two: null,
        three: null,
    };

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private loadCtrl: LoadingController,
                private commonSer: CommonService,
                private globle: GlobalData,
                private dealSer: DealService,
                private datePipe: DatePipe,
                private homeSer: HomeService, private ModalCtrl: ModalController) {
        this.mineInfo = this.globle.userObj;
    }

    ionViewDidEnter() {
        this.getList();
    }

    getList() {
        this.time.one = 24 * 60 * 60 * 1000;
        this.time.two = 24 * 60 * 60 * 1000 * 2;
        this.time.three = 24 * 60 * 60 * 1000 * 3;
        const loadCtrl = this.loadCtrl.create();
        loadCtrl.present();
        const data = {
            "page": "1",
            "limit": "10000",
            type: this.option.type,
        };
        this.homeSer.searchDb(data).subscribe(
            (res) => {
                loadCtrl.dismiss();
                res.page.list.object.forEach(e => {
                    e.timeday = Math.abs(new Date(e.timeday).getTime() - Date.now());
                    if (e.timeday < this.time.one) {
                        e.class = "green";
                        e.process = "33%";
                    } else if (this.time.one < e.timeday && e.timeday < this.time.two) {
                        e.class = "yellow";
                        e.process = "66%";
                    } else {
                        e.class = "red";
                        e.process = "100%";
                    }
                })
                this.dbList = res.page.list.object;
            }
        )
    }

    goToDetail(item) {
        item.type = this.option.type;
        this.navCtrl.push(DealDetailPage, {item: item});
    }
}
