<template>
	<view class="app">
		<view class="cards">
			<view class="item" :style="{background:listcolor[index]}" @tap='goProductList(item)'
				v-for="(item,index) in goodsCategoryList" :key="index">
				<image :style="index==4?'top:0;border-radius: 20rpx;width:100%;height: 300rpx;':''"
					:src="item.goodsCategoryPicture" mode=""></image>
				<view class="title" style="font-size:42rpx" v-if="index!=4">
					{{item.goodsCategoryName}}
				</view>
			</view>
			<view style="width:43%" v-if="goodsCategoryList.length%2!=0">
			</view>
		</view>
	</view>
</template>
<script>
	import {
		goodsCategoryList
	} from '@/api/shopping/shopping.js';
	import baseurl from '@/api/baseurl.js'
	export default {
		data() {
			return {
				pageNum: 1, //页
				pageSize: 10, //列
				total: 0, //list总长度
				goodsCategoryList: [], //商品列表list
				listimg: [{
						img: '../../static/sp.png',
					},
					{
						img: '../../static/yyss.png',
					},
					{
						img: '../../static/znsb.png',
					},
					{
						img: '../../static/cp.png',
					},
				],
				listcolor: ['#00C176', '#D43953', '#E1AE3C', '#4C7BC9', '#9e4dd0', '#00C176', '#D43953', '#E1AE3C',
					'#4C7BC9', '#9e4dd0',
				], //颜色随动
			};
		},
		onLoad(options) { //初始化加载
			this.goodsCategory()
		},
		methods: {
			//跳转到商品列表页面
			goProductList(item) {
				console.log(item)
				uni.navigateTo({
					url: `/pages/ProductList/ProductList?title=${item.goodsCategoryName}&goodsCategoryId=${item.id}`
				})
			},
			//获取商城信息
			goodsCategory() {
				goodsCategoryList(this.pageSize, this.pageNum).then(res => {
					res.rows.forEach(e => {
						e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
						this.goodsCategoryList.push(e)
					})
					console.log(this.goodsCategoryList)
					this.total = res.total
				})
			}
		},
		onReachBottom() { //下滑加载
			if (this.goodsCategoryList.length >= this.total) {} else {
				this.pageNum++;
				this.goodsCategory()
			}
		},
		onPullDownRefresh() { //下拉刷新
			this.pageNum = 1;
			goodsCategoryList(this.pageSize, this.pageNum).then(res => {
				res.rows.forEach(e => {
					e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
				})
				this.goodsCategoryList = res.rows
				this.total = res.total
			})
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		}
	}
</script>

<style lang="scss">
</style>
