<template>
	<view class="main">
		<navbar :config="config" backColor="#999999"></navbar>
		<welfareGoods :listData="listData" @tabChange="tabChange"></welfareGoods>
		<u-loadmore :status="loadStatus" />
	</view>
</template>

<script>
	export default{
		data(){
			return {
				config: {
					back: true,
					title: '公益福利购',
					color: '#1A1A1A',
					backgroundColor: [1, "#fff"],
					statusBarFontColor: '#1A1A1A'
				},
				// 包含【新人专区】【公益申领】
				pageParams:{
					page: 1,
					limit: 10,
					order_type: 1, // 1是综合（设置的顺序），2是新品，3价格，4销量
					order_mode: ''
				},
				listData: [],
				loadStatus: 'loadmore',//loading / nomore
			}
		},
		onLoad() {
			this.getList(true);
		},
		onPullDownRefresh() {
			this.getList(true);
			uni.stopPullDownRefresh();
		},
		methods:{
			// 获取列表
			getList(isRefresh,needLoading = false) {
				let that = this;
				if (!isRefresh && this.loadStatus == 'nomore') {
					return false;
				}
				this.pageParams.page = isRefresh ? 1 : this.pageParams.page + 1;
				this.listData = isRefresh ? [] : this.listData;
				if(needLoading){
					uni.showLoading({
						title: '努力加载中...',
						mask: true
					});
				}
				this.loadStatus = 'loading';
				this.$http.get('/goodsareafeature/welfarePage',this.pageParams)
				.then(res=>{
					if (res.code == 200) {
						let listData = that.listData;
						listData.push(...res.page.list);
						that.listData = listData;
						that.loadStatus = that.listData.length >= res.page.totalCount?'nomore':'loadmore';
					}
				})
				.finally(()=>{
					if(needLoading){
						uni.hideLoading();
					}
				})
			},
			tabChange(tab){
				this.pageParams = {
					...this.pageParams,
					order_type: tab.index+1,
					order_mode: tab.sort
				}
				this.getList(true);
			}
		},
		onReachBottom(){
			this.getList();
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		padding: 0 0 30rpx 0;
	}
</style>