<template>
	<view class="container">
		<!-- 首页 -->
		<Home v-if="show === 'home'" />
		<!-- 工单管理 -->
		<Management v-if="show === 'management'" />
		<!-- 通讯录 -->
		<AddressBook v-if="show === 'addressBook'" />
		<!-- 待处理池 -->
		<Pending v-if="show === 'pending'" />
		<!-- 报修 -->
		<Repairs v-if="show === 'repairs'" />
		<!-- 我的报修 -->
		<MyRepairs v-if="show === 'myRepairs'" />
		<!-- 底部导航栏 -->
		<Tabbar :list="routes" @changeRouter="handleChangeRouter" />
	</view>
</template>

<script>
import Home from '../home/home.vue'
import Management from '../management/management.vue'
import AddressBook from '../addressBook/addressBook.vue'
import Pending from '../pending/pending.vue'
import Repairs from '../repairs/repairs.vue'
import MyRepairs from '../myRepairs/myRepairs.vue'
import Tabbar from '../components/tabbar.vue'

export default {
	components: {
		Home,
		Management,
		AddressBook,
		Pending,
		Repairs,
		MyRepairs,
		Tabbar
	},
	mounted() {
		const repairsUserInfo = uni.getStorageSync('repairsUserInfo')
		console.log(repairsUserInfo)
		if (repairsUserInfo.routes) {
			this.routes = this.filterRoute(this.list, repairsUserInfo.routes)
		}
		this.show = this.routes[0].show
		uni.setNavigationBarTitle({
			title: this.routes[0].text
		})
	},
	data() {
		return {
			routes: [],
			list: [
				{
					text: '报修',
					imgUrl: '../../static/images/repairsImg/repairs.png',
					imgUrlActive: '../../static/images/repairsImg/repairs-active.png',
					show: 'repairs'
				},
				{
					text: '我的报修',
					imgUrl: '../../static/images/repairsImg/myRepairs.png',
					imgUrlActive: '../../static/images/repairsImg/myRepairs-active.png',
					show: 'myRepairs'
				},
				{
					text: '首页',
					imgUrl: '../../static/images/repairsImg/home.png',
					imgUrlActive: '../../static/images/repairsImg/home-active.png',
					show: 'home'
				},
				{
					text: '工单管理',
					imgUrl: '../../static/images/repairsImg/management.png',
					imgUrlActive: '../../static/images/repairsImg/management-active.png',
					show: 'management'
				},
				{
					text: '待处理池',
					imgUrl: '../../static/images/repairsImg/myRepairs.png',
					imgUrlActive: '../../static/images/repairsImg/myRepairs-active.png',
					show: 'pending'
				},
				{
					text: '通讯录',
					imgUrl: '../../static/images/repairsImg/addressBook.png',
					imgUrlActive: '../../static/images/repairsImg/addressBook-active.png',
					show: 'addressBook'
				}
			],
			show: ''
		}
	},
	methods: {
		handleChangeRouter(show, text) {
			this.show = show
			uni.setNavigationBarTitle({
				title: text
			})
		},
		filterRoute(arr1, arr2) {
			return arr1.filter((item) => {
				return arr2.includes(item.text)
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	width: 100vw;
	height: calc(100vh - 102rpx);
}
</style>
