zhouhao
2021-04-16 00e69f25a8c153238cc5cbea66b8b296b375348b
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!--
 * @Author: 小明丶
 * @Date: 2019-08-19 09:30:14
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-11-17 10:02:59
 * @Description: 切换身份页面
 -->
<template>
    <div class="identity-box">
        <v-navbar :title="$route.query.title" fixed></v-navbar>
        <section class="role-box" v-for="(item, index) in roleList" :key="index">
            <van-radio-group v-if="item.arr.length"  v-model="roleId">
                <h4 class="title">{{item.title}}</h4>
                <div class="flex-between-g role-item" v-for="(role, k) in item.arr" :key="k">
                    <div class="left">
                        <p class="flex-start-g">
                            <svg class="icon" aria-hidden="true" style="width:15px;height:15px;">
                                <use xlink:href="#iconyonghu"></use>
                            </svg>
                            <span class="name">{{role.orgName}}</span>
                        </p>
                        <p class="flex-start-g">
                            <svg class="icon" aria-hidden="true"  style="width:15px;height:15px;">
                                <use xlink:href="#iconshijian"></use>
                            </svg>
                            <time class='time'>创建时间:{{role.creTime | timeformat('yyyy-MM-dd HH:mm:ss')}}</time>
                        </p>
                    </div>
                    <div @click="setRole(role)" v-if="role.status == 1 && role.supStatus == 1" >
                        <van-radio :name="role.id" :checked-color="$store.state.backColor"  />
                    </div>
                </div>
            </van-radio-group>
        </section>
        <van-button class="btn-login" :color="$store.state.backColor" @click="getRoleInfo">登录</van-button>
    </div>
</template>
 
<script>
import { mapActions, mapState } from 'vuex';
    export default {
        data() {
            return {
                roleList: [],//角色列表
                roleId: '',//radio的value
                role:null //当前选中的角色
            }
        },
        computed:{
            ...mapState(['userinfo'])
        },
        created() {
            this.roleId = this.userinfo.id;
            if(sessionStorage.isLoginByOpenId == 1){
                this.roleList = [{
                    title:'门店',
                    arr:JSON.parse(localStorage.storeList) 
                }]
            }else{
                this.getRole();
            }
            
        },
        methods: {
            ...mapActions(['setUserMenu']),
            // 设置当前选中的角色
            setRole(role){
                this.role = role;
            },
            // 获取角色
            getRole() {
                this.$api.getRole().then((res) => {
                    let {
                        agencyList,
                        chanList,
                        merchantList,
                        storeList
                    } = res.body;
                    this.roleList.push({
                        title:'代理',
                        arr:agencyList || []
                    });
                    this.roleList.push({
                        title:'渠道',
                        arr:chanList || []
                    });
                    this.roleList.push({
                        title:'商户',
                        arr:merchantList || []
                    });
                    this.roleList.push({
                        title:'门店',
                        arr:storeList || []
                    });
 
                }).catch((err) => {
 
                });
            },
            // 获取用户信息
            getRoleInfo(){
                if(!this.roleId){
                     this.$notify('请选择登录角色');
                    return
                }
                this.setUserMenu({
                    vm:this,
                    lastLoginMgrId:this.roleId,
                })
                // this.$api.getPowerInfo(this.roleId).then((res) => {
 
                // }).catch((err) => {
 
                // });
            }
        },
    }
</script>
 
<style lang="less" scoped>
    .identity-box {
        background-color: @c-bg-f5;
        min-height: 100%;
        padding-top: 44px;
        padding-bottom: 30px;
    }
 
    .role-box {
        .title {
            .lh(30px);
            margin-left: 20px;
            margin-top: 15px;
            color: @c-text-999;
            font-size: @font-14;
        }
 
        .role-item {
            padding: 0 12px;
            background-color: @c-bg-fff;
            margin: 0 8px 1px;
            border-radius: 3px;
        }
 
        .left {
            height: 75px;
            .flex(center, flex-start, wrap, column);
 
            p:first-child {
                margin-bottom: 10px;
            }
 
            .icon {
                margin-right: 8px;
            }
        }
 
        .name {
            font-size: @font-16;
            font-weight: bold;
        }
 
        .time {
            font-size: @font-12;
            color: @c-text-999;
        }
 
        .circle {
            height: 18px;
            width: 18px;
            margin-right: 2px;
            border-radius: 50%;
            background-color: #fff;
            border: 2px solid @c-default;
        }
    }
 
    .btn-login {
        display: block;
        .lh(44px);
        width: 320px;
        margin: 25px auto 0;
        background-color: @c-bg-default;
        color: @c-text-fff;
        border-radius: 22px;
    }
</style>