<!-- 专区页面 -->
<template>
	<view class="zone">
		<view class="listbox">
			<Goods v-for="(item, index) in list" :key="index" :data="item"></Goods>
		</view>
		<NoData v-if="finish&&list.length<1"></NoData>
		<LoadMore v-else :loadtype="{page, loading, finish}"></LoadMore>
	</view>
</template>

<script>
import Goods from '@/pages/mall/components/goods.vue';
export default {
	name: 'zone',
	components: {
		Goods
	},
	data(){
		return {
			type:'default',
			page:1,
			loading:false,
			finish:false,
			pullDown:false,
			list: [],
		}
	},
	onLoad(opt) {
		if(opt){
			this.type = opt.type;
		}
		uni.setNavigationBarTitle({
			title:this.type=='hot'?'热门好物':this.type=='recommend'?'精选推荐':'好物推荐'
		});
		this.getList();
	},
	onReachBottom() {
		this.getList();
	},
	onPullDownRefresh(){
		this.pullDown = true;
		this.reData();
	},
	methods: {
		// 刷新数据
		reData(){
			this.page=1;
			this.finish=false;
			this.list=[];
			this.getList();
		},
		getList(){
			if(this.finish)return false;
			if(this.loading)return false;
			this.$u.api.getGoodsListAjax({
				page:this.page,
				tags_type:this.type,
			}).then(({code,data})=>{
				console.log(code,data)
				if(this.pullDown){
					uni.stopPullDownRefresh();
					this.pullDown = false;
				}
				this.loading = false;
				let returnData = data.data;
				if(code==1){
					if(data.last_page<=data.current_page){
						this.finish = true;
					}
					returnData.forEach(e => {
						e.checked = false;
					})
					if(data.current_page==1){
						this.list = returnData;
					}else{
						this.list=this.list.concat(returnData);
					}
				}else{
					this.finish = true;
				}
				this.page++;
			}).catch(()=>{
				this.loading = false;
				this.finish = true;
				if(this.pullDown){
					uni.stopPullDownRefresh();
					this.pullDown = false;
				}
			})
		},
	}
};
</script>

<style lang="scss" scoped>
	.zone{
		// background-color: #fff;
	}
	.listbox{
		margin: 20rpx 20rpx 0;
		background-color: #fff;
	}
</style>