<template>
	<view class="index-wrap">
		<view class="nav">
				<text>患者列表</text>
				<view class="handle">
					<view class="handle-item">
						<text class="zhcx-iconfont zhcx-icon-xindiantu" @click="handleRight(1)"></text>
					</view>
					<view class="handle-item">
						<text class="zhcx-iconfont zhcx-icon-xiaoxi" @click="handleRight(2)"></text>
					</view>
				</view>
		</view>		
		<fc-contacts :contacts="contacts" @click="showDetail"></fc-contacts>
	</view>
</template>

<script>
	import {getUserListApi} from '@/api/patient';
	import pinYinConvert from '@/libs/pinyin';
	export default {
		data() {
			return {
				contacts:[]
			}
		},
		created() {
			this.init();
		},
		onReady() {
			//this.setTabBar();
		},
		methods: {
			init(){
				this.getUserList();
			},
			setTabBar(){
				//如果用户是患者修改tab
				let accountInfo=uni.getStorageSync('accountInfo');
				if(!accountInfo){return};
				accountInfo=JSON.parse(accountInfo);
				let isPatient=accountInfo.userType===2;
				if(isPatient){
					uni.setTabBarItem({
					  index: 0,
					  text: '医生',
					  iconPath: '/static/tabBar/doctor.png',
					  selectedIconPath: '/static/tabBar/doctorEd.png'
					})			
				}				
			},
			getUserList(){
				getUserListApi({
					limit:999,
					page:1
				}).then((res)=>{
					let userList=res.data.records;
					userList=userList.map((item)=>{
						let pinyinName=pinYinConvert.chineseToPinYin(item.name)
						let NameK=pinYinConvert.ucfirst(pinyinName);
						item.NameK=NameK
						return item;
					})
					this.contacts=userList;
				})
			},
			showDetail(item){
				let info=JSON.parse(JSON.stringify(item));
				uni.setStorageSync('patientInfo',info)
				uni.navigateTo({
					url:'/pages/index/detail/detail'
				})
			},
			handleRight(type){
				if(type===2){
					uni.navigateTo({
						url:"/pages/session/list/list"
					})				
				}else{
					uni.navigateTo({
						url:"/pages/ECG/webView/webView"
					})					
				}
			}
		}
	}
</script>

<style lang="scss">
.nav{
	padding-top: 40upx;
	background-color: #fff;
	text-align: center;
	position: relative;
	height: 40px;
	line-height: 40px;
	font-size: 34upx;
	font-weight: 600;
	color: #000;
	.handle{
		position: absolute;
		right:0;
		top: 30upx;
		bottom: 0;
		display: flex;
		justify-content:flex-end;
		.handle-item{
			padding:0  20upx;
			display: flex;
			align-items: center;
			cursor: pointer;
			font-size: 100upx;
			[class*='xindiantu']{
				color: #007AFF;
				font-size: 50upx;
				transform: rotate(-45deg);
			}
		}
	}
}
</style>
