<style lang="scss">
	.m-app{
		padding: 0px 20rpx;
	}
	.sreach{
		background: #fff;
		margin:20rpx 0;
		border-radius: 32rpx;
		padding: 16rpx 32rpx;
		.icon{
			width: 46rpx;
			height: 46rpx;
		}
		input{
			width: calc(100% - 46rpx - 16rpx - 50px);
			font-size: 16px;
		}
		.search-btn{
			font-size: 14px;
			color: #FF4C4C;
		}
	}
		
	
	.goods-items{
			.item{
				width: calc(50% - 10rpx);
				margin-right: 10rpx;
				margin-top: 20rpx;
				box-shadow: 0px 0px 20px 0px rgba(50,50,52,0.1);
				border-radius: 20rpx;
				&:nth-child(2n){
					margin-left: 10rpx;
					margin-right: 0;
				}
				.nimg{
					width: 100%;
					height: calc(50vw - 20rpx - 10rpx);
					border-radius: 20rpx 20rpx 0 0;
				}
				.title{
					padding: 20rpx;
					height: 80rpx;
					overflow:hidden;
					text-overflow:ellipsis;
					display:-webkit-box;
					-webkit-box-orient:vertical;
					-webkit-line-clamp:2;
					color: #333333;
					font-weight: bold;
					font-size: 30rpx;
				}
				.iview{
					padding: 20rpx;
					.score{
						color: #FF4C4C;
						font-weight: bold;
						font-size: 36rpx;
						.tag{
							font-weight: bold;
							font-size: 18rpx;
							color: #FF4C4C;
						}
					}
					.btn{
						background: linear-gradient(143.2747deg, #FF6A00, #EE0979);
						border-radius: 40rpx;
						padding: 10rpx 28rpx;
						font-size: 22rpx;
						color: #FFFFFF;
					}
				}
			}
		}
</style>


<template>
	<view class="m-app">
		
		<!--关键词搜索-->
		<view class="sreach fx-r fx-bc fx-ac"  id="top-main" >
			<image class="icon" src="/static/img/tb-seach.png"></image>
			<input type="text" confirm-type="search"  v-model="keyword" @confirm="tapInput" placeholder="请输入关键词" placeholder-style="color: #B3B3B3;" />
			<view class="fx-g1"></view>
			<view class="search-btn" @tap="tapInput" v-if="keyword != ''">搜索</view>
		</view>
		
		
		<scroll-view :style="'height:calc(100vh - ' + topHeight + 'px - ' + h5Foot + 'px)'" class="mid-body clearfix" scroll-y="true" @scrolltolower="loadMoreData">		
			<view class="goods-items fx-r">
				<view class="item" @tap="tapOpen" v-for="item in data"  :data-url="'/pages/goods/index?id=' + item.id">
					<image :src="item.img" mode="aspectFill" class="nimg"></image>
					<view class="title">
						{{ item.title }}
					</view>
					<view class="iview fx-r">
						<view class="score fx-r fx-be">
							{{ item.commission }}
							<view class="tag" v-if="sysData.is_audit == 0">>积分</view>
						</view>
						<view class="fx-g1"></view>
						<view class="btn" v-if="sysData.is_audit == 0">>提货</view>
					</view>
					
					
				</view>
			</view>
			<view class="loading fx-r fx-ac fx-bc" v-if="!page.isFoot">
				<image src="/static/img/xloading.png"></image>
				<text>正在载入更多...</text>
			</view>
			<view class="loading complete" :hidden="!page.isFoot">已加载全部</view>
			
		</scroll-view>
	</view>
</template>

<script>
	import {mapState,mapMutations } from 'vuex'
	var cateId = 0;
	var brandId = 0;
	var activeId = "";//限时抢购rush,秒杀专场seckill
	var is_rush = 0;//
	var type = "";
	export default {
		computed: mapState(['user','sysData']),
	    data() {
	        return {
				keyword : "",
				tabIndex : 0,
				topHeight:0,
				tabPriceIndex : 0,
				data : [],
				h5Foot : 0,
				page:{
					page:1,
					isLoad:false,
					isFoot:false
				}
	        }
	    },
		/**
		 * 跳转的值
		 * @param {Object} option
		 */
		onLoad(option){
			this.keyword = option.keyword || "";
			cateId = option.cateId || 0;
			brandId = option.brandId || 0;
			activeId = option.activeId || '';
			if(this.utils.isDefine(option.title)) {
				uni.setNavigationBarTitle({
					title:option.title
				});
			}  
			this.$nextTick(()=>{
				const query = uni.createSelectorQuery().in(this);
				query.select("#top-main").boundingClientRect(res=>{
					this.topHeight = res.height;
				}).exec();
			});
			//判断是否H5
			// #ifdef H5
				this.h5Foot = 50;
			// #endif
			this.getData(true);
		},
	    methods: {
			/**
			 * 输入
			 */
			tapInput:function(ev){
				this.page = {page:1,isLoad:false,isFoot:false};
				this.getData(true);
			},
			/**
			 *  下拉加载
			 */
			loadMoreData:function(){
				
				if(this.page.isFoot || this.page.isLoad) {
					return;
				}
				this.page.page ++;
				this.getData();
			},
			/**
			   * 获取get数据
			*/
			getData:function(isPull = false){
					if (this.page.isLoad) return;
					this.page.isLoad = true;
					if (isPull) {
						uni.showLoading({	title: '获取数据中..'});
					}
					var post = {};
					if(this.keyword != "") {
						post.keyword = this.keyword;
					}
					post.page = this.page.page;
					this
						.request
						.post("goodsList",post)
						.then(res => {
							uni.hideLoading();
							
							uni.hideLoading();
							if (isPull) {
								this.data = res.data.list;
								uni.stopPullDownRefresh();
							} else {
								this.data = this.data.concat(res.data.list);
							}
							this.page.isLoad = false;
							//是否到底
							if (res.data.list.length != res.data.pageSize) {
								this.page.isFoot = true;
							}
							
						})
						.catch(res=>{
							console.log(res);
							uni.hideLoading();
							uni.showModal({title: '系统提示',content: '加载失败，重新点击尝试！',showCancel: false});
						});
				},
			
			/**
			 * 打开其他页面
			 * @param {Object} ev
			 */
			tapOpen: function(ev) {
				let url = ev.currentTarget.dataset.url
				uni.navigateTo({
					url: url
				});
			},	
			/**
			 * 返回上一页
			 */	
			tapBack: function () {
			    uni.navigateBack({ delta: 1 });
			},
	    }
	}
</script>

