<template>
	<view class="calendarExpert">
		<u-toast ref="uToast" />
		<view class="con" style="padding: 0;overflow: hidden;">
		<u-tabs :list="list" :is-scroll="false" font-size="32" :show-bar="false" height="120" inactive-color="rgba(0,0,0,0.6)" active-color="rgba(0,0,0,0.8)" :current="current" @change="change"></u-tabs>
		</view>
		<view class="con" v-if="patientListZjArr.length==0">
			<image class="no" src="../../static/img/no.png" mode=""></image>
			<view class="text">列表内容为空</view>
		</view>
		<view class="list" v-else>
			<view class="li" v-for="(item,index) in patientListZjArr" :key="index" @click="patientListZjMet(item)">
				<view class="flex one">
					<view class="type">{{item.title}}</view>
					<view class="name">{{item.name}}</view>
					<view class="status" v-if="item.type==0">未审核</view>
					<view class="status status1" v-else-if="item.type==2">通过</view>
					<view class="status status2" v-else>不通过</view>
				</view>
				<view class="flex address">
					<view>{{item.city}}</view>
					<view>{{item.hospital}}</view>
				</view>
				<view class="flex" style="justify-content: space-between;">
					<view class="class" >
						<view class="box">{{item.uploadingName}}</view><view class="box">{{item.caseName}}</view>
					</view>
				</view>
			</view>
		</view>
		<tabBar :pagePath="'/pages/index/calendarExpert'"></tabBar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '未审核'
				}, {
					name: '已审核'
				}],
				current: 0,
				patientListZjArr:[],
				type0List:[],
				typeList:[]
			}
		},
		onLoad(option) {
			
			this.patientListZj()
		},
		methods: {
			
			patientListZj(){
				this.$http.patientListZj()
				.then(res=>{
					if(res.data.code==200){
						// console.log(res.data.result)
						// console.log(this.geshihua(res.data.result,'type'))
						let list = this.geshihua(res.data.result,'type')
						list.forEach(val=>{
							if(val.type==0){
								this.type0List = this.type0List.concat(val.data)
							}else{
								this.typeList = this.typeList.concat(val.data)
							}
						})
						this.patientListZjArr = this.type0List
						console.log(this.patientListZjArr)
					}
				})
			},
			// 数据分类
			geshihua(data,type){
				 // 1.拿到所有type和对应的下标
				    var arr = [];   
				    data.map((e,i)=>{
				      let obj = {
				        [type]:e[type],
				        index:i
				      }
				      arr.push(obj)
				    })
				    // 2.归类
				    let newarr = []
				    arr.map((e,i)=>{
				      // 数据初始化
				      if(!i){
				        let obj = {
				          [type]:e[type],
				          data:[]
				        }
				        newarr.push(obj)
				      }
				      let index = e.index
				 
				      // 如果没有这个数据，新加一个类
				      // debugger
				      for(let j=0;j<newarr.length;j++){
				        // 如果已经有这个type,把数据添加进去即可
				        if(newarr[j][type] == e[type]){
				          newarr[j].data.push(data[index])
				          break;
				        }
				        // 如果没有这个type，就新加一个
				        else{
				          // 循环到最后一个，如果没有，则加入这个type数据
				          if(j==newarr.length-1){
				            let obj = {
				              [type]:e[type],
				              data:[data[i]]
				            }
				            newarr.push(obj)
				            break;
				          }
				        }
				      }
				    })
				    return newarr
			},
			patientListZjMet(item){
				uni.setStorageSync('patient',JSON.stringify(item));
				uni.navigateTo({
				  url: '/pages/doctor/uploadExpert?id='+item.id,
				})
			},
			change(index) {
				this.current = index;
				if(this.current == 0){
					
				this.patientListZjArr = this.type0List
				}else{
				this.patientListZjArr = this.typeList
					
				}
			}

		}
	}
</script>

<style lang="scss">
	.calendarExpert{
		padding-top: 20rpx;
		padding-bottom: 120rpx;
		.con{
			width:680rpx;
			margin: 24rpx auto;
			padding:32rpx;
			background-color: #fff;
			border-radius: 24rpx;
			text-align: center;
			.no{
				width: 520rpx;
				height: 340rpx;
			}
			.text{
				font-size: 28rpx;
				color: rgba(0,0,0,0.35);
				padding-bottom: 80rpx;
			}
		}
		.list{
			width:680rpx;
			margin: 24rpx auto;
			box-sizing: border-box;
			padding: 0 20rpx;
			background-color: #fff;
			border-radius: 24rpx;
			margin-top: 24rpx;
			.li{
				font-size: 28rpx;
				color: rgba(0,0,0,0.6);
				padding: 24rpx 32rpx;
				.flex{
					margin-bottom: 14rpx;
				}
				.address{
					view{
						margin-right: 20rpx;
					}
				}
				.class{
					display: flex;
					flex-direction: row;
					align-items: center;
					.box{
						padding: 4rpx 16rpx;
						background: rgba(22,127,255,0.1);
						color: #167FFF;
						font-size: 24rpx;
						margin-right: 16rpx;
						border-radius: 24rpx;
					}
				}
				.btn{
					padding: 6rpx 24rpx;
					background: #F02E2F;
					color: #fff;
					font-size: 28rpx;
					border-radius: 24rpx;
				}
				.btn1{
					background-color: $color;
				}
				.one{
					color: rgba(0,0,0,0.8);			
					.type{
						max-width: 280rpx;
						white-space:nowrap;
						overflow:hidden;
						text-overflow:ellipsis;
						font-size: 32rpx;
						color: rgba(0,0,0,0.8);
						margin-right: 24rpx;
						font-weight: bold;			
					}
					.name{
						flex: 1;
					}
					.status{
						position: relative;
					}
					.status1{
						color: $color;
					}
					.status2{
						color: #F02E2F;
					}
					.status::after{
						content: '';
						position: absolute;
						left: -30rpx;
						top: 50%;
						transform: translateY(-50%);
						width: 10rpx;
						height: 10rpx;
						border-radius: 50%;
						background: #F0A22E;
					}
					.status1::after{
						content: '';
						position: absolute;
						left: -30rpx;
						top: 50%;
						transform: translateY(-50%);
						width: 10rpx;
						height: 10rpx;
						border-radius: 50%;
						background: $color;
					}
					.status2::after{
						content: '';
						position: absolute;
						left: -30rpx;
						top: 50%;
						transform: translateY(-50%);
						width: 10rpx;
						height: 10rpx;
						border-radius: 50%;
						background: #F02E2F;
					}
				}
			}
		}
	}
</style>
