<template>
	<view class="content" >
		<view class="top-box">
			<!-- 搜索框 -->
			<view class="search-cont">
				<view class="inner">
					<image class="icon-search" src="/static/images/search.png" mode=""></image>
					<input type="text" v-model="keyword" placeholder="输入关键字搜索" confirm-type="search" @confirm="doSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
				</view>
			</view>
			<view class="tabs">
				 <u-tabs
				  :scrollable="false"
				  :list="tabs"  
				  :lineColor="basecolor"
				 @change="tabChange">
				 </u-tabs>
			</view>
		</view>
		<view class="cont-box">
			<view class="left">
				<view class="items">
					<view v-if="tabIndex==1" @click="typeClick(item)" v-for="item in typeOptions" :class="item.dictValue==prescribeType?'item ellipsis active':'item ellipsis'">
						<text class="line" v-if="item.dictValue==prescribeType"></text>
						{{ utils.subString(item.dictLabel) }}
					</view>
					<view v-if="tabIndex==2" @click="indicationClick(item)" v-for="item in indicationOptions" :class="item.dictLabel==indication?'item ellipsis active':'item ellipsis'">
						<text class="line" v-if="item.dictLabel==indication"></text>
						{{ utils.subString(item.dictLabel) }}
					</view>
					<view v-if="tabIndex==3" @click="bookClick(item)" v-for="item in bookOptions" :class="item.dictLabel==belongBook?'item ellipsis active':'item ellipsis'">
						<text class="line" v-if="item.dictLabel==belongBook"></text>
						{{  utils.subString(item.dictLabel)  }}
					</view>
				</view>
			</view>
			<view class="right" >
				<view class="title">{{title}}</view>
				<scroll-view @scrolltolower="scrolltolower" scroll-y="true"  style="height: calc(100vh - 180rpx);">
				<view class="items">
					<view class="r-item" @click="showDetail(item)" v-for="item in dataList">
						<view class="r-left">{{item.prescribeName}}</view>
						<view class="r-right">
							<image src="/static/images/fire.png"></image>
						</view>
					</view>
				</view>
				</scroll-view>
			</view>
		</view>
		 
		
	</view>
</template>

<script>
	import {getDictByKey} from '@/api/common.js'
	import {getFamousPrescribeList} from '@/api/index.js'
	export default {
		data() {
			return {
				tabIndex:1,
				indication:"",
				belongBook:"",
				title:"",
				prescribeType:0,
				pageNum:1,
				pageSize:20,
				typeOptions:[],
				bookOptions:[],
				indicationOptions:[],
				tabs: [
					{name:"按类型",id:"1"},
					{name:"按疾病",id:"2"},
					{name:"按书籍",id:"3"}
				],
				keyword: '',
				dataList: [],
			};
		},
		onLoad() {
			this.getDictByKey("sys_famous_prescribe_type");
			this.getDictByKey("sys_famous_prescribe_indication");
			this.getDictByKey("sys_famous_prescribe_book");
			
		},
		methods:{
			scrolltolower(e){
				this.pageNum++;
				this.getFamousPrescribeList()
			},
			typeClick(item){
				this.indication=""
				this.belongBook="";
				this.prescribeType=parseInt(item.dictValue);
				this.title=item.dictLabel;
				this.pageNum=1;
				this.getFamousPrescribeList()
			},
			bookClick(item){
				this.indication=""
				this.prescribeType=0;
				this.belongBook=item.dictLabel;
				this.title=item.dictLabel;
				this.pageNum=1;
				this.getFamousPrescribeList()
			},
			indicationClick(item){
				this.belongBook=""
				this.prescribeType=0;
				this.indication=item.dictLabel;
				this.title=item.dictLabel;
				this.pageNum=1;
				this.getFamousPrescribeList()
			},
			getDictByKey(key){
				var data={key:key}
				getDictByKey(data).then(
					res => {
						if(res.code==200){
							if(key=="sys_famous_prescribe_type"){
								this.typeOptions=res.data;
								if(this.typeOptions!=null&&this.typeOptions.length>0){
									this.typeClick(this.typeOptions[0])
								}
							}
							if(key=="sys_famous_prescribe_indication"){
								this.indicationOptions=res.data;
								 
							}
							if(key=="sys_famous_prescribe_book"){
								this.bookOptions=res.data;
								 
							}
						}
					},
					err => {
					}
				);
				
			},
			tabChange(item) {
				this.tabIndex = item.id
				this.getFamousPrescribeList()
			},
			doSearch(){
				this.pageNum=1;
				this.getFamousPrescribeList()
			},
			getFamousPrescribeList() {
				//联网加载数据
				var that = this;
				var data = {
					indication:this.indication,
					belongBook:this.belongBook,
					prescribeType:this.prescribeType,
					keyword:this.keyword,
					pageNum: this.pageNum,
					pageSize: this.pageSize
				};
				uni.showLoading({
					title:"加载中..."
				})
				getFamousPrescribeList(data).then(res => {
					uni.hideLoading()
					if(res.code==200){
						//设置列表数据
						if (this.pageNum == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = [];
					}
				});
			},
			 
			// 查看详情
			showDetail(item) {
				uni.navigateTo({
					url: './famousPrescribeDetails?id=' + item.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		height: 100%;
		overflow: hidden;
	}
	.top-box{
		width: 100%;
		height: 180rpx;
		background-color: #FFFFFF;
		.search-cont{
			padding: 16upx 30upx;
			.inner{
				box-sizing: border-box;
				width: 100%;
				height: 72upx;
				background: #F7F7F7;
				border-radius: 36upx;
				display: flex;
				align-items: center;
				padding: 0 30upx;
				.icon-search{
					width: 28upx;
					height: 28upx;
					margin-right: 20upx;
				}
				input{
					height: 60upx;
					line-height: 60upx;
					flex: 1;
				}
			}
		}
		.tabs{
		}
	}
	.cont-box{
		height: calc(100% - 180rpx);
		display: flex;
		align-items: flex-start;
		justify-content: flex-start;
		.left{
			padding: 30rpx 0rpx;
			width: 240rpx;
			height: 100%;
			overflow-y: auto;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: flex-start;
			.items{
				width: 240rpx;
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: flex-start;
				.item{
					width: 240rpx;
					padding: 0rpx 20rpx;
					display: flex;
					align-items: center;
					justify-content: flex-start;
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: normal;
					color: #111111;
					font-weight: 500;
					line-height: 80upx;
					.line{
						margin-right: 15rpx;
						border-radius: 5rpx;
						width: 8rpx;
						height:30rpx;
						background-color: var(--base-color);
					}
					
				}
				.active{
					background-color: #fff;
					font-weight: bold;
					color: var(--base-color);
				}
			}
			
		}
		.right{
			padding: 30rpx 15rpx;
			background-color: #fff;
			height: 100%;
			overflow-y: auto;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: flex-start;
			width: calc(100% - 240rpx);
			.title{
				font-size: 40upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: var(--base-color);
				line-height: 80upx;
			}
			.items{
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: flex-start;
				.r-item{
					line-height: 80rpx;
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: flex-start;
					.r-left{
						flex: 1;
						font-size: 32upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #080808;
					}
					.r-right{
						padding: 0rpx 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						image{
							width: 22rpx;
							height:30rpx;
						}
					}
					
				}
				 
			}
		}
	}
	 
</style>
