import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {ContactDetailPage} from "../contact-detail/contact-detail";
import * as Mock from "mockjs";
import {HomeService} from "../home.service";
import {GlobalData} from "../../../core/GlobleData";

@Component({
    selector: 'page-contact-list',
    templateUrl: 'contact-list.html',
})
export class ContactListPage {

    role;
    area;
    page = {
        list: [],
        noNumList: [],
        isLoad: false
    };
    roleName;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private globle: GlobalData,
                private homeSer: HomeService) {
        this.role = this.navParams.get('role');
        this.area = this.navParams.get('area');
        this.roleName = this.navParams.get('roleName');
    }

    ionViewDidLoad() {
        this.getPersonList();
    }

    //人员列表
    getPersonList() {
        const data = {
            page: 1,
            limit: 1000,
            areacode: this.area.code,
            role: this.role,
        };
        // debugger
        console.log(` 查看role：   + ${this.role}`)
        this.homeSer.getOrgList(data).subscribe(
            (res) => {
                this.page.list = res.list.user.filter(e => e.orderNum != "" && e.areacode == this.area.code);
                res.list.user.map(x=> x.role == 4 ? x.telPhone = x.telPhone.replace(/^(.*).{4}$/, "$1****") : '')
                this.page.noNumList = res.list.user.filter(e => e.orderNum == "" && e.areacode == this.area.code);
                this.page.list.sort((a, b) => a.orderNum - b.orderNum);
                console.log(this.page.list);
                console.log(this.page.noNumList);
                this.page.isLoad = true;
            }
        )
    }

    //人员详情
    goToInfo(person) {
        this.navCtrl.push(ContactDetailPage, {person: person});
    }

}
