<template>
	<view class="">
		<view class="p-2">
			<view class="p-32 white">
				<view class="flex-row">
					<u-image width="96rpx" height="96rpx" shape="circle" :src="avatar">
						<u-loading slot="loading"></u-loading>
					</u-image>
					<view class="flex-col flex-jus-sp m-l-32">
						<d-text :text="info.name" :bold="true"></d-text>
						<d-text :text="info.idcard.replace(/\d{4}$/, '****')"   >
						</d-text>
					</view>
				</view>
				<view class="organization m-t-32">
					<d-text text="执业机构" color="#31353D" :bold="true"></d-text>
					<d-text className="content-c m-t08" :text="`${info.idcard.replace(/^\d{2}/, '**')} （${info.yardes[0].name}）`">
					</d-text>
				</view>
			</view>
			<!-- 菜单卡：绑定微信 / 个人资料 / 设置 / 切换账号（对齐医生「我的」） -->
			<view class="flex-col m-t-12 white p-row-32">
				<view class="wx-bind-wrap">
					<wx-bind-entry ref="wxBindEntry" />
				</view>
				<view class="flex-row bottom-border flex-jus-sp p-col-32 flex-ali-center"
					@click="$go('../../subPackages/sub_pharmacist/pharmacist_info?avatar='+avatar+'&info='+JSON.stringify(info))">
					<view class="flex-row flex-ali-center">
						<u-icon margin-left="20" label-size="32" label-color="#31353D"
							:name="require('../../static/image/grzl.png')" label="个人资料" size="30"></u-icon>
					</view>
					<u-icon name="arrow-right" size="32" color="#A7ABB0"></u-icon>
				</view>
				<view class="flex-row bottom-border flex-jus-sp p-col-32 flex-ali-center"
					@click="$go('../../subPackages/sub_pharmacist/pharmacist_setInfo')">
					<view class="flex-row flex-ali-center">
						<u-icon margin-left="20" label-size="32" label-color="#31353D"
							:name="require('../../static/image/set.png')" label="设置" size="30"></u-icon>
					</view>
					<u-icon name="arrow-right" size="32" color="#A7ABB0"></u-icon>
				</view>
				<view class="account-switch-wrap">
					<account-switch-entry />
				</view>
			</view>
			<!-- 独立绿色退出按钮，不再藏在二级设置页 -->
			<view class="logout-wrap p-row-32 m-t-12">
				<u-button :throttle-time="0" shape="circle"
					:custom-style="{ backgroundColor: '#6ACDBB', color: '#fff', height: '96rpx' }"
					@click="logout">退出登录</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	/**
	 * 药师「我的」：资料 + 绑定微信 + 切换账号 + 退出登录（对齐医生主页结构）
	 */
	import { logout } from '@/api/all.js'
	import WxBindEntry from '@/components/wx-bind-entry/wx-bind-entry.vue'
	import AccountSwitchEntry from '@/components/account-switch/account-switch-entry.vue'
	export default {
		components: { WxBindEntry, AccountSwitchEntry },
		props:{
			avatar:{
				type:String,
				default:''
			},
			info:{
				type:Object,
				default:()=>{
					return {}
				}
			}
		},
		data() {
			return {};
		},
		mounted() {
			this.refreshWxBind()
		},
		methods: {
			refreshWxBind() {
				if (this.$refs.wxBindEntry) {
					this.$refs.wxBindEntry.refresh()
				}
			},
			/** 退出登录：清本地会话并回登录页 */
			logout() {
				logout({ store_id: uni.getStorageSync('store_id') || 11001 }).then((res) => {
					if (res.errcode != -1) {
						uni.clearStorage()
						uni.clearStorageSync()
						this.$go('/pages/login/index', 2)
					} else {
						this.$toast(res.msg);
					}
				})
			},
		}
	};
</script>
<style>
	page {
		background-color: #F9FAFB;
	}
</style>
<style lang="scss" scoped>
	.organization {
		background-color: #F9FAFB;
		padding: 16rpx;
	}
	.wx-bind-wrap {
		border-bottom: 1rpx solid #f0f0f0;
	}
	.account-switch-wrap {
		padding-top: 8rpx;
	}
	.logout-wrap {
		margin-bottom: 32rpx;
	}
</style>
