<template>
	<div>
		<common ref="common" @asynCallBack="asynCallBack" :projectCheck="false"></common>
		<top-header :pageTitle="pageTitle" :leftShow="false"></top-header>

		<div class="mui-content margin60">
			<div class="vongi-choose mui-content-padded">
				<h5>经过比对，您可以使用下列身份登录: </h5>
				<ul class="mui-table-view  mui-table-view-radio vongi-pipei">
					<li v-for="(item,index) in roleList" :class="'mui-table-view-cell '+(person_popedom.id==item.id?'mui-selected':'')">
						<a @click="switchRole(item.id)">
							<div class="mui-pull-left mui-col-xs-2">
								<div class="mui-media-object">
									<img :src="item.faceImagUrl">
								</div>
								<p class='mui-ellipsis' v-text="item.personRoleName"></p>
								<span v-if="item.unreadMessageNum>0" class="mui-badge mui-badge-danger" v-text="item.unreadMessageNum"></span>
							</div>
							<div class="mui-media-body mui-col-xs-10">
								{{item.sceneName}}
								<p class='mui-ellipsis' v-text="item.companyName"></p>
							</div>
						</a>
					</li>
				</ul>
			</div>
		</div>

		<loading :visible="isLoading"></loading>
	</div>
</template>

<script>
	import * as API_User from '$project/apis/user'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'UserRole',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '匹配身份',
				isLoading: false,

				roleList: []
			}
		},
		created() {},
		methods: {
			//获取用户角色列表
			getRoleList() {
				this.isLoading = true;
				API_User.getRoleList().then(response => {
					this.isLoading = false;

					this.roleList = response.list;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//切换角色
			switchRole(id) {
				this.isLoading = true;
				API_User.exchangePopedom({
					id: id
				}).then(response => {
					this.isLoading = false;

					//跳转到项目主页上去
					window.location.href = '../' + this.$route.query.project + '/#/master';
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			asynCallBack() {

			},
		},
		mounted() {
			//获取用户角色列表
			this.getRoleList();
		},
		destroyed() {

		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		}
	}
</script>

<style src="$project/assets/css/iconfont.css"></style>
<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style scoped>
</style>
