<template>
	<view class="content">
		<view class="inner">
			<view v-for="(item,index) in docs" :key="index" class="item" @click="showDetail(item)">
				<view class="user-info">
					<view class="user-top">
						<view class="user-left">
							<image :src="maleurl" class="w112 h112"></image>
							<view class="ml32">
								<view class="name">{{item.userName}}</view>
								<view class="age-box"  :style="{'background-color':item.sex==1?'#EBF8FF':'#FCF0E7'}">
									<u-icon :color="item.sex==1?'#008FD3':'#FF5030'" :name="item.sex==1?'man':'woman'"></u-icon>
									<view class="age">{{utils.getAge(item.birthday)}}岁</view>
								</view>
							</view>
							
						</view>
						<view class="user-phone">{{utils.parsePhone(item.phone)}}</view>
					</view>
					<view class="user-bottom">
						<view class="btn" @click="navgetTo('/pages_health/buyOrder?type=add')">购买信息</view>
						<view class="btn" @click="navgetTo('/pages_health/addUser?type=add')">基本信息</view>
						<view class="btn" @click="navgetTo('/pages_health/addDoc?type=add')">健康档案</view>
					</view>
				</view>
			</view>
			<view v-if="docs.length == 0" class="no-data-box" @click="getMyDocList()">
				<image src="../../static/images/no_data.png" mode="aspectFit"></image>
				<view class="empty-title">暂无数据</view>
			</view>
		</view>
		<view class="btn-box">
			<view class="sub-btn" @click="addDoc">
				<image src="/static/images/health/nav_add_icon24.png" class="w48 h48"></image>
				<text>创建用户信息</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {getMyDocList,delDoc} from '@/api/doc.js'
	export default {
		data() {
			return {
				famaleurl:"/static/images/health/female_profile.png",
				maleurl:"/static/images/health/my_heads.png",
				docs:[
					{userName:'西航宇',sex:1,birthday:'1990-01-01',phone:'16666666666'},
					{userName:'蓝西',sex:2,birthday:'1990-06-01',phone:'1888888888'},
					{userName:'西航宇',sex:1,birthday:'1993-01-01',phone:'16666666666'},
					{userName:'蓝西',sex:2,birthday:'1994-06-01',phone:'1888888888'},
					{userName:'蓝西',sex:2,birthday:'1994-06-01',phone:'1888888888'}
				],
			}
		},
		onLoad() {
			// this.getMyDocList()
			// uni.$on('refreshDoc', () => {
			// 	this.getMyDocList()
			// })
		},
		methods: {
			navgetTo(url){
				uni.navigateTo({
					url: url
				})
			},
			showDetail(item){
				uni.navigateTo({
					url: './docDetail?docId='+item.docId
				})
			},
			editDoc(item){
				uni.navigateTo({
					url: './addDoc?type=edit&docId='+item.docId
				})
			},
			delDoc(item){
				uni.showModal({
					title:"提示",
					content:"确认删除吗?",
					showCancel:true,
					cancelText:'取消',
					confirmText:'确定',
					success:res=>{
						if(res.confirm){
							// 用户点击确定
							var data={docId:item.docId}
							delDoc(data).then(
								res => {
									if(res.code==200){
										 uni.showToast({
										 	icon:'success',
										 	title: "操作成功",
										 });
										 this.getMyDocList()
									}else{
										uni.showToast({
											icon:'none',
											title: "请求失败",
										});
									}
								},
								rej => {}
							);
														
						}else{
							// 否则点击了取消  
						}
					}
				})
			},
			getMyDocList(){
				uni.showLoading({
					title:"正在加载中"
				})
				getMyDocList().then(
					res => {
						uni.hideLoading()
						if(res.code==200){
							this.docs=res.data;
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			addDoc() {
				uni.navigateTo({
					url: '/pages_health/addUser?type=add'
				})
			}
			 
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.content{
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.inner{
			flex: 1;
			padding: 20upx 20upx 160upx;
			.item{
				background: #FFFFFF;
				border-radius: 20upx;
				margin-bottom: 20upx;
				// padding: 40upx 30upx;
				padding: 32rpx;
				&:last-child{
					margin-bottom: 0;
				}
				.user-info{
					.user-top{
						display: flex;
						align-items: flex-start;
						justify-content: space-between;
						border-bottom: 1px solid #ECECEC;
						padding-bottom: 40rpx;
						.user-left{
							display: flex;
							align-items: center;
							justify-content: flex-start;
							.name{
								font-family: PingFang SC;
								font-weight: 500;
								font-size: 36rpx;
								color: #222426;
								text-align: left;
							}
							.age-box{
								display: flex;
								align-items: center;
								justify-content: center;
								border-radius: 24rpx 24rpx 24rpx 24rpx;
								margin-top: 16rpx;
								width: 114rpx;
								    height: 40rpx;
								.age{
									font-weight: 400;
									font-size: 22rpx;
									color: #626468;
									line-height: 22rpx;
									text-align: left;
								}
							}
							
						}
						.user-phone{
							font-family: PingFang SC;
							font-weight: 500;
							font-size: 28rpx;
							color: #222426;
							text-align: right;
						}
					}
					.user-bottom{
						display: flex;
						align-items: center;
						justify-content: flex-end;
						padding-top: 20rpx;
						.btn{
							width: 176rpx;
							height: 60rpx;
							border-radius: 30rpx 30rpx 30rpx 30rpx;
							border: 1rpx solid #B2B2B2;
							font-size: 24rpx;
							color: #222426;
							line-height: 60rpx;
							text-align: center;
							margin-left:16rpx ;
							&:last-child{
								border: 1rpx solid #008FD3;
								color: #008FD3;
							}
						}
						
					}
					.gray-tag{
						height: 46upx;
						line-height: 46upx;
						padding: 0 16upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #333333;
						background: #F7F7F7;
						border-radius: 8upx;
						margin-right: 10upx;
					}
					.blue-tag{
						height: 46upx;
						line-height: 46upx;
						padding: 0 16upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #4BC9B1;
						background: #E2F6F2;
						border-radius: 8upx;
					}
				}
				.stage-box{
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					margin-top: 34upx;
					.stage{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #111111;
						line-height: 1;
					}
					.stage-text{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						line-height: 1;
					}
				}
				.progress-box{
					margin-top: 18upx;
				}
				.period{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 1;
					margin-top: 40upx;
				}
			}
			 
		}
		.btn-box{
			z-index: 9999;
			width: 100%;
			padding: 30upx;
			position: fixed;
			bottom: 0;
			left: 0;
			box-sizing: border-box;
			// background: #FFFFFF;
			
	 
			.sub-btn{
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #008FD3;
				border-radius: 44upx;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					margin-right: 16rpx;
				}
			}
		}
		 
	}
</style>
