<template>
	<view class="">
		<u-navbar title="我的" :is-back="false" title-size="34" :title-color="parseInt(identity)>1?'#EAF2FF':'#000'"
			:border-bottom="false"></u-navbar>
		<view v-if="parseInt(identity)==1">
			<view class="info flex-row flex-jus-sp flex-ali-center">
				<view class="flex-row flex-a">
					<image class="avatar" :src="doctorInfo.DoctorInfo.avatar">
					</image>
					<view class="flex-col flex-jus-se m-l-32">
						<view class="flex-row flex-ali-center">
							<d-text :text="doctorInfo.DoctorInfo.name || '微信用户'"
								className="m-r-16 main-c fs-36"></d-text>
							<u-tag text="审核中" type="warning" size="mini" shape="circle" border-color="#6A77CD"
								bgColor="#6A77CD" color="#fff" v-if="doctorInfo.DoctorInfo.user.status==1" />
							<u-tag text="已认证" type="warning" size="mini" shape="circle" border-color="#6A77CD"
								bgColor="#6A77CD" color="#fff" v-if="doctorInfo.DoctorInfo.user.status==2" />
							<u-tag v-if="doctorInfo.DoctorInfo.user.status==3" text="审核未通过" type="warning" size="mini"
								border-color="#A7ABB0" bgColor="#A7ABB0" color="#fff" />
						</view>
						<view class="flex-row" @click="$go('../../subPackages/sub_my/my_setAct')">
							<d-text text="个人主页" color="#6C7380"></d-text> &nbsp;
							<u-icon name="arrow-right" size="24" color="#A7ABB0"></u-icon>
						</view>
					</view>
				</view>
				<view class="button" @click="$go('../../subPackages/sub_pharmacist/pharmacist_info')">
					编辑资料
				</view>
			</view>
			<view class="p-row-2">
				<!-- <view class="p-32 white b-r-16">
					<view class="flex-row" @click="$go('../../subPackages/sub_my/my_revenue/index')">
						<d-text text="我的收入" className="main-c fs-32 m-r-16"></d-text>
						<u-icon :name="eye?'eye':'eye-off'" color="#000" @click="eye=!eye" size="32"></u-icon>
					</view>
					<view class="flex-row m-t-32">
						<view class="flex-1 flex-col">
							<d-text className="tips-c fs-24" text="累计收入（元）"></d-text>
							<d-text className="content-c fs-4" text="0.00" :bold="true"></d-text>
						</view>
						<view class="flex-1 flex-col m-l-24">
							<d-text className="tips-c fs-24" text="本月预估收入（元）"></d-text>
							<d-text className="content-c fs-4" text="0.00" :bold="true"></d-text>
						</view>
					</view>
				</view> -->
				<view class="grid-tem-col-3 m-t-2 white p-col-32">
					<view class="flex-col flex-jus-sp flex-ali-center" v-for="(item,i) in functions"
						@click="$go(item.url)" :key="i">
						<image class="fun" :src="item.icon"></image>
						<d-text color="#31353D" :text="item.name"></d-text>
					</view>
				</view>
				<view class="flex-col m-t-2 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" v-for="(item,i) in items"
						:key="i" @click="$go(item.url)">
						<view class="flex-row flex-ali-center">
							<image class="item" :src="item.icon" mode="aspectFit"></image>
							<d-text :text="item.name" className="content-c m-l-16"></d-text>
						</view>
						<u-icon name="arrow-right" color="#bcbcbc"></u-icon>
					</view>
					<view class="account-switch-wrap">
						<account-switch-entry />
					</view>
				</view>
				<view class="logout-wrap p-row-32 m-t-2">
					<u-button :throttle-time="0" shape="circle"
						:custom-style="{ backgroundColor: '#6ACDBB', color: '#fff', height: '96rpx' }"
						@click="logout">退出登录</u-button>
				</view>
			</view>
		</view>
		<my-pharmacist v-if="parseInt(identity)==2" ref="myPharmacist" :info="userInfo" :avatar="getAvatar"></my-pharmacist>
		<my-service v-if="parseInt(identity)>2" ref="myService" :info="userInfo" :avatar="getAvatar"></my-service>
		<d-tabbar></d-tabbar>
	</view>
</template>

