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";

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

    dbList;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private loadCtrl:LoadingController,
                private commonSer:CommonService,
                private homeSer: HomeService, private ModalCtrl: ModalController) {
    }

    ionViewDidLoad() {
        this.getList();
    }

    getList() {
        const loadCtrl = this.loadCtrl.create();
        loadCtrl.present();
        const data = {
            page:1,
            limit:10,
        };
        this.homeSer.searchDb(data).subscribe(
            (res) => {
                loadCtrl.dismiss();
                this.dbList = res.page.list.object;
            }
        )
    }

    handleClick(item) {
        let modal = this.ModalCtrl.create(SearchPersonComponent, {
            enterAnimation: 'modal-scale-enter',
            leaveAnimation: 'modal-scale-leave'
        });
        modal.onDidDismiss(res => {
            if (res) {
                this.handleSend(res,item);
            }
        });
        modal.present();
    }

    //发送信息
    handleSend(res,item){
        const data = {
            "dbuserid":res.id,
            "scheduleid":item.id,
            "node":"",
            "content":"",
            "status":"",
            "type":""
        };
        this.homeSer.dbSuper(data).subscribe(
            (res)=>{
                this.commonSer.toast('督办成功');
            }
        )
    }

    goToDetail(item) {
        this.navCtrl.push(DealDetailPage, {item: item, type: "db"});
    }
}
