MrShi
6 天以前 bfd70830b78bc42e0a284baa044efacc29897cd5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<template>
    <view class="tabbar-wrapper">
        <view class="custom-tabbar" :style="{ paddingBottom: safeAreaBottom + 'px' }">
            <view class="tabbar-item" v-for="(item, index) in tabList" :key="index" @click="switchTab(item)">
                <image class="tabbar-icon" :src="currentIndex === index ? item.selectedIconPath : item.iconPath" mode="aspectFit"></image>
                <text class="tabbar-text" :class="{ active: currentIndex === index }">{{ item.text }}</text>
            </view>
        </view>
        <view class="tabbar-placeholder" :style="{ height: '100px' }"></view>
    </view>
</template>
 
<script>
    import { mapState } from 'vuex'
    export default {
        name: 'CustomTabbar',
        data() {
            return {
                safeAreaBottom: 0,
                memberTabList: [
                    {
                        text: '首页',
                        pagePath: '/pages/index/index',
                        iconPath: '/static/icon/nav_home@2x.png',
                        selectedIconPath: '/static/icon/nav_home_sel@2x.png'
                    },
                    {
                        text: '行程',
                        pagePath: '/pages/itinerary/itinerary',
                        iconPath: '/static/icon/nav_xingcheng@2x.png',
                        selectedIconPath: '/static/icon/nav_xingcheng_sel@2x.png'
                    },
                    {
                        text: '消息',
                        pagePath: '/pages/message/message',
                        iconPath: '/static/icon/nav_xiaoxi@2x.png',
                        selectedIconPath: '/static/icon/nav_xiaoxi_sel@2x.png'
                    },
                    {
                        text: '我的',
                        pagePath: '/pages/mine/mine',
                        iconPath: '/static/icon/nav_wode@2x.png',
                        selectedIconPath: '/static/icon/nav_wode_sel@2x.png'
                    }
                ],
                shopTabList: [
                    {
                        text: '首页',
                        pagePath: '/shop/pages/store-home/store-home',
                        iconPath: '/static/icon/nav_home@2x.png',
                        selectedIconPath: '/static/icon/nav_home_sel@2x.png'
                    },
                    {
                        text: '钱包',
                        pagePath: '/shop/pages/wallet/wallet',
                        iconPath: '/static/icon/nav_qianbao@2x.png',
                        selectedIconPath: '/static/icon/nav_qianbao_sel@2x.png'
                    },
                    {
                        text: '消息',
                        pagePath: '/shop/pages/message/message',
                        iconPath: '/static/icon/nav_xiaoxi@2x.png',
                        selectedIconPath: '/static/icon/nav_xiaoxi_sel@2x.png'
                    },
                    {
                        text: '我的',
                        pagePath: '/shop/pages/mine/mine',
                        iconPath: '/static/icon/nav_wode@2x.png',
                        selectedIconPath: '/static/icon/nav_wode_sel@2x.png'
                    }
                ]
            }
        },
        computed: {
            ...mapState(['userType']),
            currentIndex() {
                const pages = getCurrentPages()
                const currentPage = pages[pages.length - 1]
                const currentPath = '/' + currentPage.route
                const list = this.tabList
                const index = list.findIndex(item => item.pagePath === currentPath)
                return index > -1 ? index : 0
            },
            tabList() {
                if (this.userType === 1) {
                    return this.shopTabList
                }
                return this.memberTabList
            }
        },
        created() {
            this.getSafeAreaBottom()
        },
        methods: {
            getSafeAreaBottom() {
                const systemInfo = uni.getSystemInfoSync()
                this.safeAreaBottom = systemInfo.safeAreaInsets.bottom || 0
            },
            switchTab(item) {
                const currentPath = getCurrentPages()[getCurrentPages().length - 1].$page.fullPath
                if (this.userType === 1) {
                    if (currentPath !== item.pagePath) {
                        uni.redirectTo({
                            url: item.pagePath
                        })
                    }
                } else {
                    if (currentPath !== item.pagePath) {
                        if(item.pagePath ==='/pages/itinerary/itinerary'){
                            uni.setStorageSync("orderStatus",-1)
                        }
                        uni.switchTab({
                            url: item.pagePath
                        })
                    }
                }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .tabbar-wrapper {
        width: 100%;
    }
    
    .tabbar-placeholder {
        width: 100%;
    }
 
    .custom-tabbar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100rpx;
        background: #ffffff;
        display: flex;
        align-items: center;
        justify-content: space-around;
        box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
        z-index: 999;
    }
 
    .tabbar-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
 
    .tabbar-icon {
        width: 48rpx;
        height: 48rpx;
    }
 
    .tabbar-text {
        font-size: 22rpx;
        color: #999999;
        margin-top: 4rpx;
 
        &.active {
            color: #1ba8fa;
        }
    }
</style>