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

		<div class="mui-content vongi-qqhm vongi-fklist vongi-ylqhsf">
			<ul class="mui-table-view openfyy-list ">
				<li v-for="(item,index) in roleList" class="mui-table-view-cell">
					<a @click="switchRole(item.id)" class="mui-radio">
						<div class="mui-col-xs-10  mui-pull-left flew-items">
							<div class="mui-media-object mui-pull-left "><img src="~$project/assets/img/02.jpg" width="50" /></div>
							<div class="mui-media-body">
								<h1 v-text="item.companyName"></h1>
								<p class='mui-ellipsis mui-h3' v-text="item.personRoleName"></p>
							</div>
						</div>
						<input name="radio1" type="radio" checked>
					</a>
				</li>
			</ul>
		</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 NavMenu from '@/components/NavMenu.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterExchangeRole',
		components: {
			Common,
			Loading,
			TopHeader,
			NavMenu
		},
		data() {
			return {
				isLoading: false,

				roleList: [],

				pageTitle: '切换身份',
			}
		},
		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;

					this.$refs.common.getDataByOpenId();
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},

			asynCallBack() {
				//获取用户角色列表
				this.getRoleList();

			},
		},
		mounted() {},
		destroyed() {

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

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