<template>
	<view>
		<view class="top-content">
			<!-- 搜索框 -->
			<view class="search-cont">
				<view class="inner">
					<image class="icon-search" src="/static/images/icon_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="cate-list">
				<!-- 关键字列表 -->
				<scroll-view   scroll-x="true" >
					<view class="inner">
						<view v-for="(item,index) in cates" :key="index" :class="privateType == item.cateCode?'item active':'item'" @click="choseType(item)">
							{{ item.cateName }}
						</view>
					</view>
				</scroll-view>
			</view>
			 
		</view>
		<mescroll-body  top="192rpx"  ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="package-list">
				<view  v-for="(item,index) in dataList" :key="index" class="item" >
					<view class="top-box">
						<view class="title">{{item.packageName}}</view>
						<view class="subtitle">别名:{{item.secondName}}</view>
					</view>
					<!-- 药品列表 -->
					<view class="drug-list"  >
						<view v-for="(subItem,subIndex) in item.products" :key="subIndex" class="drug-item" :class="item.displayMore==0?'hide':'show'">
							<view class="img-box">
								<image :src="subItem.image" mode="aspectFill"></image>
							</view>
							<view class="drug-info"  >
								<view>
									<view class="name-box ellipsis2">
										{{subItem.productName}}
									</view>
									<view class="spec">{{subItem.sku}}</view>
								</view>
								<view class="num-box">
									<view class="price" v-if="subItem.price!=null">
										<text class="unit">¥</text>
										<text class="num" >{{subItem.price.toFixed(2)}}</text>
									</view>
									<view class="amount">x{{subItem.count}}</view>
								</view>
							</view>
						</view>
						<view class="display-more" @click="showMore(item)" >{{item.displayText}}</view>
						<!-- 实付金额、按钮 -->
						<view class="bottom-box">
							<view class="amount-paid">
								<text class="label">套餐价格：</text>
								<view class="price-box" v-if="item.totalPrice!=null">
									<view class="unit">¥</view>
									<view class="num" >{{item.totalPrice.toFixed(2)}}</view>
								</view>
							</view>
							<view class="btn-box">
								<view  class="btn pay" @click.stop="navTo('/pages_company/packageDetails?packageId='+item.packageId)">
									查看详情
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="package-box"  >
				<view class="item"  @click="navTo('/pages_company/packageDetails?packageId='+item.packageId)" v-for="(item,index) in dataList">
					<view class="top">
						<image :src="item.imgUrl"></image>
					</view>
					<view class="bottom">
						<view class="title ellipsis2">
							{{item.packageName}}
						</view>
						<view class="price-box">
							<view class="price">￥{{item.price.toFixed(2)}}元/日</view>
							<view class="count">{{item.sales}}人已购</view>
						</view>
					</view>
				</view>
			</view> -->
		</mescroll-body>
		
	</view>
</template>

<script>
	import {getPackageList,getPackagCateList} from '@/api/package.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				cates:[],
				privateType:0,
				keyword: '',
				mescroll:null,
				downOption: {   //下拉刷新
				 	use:true,
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
						tip: '暂无数据'
					}
				},
				dataList: []
			};
		},
		onShow() {
			this.getPackagCateList(2);
		},
		methods:{
			getPackagCateList(type){
				var data={type:type}
				getPackagCateList(data).then(
					res => {
						if(res.code==200){
							 this.cates=res.data;
						}
					},
					err => {
					}
				);
				
			},
			showMore(item){
				item.displayMore=item.displayMore==1?0:1;
				item.displayText=item.displayMore==1?'收起':'点击查看方案明细'
			},
			navTo(url){
				uni.navigateTo({
					url: url
				})
			},
			doSearch(){
				this.mescroll.resetUpScroll()
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					isShow:0,
					keyword:this.keyword,
					privateType:this.privateType,
					pageNum: page.num,
					pageSize: page.size
				};
				getPackageList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						res.data.list.forEach(function(element) {
						   element.displayMore=0
						   element.displayText='点击查看方案明细'
						   if(element.productJson!=null){
							   element.products=JSON.parse(element.productJson)
						   }
						   else{
							   element.products=[]
						   }
						   
						   
						});
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			choseType(item) {
				this.privateType = item.cateCode;
				this.mescroll.resetUpScroll()
			},
			 
		}
	}
</script>

