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

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

    text: string;
    approvaList = [];
    approvalObj;


    areaObj;
    areaList = [];
    globleArea;

    constructor(private viewCtrl: ViewController, private params: NavParams,
                private globle: GlobalData,
                private storage: Storage,
                private loginSer: LoginService) {
        this.areaObj = this.params.get("areaObj");
        this.approvalObj = this.params.get("approvalObj");
        this.globleArea = this.globle.area;
        this.storage.get('roles').then((value) => {
            if (value.indexOf('8') > -1) {
                this.approvaList.push({name: "事业单位", type: "1"})
            }
            if (value.indexOf('9') > -1) {
                this.approvaList.push({name: "机关群团", type: "2"})
            }
        })

        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);
    }

}
