<template>
	<view>
		<home v-show="current == 0" ref="home"></home>
		<recruitment v-show="current == 1" ref="recruitment"></recruitment>
		<my v-show="current == 2" ref="refMy"></my>

		<u-tabbar v-model="current" :safe-area-inset-bottom="true" :list="list" active-color="#2F4379" :before-switch="beforeSwitch"></u-tabbar>
	</view>
</template>

<script>
import home from '@/components/home.vue';
import my from '@/components/my.vue';
import recruitment from '@/components/recruitment.vue';
import { mapGetters } from 'vuex';
export default {
	components: {
		home,
		my,
		recruitment
	},
	data() {
		return {
			list: [
				{
					iconPath: '/static/nav1.png',
					selectedIconPath: '/static/nav1_on.png',
					text: '学习中心',
					customIcon: false
				},
				{
					iconPath: '/static/job@3x.png',
					selectedIconPath: '/static/job@3xactive.png',
					text: '求职',
					customIcon: false
				},
				{
					iconPath: '/static/nav4.png',
					selectedIconPath: '/static/nav4_on.png',
					text: '我的',
					customIcon: false
				}
			],
			current: 0,
			isClick1: false
		};
	},
	onPullDownRefresh(){
	},
	onLoad(option) {
		this.$refs.home.init();
		this.getDict()
	},
	onShow() {
		/* if(this.current === 2 && this.$method.isLogin()){
			this.$refs.refMy.init();
		} */
	},
	onShareAppMessage(res) {
		var self = this;
		return {
			title: '中正',
			path: `/pages/index/index?inviteCode=` + userInfo == null ? '' : userInfo.userAccount
		};
	},
	methods: {
		getDict(){
			let that = this
			this.$api.dictList().then(res => {
				if (res.data.code === 200) {
					let newList = {}
					let list = res.data.data
					for(let i =0 ;i<list.length;i++){
						let item = list[i]
						if(newList.hasOwnProperty(item.dictType)){
							newList[item.dictType].push(item.dictLabel)
						}else{
							newList[item.dictType] = [item.dictLabel]
						}
					}
					that.$store.state.dictObj = newList;
				}
			});
		},
		updateHomePlan() {
			this.$refs.home.init();
		},
		beforeSwitch(index) {
			let that = this;
			if (index == 1) {
				this.isClick1 = true;
			}
			if (index == this.current) {
				return false;
			}
			if (!this.$method.isLogin()) {
				if (index == 0 || index == 1) {
					return true;
				} else {
					this.$navTo.togo('/pages/login/login');
					return false;
				}
			} else {
				if (index == 2) {
					this.$refs.refMy.init();
				}
				return true;
			}
		}
	},
	onReachBottom() {},
	computed: { ...mapGetters(['userInfo']) }
};
</script>

<style scoped></style>
