<template>
	<view class="content">
		<u-swiper height="250" :list="imageTopList"></u-swiper>
		<view class="t1">
			<u-image height="40" src="/static/t1.png"></u-image>
		</view>
		<!-- 商品 -->
		<view class="goods">
			<view v-for="(item,index) in goodsList" :key="item.type.id" v-if="item.list.length">
				<u-section :title="item.type.name" line-color="#01c9b2" sub-title="更多" @click="toGoods(item.type)"></u-section>
				<view class="goods-list">
					<uni-coods :list="item.list"></uni-coods>
				</view>
			</view>
			<u-empty v-else text="暂无商品" mode="list"></u-empty>
		</view>
		<!-- 购物车 -->
		<uni-cart-fix></uni-cart-fix>
	</view>
</template>

<script>
	import {
		getGoodsClass,
		getGoodsList
	} from '@/api/goods.js'
	export default {
		components: {
		},
		data() {
			return {
				imageTopList:[
					{image:'/static/banner.png'},
					{image:'/static/banner1.png'}
				],
				goodsList:[], // 商品
				goodsType:[], // 商品分类
			}
		},
		onLoad() {
			getGoodsClass({}).then(res => {
				console.log(res)
				if(res.status == 200){
					this.goodsType = res.data
					this.goodsType.map((item,index) => {
						this.getGoods(item,index)
					})
				}
			})
		},
		methods: { 
			// 更多商品
			toGoods(item){
				uni.navigateTo({
					url:"/pages/goods/goods?goodsTypeNo="+ item.goodsTypeNo + "&goldLimit="+ item.goldLimit
				})
			},
			// 查询商品
			getGoods(item,index){
				getGoodsList({pageNo:1,pageSize:item.popularizeGoodsLimit,goodsTypeNo:item.goodsTypeNo}).then(res => {
					console.log(res,'goodsList')
					if(res.status == 200&&res.data.list&&res.data.list.length){
						this.goodsList.push({
							type: item,
							list: res.data.list
						})
						this.goodsList.splice()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: url(../../static/topBg.png) no-repeat top center;
		background-size: 100%;
		width: 100%;
		.goods{
			>view{
				padding: 25upx 20upx 10upx;
				background: #FFFFFF;
				border-radius: 15upx;
				box-shadow: 0upx 6upx 10upx #eee;
				margin-bottom: 20upx;
				> .goods-list{
					padding-top: 5upx;
				}
			}
		}
		.t1{
			padding: 20upx 0;
		}
	}
</style>
