<template>
	<view>
		<!-- 数据列表 -->
		<!-- <mescroll-body :top="top+'px'" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption"> -->
			<view class="medic-itemlist">
				<medicineItem :type="'store'" v-for="(item, index) in dataList" :key="index" :item="item"></medicineItem>
				<view class="morebtn" v-if="dataList&&dataList.length>0" @click="navTo('/pages_shopping/home/productList?storeId='+storeId)">查看更多</view>
			</view>
			<!-- <view class="goods-list">
				<view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
					<view class="img-box">
						<image :src="item.image" mode="aspectFill"></image>
						<view class="otctxt" :style="{background:_background(item.productType)}" v-show="item.productType">{{$getDictLabelName("storeProductType",item.productType)}}</view>
					</view>
					<view class="info-box">
						<view class="title ellipsis2">{{item.productName}}</view>
						<view class="price-box">
							<view class="now">
								<text class="unit">¥</text>
								<text class="num">{{item.price.toFixed(2)}}</text>
							</view>
							<view class="old" v-show="item.price!=item.otPrice&&item.otPrice!==null&&item.otPrice!==undefined">¥{{item.otPrice.toFixed(2)}}</view>
						</view>
					</view>
				</view>
			</view> -->
		<!-- </mescroll-body> -->
	</view>
</template>

<script>
	import medicineItem from '@/components/medicineItem.vue'
	import {getProducts} from '@/pages_shopping/api/product.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		components:{
			medicineItem
		},
		 props: {
			 storeId:'',
			 top: 0
		 },
		data() {
			return {
				form:{
					defaultOrder:'desc',
					newOrder:null,
					priceOrder:null,
					salesOrder:null,
					productName:"",
					storeId: ""
				},
				mescroll:null,
				downOption: {
					//下拉刷新
					use: true,
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				// 上拉加载的配置
				upOption: {
					onScroll:true,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 20, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon:'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/empty_icon.png',
						tip: '暂无数据'
					},
					textNoMore:"已经到底了",
				},
				// 列表数据
				dataList: [],
			};
		},
		computed: {
			_background() {
				//productType： 1：OTC，2：Rx，3：非药品，4：器械
				return (productType)=> {
					switch (productType) {
						case 1: return '#37E2EA' // OTC
						case 2: return 'red'     // Rx
						case 3: return '#2583EB' // 非药品
						case 4: return '#999'    // 器械
						default: return '#ccc'
					}
				}
			}
		},
		// watch: {
		//   storeId: {
		//     immediate: true,           // 第一次也触发
		//     handler (newVal, oldVal) {
		//       console.log('msg 变了：', newVal)
		// 	  if(newVal) {
		// 		  console.log(this.mescroll)
		// 		 this.mescroll.resetUpScroll()
		// 	  }
		//     }
		//   }
		// },
		methods:{
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			getProducts(storeId) {
				this.storeId = storeId
				//联网加载数据
				var that = this;
				const param = {
					page: 1,
					pageSize: 10,
					storeId: this.storeId,
					isGood: 1
				}
				getProducts(param).then(res => {
					if(res.code==200){
						//设置列表数据
						that.dataList = res.data.list;
						// that.mescroll.endBySize(res.data.list.length, 10);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						// that.dataList = null;
						// that.mescroll.endErr();
					}
					that.$emit('refreshElementTop')
				});
			},
			// 查看详情
			showDetail(item) {
				uni.navigateTo({
					url: '/pages_shopping/productDetails?productId='+item.productId + `${this.storeId ? '&storeId='+this.storeId : ''}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.morebtn{
		padding: 20rpx;
		box-sizing: border-box;
		text-align: center;
		font-weight: 500;
		font-size: 32rpx;
		color: #999;
	}
	.medic-itemlist {
		padding: 20upx;
		box-sizing: border-box;
	}
	.desc {
		margin-top: 12rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #939599;
	}
	.otctxt {
		position: absolute;
		top: 0;
		left: 0;
		background-color: #37E2EA;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 20rpx;
		color: #FFFFFF;
		padding: 4rpx 14rpx;
		border-radius: 16rpx 0 16rpx 0;
	}
	.goods-list{
		padding: 20upx;
		display: flex;
		flex-wrap: wrap;
		.item{
			margin-right: 20rpx;
			margin-bottom: 20rpx;
			width: 345rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 10rpx 4rpx rgba(199, 199, 199, 0.22);
			border-radius: 20rpx;
			overflow: hidden;
			&:nth-child(2n) {
				margin-right: 0;
			}
			.img-box{
				width: 100%;
				height: 334upx;
				position: relative;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.info-box{
				box-sizing: border-box;
				height: 182upx;
				padding: 20upx 20upx 30upx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title{
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					line-height: 40upx;
				}
				.price-box{
					display: flex;
					align-items: flex-end;
					.now{
						display: flex;
						align-items: flex-end;
						margin-right: 20upx;
						.unit{
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #FF6633;
							line-height: 1.2;
							margin-right: 4upx;
						}
						.num{
							font-size: 36upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #FF6633;
							line-height: 1;
						}
					}
					.old{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						text-decoration: line-through;
						color: #BBBBBB;
						line-height: 1.1;
					}
				}
			}
		}
	}
</style>
