<template>
	<view class="content">

		<view class="fixed">
			<view class="status_bar" :style="'height:'+ statusBarHeight +'px;'"></view>
			<view class="header_title">
				<view class="title_ipt">
					<image src="/static/shop/search.png"></image>
					<input type="text" placeholder="在此搜索商品" placeholder-style="color:rgba(255,255,255,0.6)"
						confirm-type="search" v-model="keyword" @confirm="show=0,loadData(1)" />

				</view>
			</view>
		</view>

		<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">

			<view class="home_class">
				<v-tabs v-model="show" :tabs="cate1" field="title" @change="changeTab">
				</v-tabs>
			</view>

			<view class="lunbo">
				<swiper class="lb_swiper">
					<swiper-item v-for="(a,index) in bannerdata" :key="index">
						<view class="swiper-item">
							<image :src="a.imgurl"></image>
						</view>
					</swiper-item>
				</swiper>
			</view>

			<swiper :indicator-dots="false" :autoplay="false" style="min-height: 80rpx;">
				<swiper-item v-for="(v,i) in cate2" :key='i' style="min-height: 80rpx !important;">
					<view class="class_box">
						<view v-for="(a,b) in v" :key='b' @click="gotoPage('/pages/shop/list?id='+a.id)">
							<image :src="a.imgurl"></image>
							<view class="hang1">{{a.title}}</view>
						</view>
					</view>
				</swiper-item>
			</swiper>


			<view class="new_goods_list">
				<view class="flex_center">
					<image src="/static/shop/gift.png"></image>鉴正品 速发货
				</view>
				<view>好物集市丨精选搭配丨极速发货</view>
			</view>

			<view class="goods_ls_zc">
				<view class="goods_ls_bx_it" v-for="(a,b) in tui_data" :key="b"
					@click="gotoPage('/pages/shop/detail?goods_id='+a.id)">
					<image :src="a.image"></image>
					<view class="hang2">{{a.title}}</view>
					<view class="zuanshi"> ￥{{a.price}} </view>
				</view>
			</view>

		</mescroll-body>
		<tab-bar :index="2"></tab-bar>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
				keyword: '',

				show: 0,
				cate1: [],
				cate2: [],
				bannerdata: [],

				tui_data: [],
				classindex: '',
				downOption: {
					auto: false
				},
			}
		},
		onShow() {
			// this.getCate()
		},
		methods: {
			changeTab(index) {
				console.log('当前选中的项：' + index)
				this.show = index
				this.tui_data = []
				// this.getCate()
				this.mescroll.resetUpScroll()
			},
			getCate() {
				let that = this;

			},
			openUrl(e) {
				if (e.target == 1) {
					this.$customRouter.navigateTo('../shouye/detail', { id: e.goods_id });
				}
				if (e.target == 2) {
					this.$customRouter.navigateTo('detail', { goods_id: e.product_id });
				}
				if (e.target == 3) {
					this.$customRouter.navigateTo('../web-view', { url: e.url });
				}
			},


			downCallback() {
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				this.loadData(page.num);
			},
			loadData(pageNo) {
				// 模拟接口
				let that = this;
				that.req({
					url: 'shop_seckill_index',
					data: {
						cate_id1: that.cate1 && that.cate1.length > 0 ? that.cate1[that.show].id : that.show,
					},
					Loading: true,
					success(res) {
						that.cate1 = res.data.cate1;
						that.cate2 = res.data.cate2;
						that.bannerdata = res.data.advert;
					}
				})
				that.req({
					url: 'shop_seckill_product',
					Loading: true,
					data: {
						page: pageNo,
						cate_id1: that.cate1 && that.cate1.length > 0 ? that.cate1[that.show].id : that.show,
						title: that.keyword,
					},
					success(res) {
						that.mescroll.endByPage(res.data.data.length, res.data.last_page);
						if (pageNo == 1) {
							that.tui_data = res.data.data;
						} else {
							that.tui_data = that.tui_data.concat(res.data.data);
						}
					}
				})
			},

		}
	}
</script>

<style>
	.new_goods_list>view:nth-of-type(2) {
		font-size: 20rpx;
	}

	.new_goods_list image {
		width: 40rpx;
		height: 40rpx;
		margin-right: 10rpx;
	}

	.new_goods_list {
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		margin: 30rpx auto;
		width: 690rpx;
		height: 58rpx;
		color: #FFFFFF;
		font-size: 28rpx;
	}

	.home_class {
		width: 710rpx;
		margin: 10rpx auto 20rpx;
	}

	.title_ipt>image {
		width: 50rpx;
		height: 50rpx;
		position: absolute;
		left: 24rpx;
		top: 0;
		bottom: 0;
		margin: auto;
	}

	.title_ipt {
		width: 476rpx;
		height: 60rpx;
		background: #161616;
		border-radius: 30rpx;
		position: relative;
	}

	.title_ipt>input {
		width: 380rpx;
		height: 60rpx;
		background: #161616;
		padding-left: 90rpx;
		box-sizing: border-box;
		border-radius: 30rpx;
		font-size: 28rpx;
		line-height: 60rpx;
		color: #FFFFFF;
	}

	.header_title {
		height: 60rpx;
		line-height: 60rpx;
		margin-top: 10rpx;
		width: 100%;
		box-sizing: border-box;
		padding-left: 30rpx;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.fixed {
		background: #000000;
		/* border: 1rpx solid red; */
		width: 750rpx;
		box-sizing: border-box;
		position: fixed;
		/* #ifdef MP */
		top: 0;
		/* #endif */
		/* #ifndef MP */
		top: 0rpx;
		/* #endif */
		z-index: 1995;
	}

	.content {
		padding-top: calc(var(--status-bar-height) + 100rpx);
		background: #000000;
		box-sizing: border-box;
		width: 100vw;
		min-height: 100vh;
	}

	.lunbo {
		height: 280rpx;
		padding: 0 30rpx;
		margin-bottom: 30rpx;
		padding-top: 10rpx;
	}

	.lb_swiper {
		width: 100%;
		height: 280rpx;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.lb_swiper .swiper-item>image {
		width: 100%;
		height: 280rpx;
		border-radius: 20rpx;
	}

	.class_box {
		padding: 0 30rpx;
		display: flex;
		/* justify-content: space-between; */
		flex-wrap: wrap;
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
	}

	.class_box>view {
		margin-right: 50rpx;
		margin-bottom: 36rpx;
		width: 98rpx;
		text-align: center;
	}

	.class_box>view>view {
		/* overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis; */
		margin-top: 8rpx;
	}

	.class_box>view:nth-of-type(5n+5) {
		margin-right: 0;
	}

	.class_box image {
		width: 90rpx;
		height: 78rpx;
		display: block;
		margin: auto;
	}




	.goods_ls_zc {
		padding: 30rpx;
		position: relative;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		color: #FFFFFF;
	}

	.goods_ls_bx_it {
		width: 330rpx;
		border-radius: 10rpx;
		overflow: hidden;
		margin-bottom: 26rpx;
	}

	.goods_ls_bx_it>image {
		width: 330rpx;
		height: 330rpx;
		border-radius: 16rpx;
	}

	.goods_ls_bx_it>view:nth-of-type(1) {
		font-size: 28rpx;
		padding: 0 22rpx;
		padding-top: 10rpx;
	}

	.zuanshi {
		font-size: 32rpx;
		padding: 0 22rpx;
		margin: 14rpx 0 8rpx 0;
		color: #0FEFFF;
	}
</style>
