Skip to content
tabs.ts 3.09 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, Renderer, ElementRef, ViewChild} from '@angular/core';
import {NavParams, NavController, AlertController, Events, Tabs, Platform} from 'ionic-angular';

import {HomePage} from './home/home';
import {MinePage} from './mine/mine';

import {Storage} from '@ionic/storage';
import {AppService, AppGlobal} from '../../service/http.service';
import {BackButtonService} from "../../provide/backButton.service";
import {ServePage} from "./serve/serve";
import {DiscoverPage} from "./discover/discover";
wangqinghua's avatar
wangqinghua committed
import {TabsService} from "./tabs.service";
wangqinghua's avatar
wangqinghua committed
import {KeyPage} from "./key/key";
wangqinghua's avatar
wangqinghua committed
import {CommonService} from "../../provide/common.service";
wangqinghua's avatar
wangqinghua committed
import {AppMainService} from "../../app/app.service";
wangqinghua's avatar
wangqinghua committed

@Component({
    templateUrl: 'tabs.html'
})
export class TabsPage {
    @ViewChild('myTabs') myTabs: Tabs;

    tabRoots: Object[];

    userInfo: any;

    userid: string;

    roleflag: any;
    tabsIndex;
    role: any;

wangqinghua's avatar
wangqinghua committed
    serve = {
wangqinghua's avatar
wangqinghua committed
        root: ServePage,
        tabTitle: '服务',
        tabIconOn: 'custom-serve-on',
        tabIconOff: 'custom-serve-off',
wangqinghua's avatar
wangqinghua committed
        index: 3
wangqinghua's avatar
wangqinghua committed
    };
wangqinghua's avatar
wangqinghua committed
    mine = {
wangqinghua's avatar
wangqinghua committed
        root: MinePage,
        tabTitle: '我的',
        tabIconOn: 'custom-mine-on',
        tabIconOff: 'custom-mine-off',
wangqinghua's avatar
wangqinghua committed
        index: 4
    };
wangqinghua's avatar
wangqinghua committed


wangqinghua's avatar
wangqinghua committed
    constructor(
wangqinghua's avatar
wangqinghua committed
        public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController,
        public storage: Storage, public event: Events, public render: Renderer,
        public tabSer: TabsService, public appService: AppService, private backButtonService: BackButtonService,
wangqinghua's avatar
wangqinghua committed
        public platform: Platform,private commonSer:CommonService,private appMainSer:AppMainService,
wangqinghua's avatar
wangqinghua committed
    ) {
        this.tabRoots = [{
            root: HomePage,
            tabTitle: '首页',
            tabIconOn: 'custom-home-on',
            tabIconOff: 'custom-home-off',
            index: 0
        }, {
            root: DiscoverPage,
            tabTitle: '发现',
            tabIconOn: 'custom-discover-on',
            tabIconOff: 'custom-discover-off',
            index: 1
wangqinghua's avatar
wangqinghua committed
        },];

wangqinghua's avatar
wangqinghua committed
        //判定是否退休人员
wangqinghua's avatar
wangqinghua committed
        this.tabSer.getUserIntegral().subscribe(
            (res) => {
                const mineInfo = res.data;
wangqinghua's avatar
wangqinghua committed
                if (mineInfo.orgName != "退休人员") {
wangqinghua's avatar
wangqinghua committed
                    this.tabRoots.push( this.serve, this.mine);
wangqinghua's avatar
wangqinghua committed
                } else {
wangqinghua's avatar
wangqinghua committed
                    this.tabRoots.push(this.mine);
                }
            }
        );
wangqinghua's avatar
wangqinghua committed

        this.platform.ready().then(() => {
            this.backButtonService.registerBackButtonAction(this.myTabs);
        });
    }

wangqinghua's avatar
wangqinghua committed
    ionViewDidLoad(){
        //3:管理员,0:普通用户,1:内勤人员,2:处室领导,4:值班管理员,5:审核人员,6:耗材管理员
        this.tabSer.getRoles().subscribe(
            (res) => {
                if(res.errcode == 1000){
wangqinghua's avatar
wangqinghua committed
                    this.appMainSer.setRole(res.data);
wangqinghua's avatar
wangqinghua committed
                }else{
                    this.commonSer.toast('获取权限失败');
                }
            }
        )
    }
wangqinghua's avatar
wangqinghua committed

    onChange(e) {
        this.tabsIndex = e;
        this.myTabs.select(e);
    }
}