<style lang="scss">
	.top-content{
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
	}
	.search-cont{
		padding: 16upx 30upx;
		background-color: #FFFFFF;
		.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;
			}
		}
	}
	.cate-list{
		box-sizing: border-box;
		background: #fff;
		padding: 10upx 27upx;
		height: 100upx;
		.inner{
			display: flex;
		}
		.item{
			flex-shrink: 0;
			padding: 0 24upx;
			height: 64upx;
			line-height: 64upx;
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #C39A58;
			background: #ffffff;
			border: 1px solid #E2C99E;
			border-radius: 32upx;
			margin: 0 20upx 20upx 0;
			&.active{
				color: #FFFFFF;
				background: #C39A58;
				border: 1px solid #C39A58;
			}
		}
	}
	.package-box{
		margin-top: 20rpx;
		display: flex;
		align-items: flex-start;
		justify-content: flex-start;
		flex-wrap: wrap;
		.item{
			box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
			background-color: #fff;
			width: calc(50% - 20rpx);
			border-radius: 15rpx;
			margin: 10rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: flex-start;
			&:last-child{
			}
			.top{
				width:100%;
				height:300rpx;
				image{
					border-radius: 15rpx 15rpx 0rpx 0rpx;
					width:100%;
					height:300rpx;
				}
				
			}
			.bottom{
				width: 100%;
				padding: 15rpx 10rpx;
				.title{
					font-weight: bold;
					font-size: 28upx;
					font-family: PingFang SC;
					color: #111111;
				}
				.price-box{
					margin-top: 10rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					.price{
						padding: 5rpx 10rpx;
						background-color: #C39A58;
						border-radius: 30rpx;
						font-size: 20upx;
						font-family: PingFang SC;
						color: #ffffff;
					}
					.count{
						font-size: 24upx;
						font-family: PingFang SC;
						color: #333333;
					}
					
				}
			}
		}
	}
	.package-list{
		padding: 20upx;
		.item{
			background: #FFFFFF;
			border-radius: 16upx;
			padding: 0 30upx;
			margin-bottom: 20upx;
			.top-box{
				padding: 34upx 0 20upx;
				.title{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					font-weight: bold;
					color: #111111;
				}
				.subtitle{
					margin-top: 5rpx;
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #111111;
				}
				 
			}
			.drug-list{
				.drug-item{
					padding-bottom: 30rpx;
					border-bottom: 1px soli #F0F0F0;
					display: flex;
					align-items: center;
					.img-box{
						width: 160upx;
						height: 160upx;
						margin-right: 30upx;
						flex-shrink: 0;
						image{
							width: 100%;
							height: 100%;
						}
					}
					.drug-info{
						width: calc(100% - 190upx);
						height: 160upx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						.name-box{
							font-size: 28upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #111111;
							line-height: 40upx;
							.tag{
								display: inline-block;
								padding: 0 6upx;
								height: 30upx;
								background: linear-gradient(90deg, #C39A58 0%, #C39A58 100%);
								border-radius: 4upx;
								margin-right: 10upx;
								font-size: 22upx;
								font-family: PingFang SC;
								font-weight: bold;
								color: #FFFFFF;
								line-height: 30upx;
								float: left;
								margin-top: 7upx;
							}
						}
						.spec{
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							line-height: 1;
							margin-top: 10upx;
						}
						.num-box{
							display: flex;
							align-items: center;
							justify-content: space-between;
							.price{
								display: flex;
								align-items: flex-end;
								.unit{
									font-size: 24upx;
									font-family: PingFang SC;
									font-weight: 500;
									color: #111111;
									line-height: 1.2;
									margin-right: 4upx;
								}
								.num{
									font-size: 32upx;
									font-family: PingFang SC;
									font-weight: 500;
									color: #111111;
									line-height: 1;
								}
							}
							.amount{
								font-size: 24upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #999999;
								line-height: 1;
							}
						}
					}
				}
				.show{
					visibility: flex;
				}
				.hide{
					display: none;
				}
				.display-more{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				.bottom-box{
					height: 110upx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.amount-paid{
						display: flex;
						align-items: center;
						.label{
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							line-height: 1;
						}
						.price-box{
							display: flex;
							align-items: flex-end;
							.unit{
								font-size: 24upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #FF6633;
								line-height: 1.2;
								margin-right: 4upx;
							}
							.num{
								font-size: 32upx;
								font-family: PingFang SC;
								font-weight: bold;
								color: #FF6633;
								line-height: 1;
							}
						}
					}
					.btn-box{
						box-sizing: border-box;
						display: flex;
						align-items: center;
						.btn{
							width: 155upx;
							height: 64upx;
							line-height: 64upx;
							font-size: 26upx;
							font-family: PingFang SC;
							font-weight: 500;
							text-align: center;
							border-radius: 32upx;
							margin-left: 15upx;
							&:first-child{
								margin-left: 0;
							}
							&.cancel{
								border: 1px solid #DDDDDD;
								color: #666666;
							}
							&.pay{
								background: #C39A58;
								color: #FFFFFF;
								position: relative;
								.share{
									display: inline-block;
									position: absolute;
									top: 0;
									left: 0;
									width: 100%;
									height: 100%rpx;
									opacity: 0;
								}
							}
						}
					}
				}
			}
		}
		
	}
</style>