<script>
	import {
		info,
		logout,
		personalData,
		leadInfo,
		servInfo
	} from "@/api/all.js"
	import myPharmacist from './my-pharmacist.vue'
	import myService from './my-service.vue'
	import WxBindEntry from '@/components/wx-bind-entry/wx-bind-entry.vue'
	import AccountSwitchEntry from '@/components/account-switch/account-switch-entry.vue'
	export default {
		components: {
			myService,
			myPharmacist,
			WxBindEntry,
			AccountSwitchEntry,
		},
		data() {
			return {
				userInfo: uni.getStorageSync('userInfo') || {},
				functions: [{
						// 	name: '我的评价 我的常用方',
						// 	icon: '../../static/image/wdpj.png',
						// 	url: '../../subPackages/sub_workbench/workbench_evaluation'
						// }, {
						name: '我的处方',
						icon: '../../static/image/wd-cf.png',
						url: '/subPackages/sub_my/prescriptionList'
					},
					{
						name: '我的常用方',
						icon: '../../static/image/wd-cyf.png',
						url: '../../subPackages/sub_workbench/workbench_recipe/common?type=0'
					},
					// {
					// 	name: '挂号费用',
					// 	icon: '../../static/image/wd-ghfy.png',
					// 	url: '../../subPackages/sub_my/my_revenue/index'
					// },
					{
						name: '服务设置',
						icon: '../../static/image/fwsz.png',
						url: '../../subPackages/sub_my/my_service'
					}
				],
				items: [
					// {
					// 			name: '常用语管理',
					// 			icon: '../../static/image/wj.png',
					// 			url: '../../subPackages/sub_my/my_commonReply/index'
					// 		}, {
					// 			name: '账号设置我的评价',
					// 			icon: '../../static/image/set.png',
					// 			url: '../../subPackages/sub_pharmacist/pharmacist_setInfo'
					// 		},
					// {
					// 	name: '我的评价',
					// 	icon: '../../static/image/wj.png',
					// 	url: '../../subPackages/sub_workbench/workbench_evaluation'
					// },
					{
						name: '常用医嘱管理',
						icon: '../../static/image/i1.png',
						url: '../../subPackages/sub_my/my_diagnose_common'
					}
				],
				eye: false,
				identity: uni.getStorageSync('identity') || (uni.getStorageSync('userInfo') || {}).role || 1,
				userInfo: uni.getStorageSync('userInfo') || {},
				is_req: false,
				doctorInfo: []
			};
		},
		computed: {
			// getAvatar() {
			// 	let doctorInfo = uni.getStorageSync('doctorInfo')
			// 	let url = require(`@/static/image/${doctorInfo.DoctorInfo.user.role%2==0?'nv':'nan'}.png`);
			// 	// console.log(info, 'ddd')
			// 	return doctorInfo.DoctorInfo['avatar'] ? doctorInfo.DoctorInfo['avatar'] : doctorInfo
			// 		.DoctorInfo.user.role == 1 ? url : url
			// }
		},
		created() {
			this.getInfo()
		},
		onHide() {

		},
		onShow() {
			this.getInfo()
			this.refreshWxBind()
		},
		methods: {
			refreshWxBind() {
				if (parseInt(this.identity) === 1 && this.$refs.wxBindEntry) {
					this.$refs.wxBindEntry.refresh()
				}
				if (parseInt(this.identity) === 2 && this.$refs.myPharmacist) {
					this.$refs.myPharmacist.refreshWxBind()
				}
				if (parseInt(this.identity) > 2 && this.$refs.myService) {
					this.$refs.myService.refreshWxBind()
				}
			},
			async getInfo() {
				let res = {}
				this.identity == 1 && (res = await info({
					store_id: uni.getStorageSync('store_id') || '11001'
				}));
				if (res.errcode == 0) {
					this.doctorInfo = res.data
					uni.setStorageSync('userInfo', res.data.DoctorInfo)
				} else if (res.msg) {
					this.$toast(res.msg);
				}
			},
			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);
					}
				})
			}
		},
		mounted() {
			this.getInfo()
		},
	};
</script>
<style>
	page {
		background-color: #F9FAFB;
	}
</style>
<style lang="scss" scoped>
	.info {
		background: linear-gradient(180deg, #EAF2FF 0%, rgba(238, 245, 255, 0) 100%);
		padding: 32rpx 20rpx;

		.button {
			width: 128rpx;
			height: 50rpx;
			border-radius: 198rpx;
			border: 1rpx solid #6ACDBB;
			font-size: 24rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #6ACDBB;
			text-align: center;
			line-height: 50rpx;
		}
	}

	.fun {
		width: 80rpx;
		height: 80rpx;
		margin-bottom: 10rpx;
		vertical-align: middle;
	}

	.item {
		width: 40rpx;
		height: 40rpx;
	}

	.wx-bind-wrap {
		padding: 0 0 0 0;
	}

	.account-switch-wrap {
		border-top: 1rpx solid #f0f1f3;
	}

	.logout-wrap {
		padding-bottom: 32rpx;
	}

	.avatar {
		width: 128rpx;
		height: 128rpx;
		background: #D9D9D9;
		border: 4rpx solid #FFFFFF;
		border-radius: 128rpx;
	}
</style>