<template>
	<view class="content">
		<u-swiper height="250" @click="clickBanner" :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="goodsList.length&&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>
			<view v-if="goodsList.length==0">
				<u-empty icon-size="60" :text="noDataText" mode="list"></u-empty>
			</view>
		</view>
		<!-- 购物车 -->
		<uni-cart-fix></uni-cart-fix>
	</view>
</template>

<script>
	import {
		getGoodsClass,
		getGoodsList
	} from '@/api/goods.js'
	import {bannerList} from '@/api/banner.js'
	export default {
		components: {
		},
		data() {
			return {
				noDataText: '正则加载...',
				imageTopList:[],
				goodsList:[], // 商品
				goodsType:[], // 商品分类
			}
		},
		onShow() {
			this.getbannerList()
			this.goodsList = []
			getGoodsClass({}).then(res => {
				console.log(res)
				if(res.status == 200){
					this.goodsType = res.data
					this.goodsType.map((item,index) => {
						this.getGoods(item,index)
					})
				}else{
					this.goodsList = []
					this.noDataText = '暂无商品'
				}
			})
		},
		methods: { 
			// 点击banner
			clickBanner(index){
				let row = this.imageTopList[index]
				console.log(index,row)
				if(row.jumpType !== 'NONE'){
					uni.navigateTo({
						url: row.jumpUrl
					})
				}
			},
			// 获取banner
			getbannerList(){
				bannerList({type:'banner',location:'MALL_TOP'}).then(res=>{
					if(res.status==200){
						this.imageTopList=res.data
					}
				})
			},
			// 更多商品
			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>
