import {Component} from '@angular/core';
import {NavParams, ViewController} from "ionic-angular";
import {LoginService} from "../../pages/login/login.service";
import {GlobalData} from "../../core/GlobleData";

@Component({
    selector: 'filter',
    templateUrl: 'filter.html'
})
export class FilterComponent {

    text: string;
    approvaList = [
        {name: "事业单位", type: "1"},
        {name: "机关群团", type: "2"},
        {name: "其他", type: "3"},
    ];
    approvalObj;


    areaObj;
    areaList = [];
    globleArea;

    constructor(private viewCtrl: ViewController, private params: NavParams,
                private globle: GlobalData,
                private loginSer: LoginService) {
        this.areaObj = this.params.get("areaObj");
        this.approvalObj = this.params.get("approvalObj");
        this.globleArea = this.globle.area;
        this.getArea()
    }

    //获取区属
    getArea() {
        const data = {};
        this.loginSer.getArea(data).subscribe(
            (res) => {
                if (res.list) {
                    this.areaList = res.list;
                }
            }
        )
    }

    selectApproval(approval) {
        this.approvalObj = approval;
    }

    //区域选择
    selectArea(area) {
        this.areaObj = area;
    }

    //重置
    reset() {
        this.approvalObj = null;
        this.areaObj = null;
    }

    //确定
    confirm() {
        const data = {
            approval: this.approvalObj,
            area: this.areaObj
        };
        this.viewCtrl.dismiss(data);
    }

}
