<template>
	<view>
		<view class="header">
			<view class="btn" @tap="screen(0)">
				<text :class="current==0?'active':'normal'">店铺收藏</text>
			</view>
			<view class="btn" @tap="screen(1)">
				<text :class="current==1?'active':'normal'">工厂收藏</text>
			</view>
		</view>
		<view class="content" v-if="current==0">
			<ShopCell v-for="(item, index) in shops" :key="index" :item="item" :current="0"></ShopCell>
		</view>
		<view class="content" v-if="current==1">
			<ShopCell v-for="(item, index) in factorys" :key="index" :item="item" :current="1"></ShopCell>
		</view>
		<uni-load-more :status="listStatus"></uni-load-more>
	</view>
</template>

<script>
	import {
		getCollectList
	} from '@/config/api.js'
	import ShopCell from '@/pages/collect/shop-cell.vue'
	export default {
		components: {
			ShopCell,
		},
		data() {
			return {
				current: 0,
				factoryPage: 1,
				shopPage: 1,
				shops: [],
				factorys: [],
				listStatus: 'more',
			}
		},
		methods: {
			screen(index) {
				this.current = index
				if (index == 1 && this.factorys.length == 0) {
					this.getPageData()
				}
			},
			async getPageData() {
				const {
					content

				} = await getCollectList({
					page: this.current == 0 ? this.shopPage : this.factoryPage,
					current: this.current
				})

				if (this.current == 0) {
					this.shops = [...this.shops, ...content.content]
					if (content.totalPages == this.shops.length) {
						this.listStatus = 'noMore'
					}
					this.shopPage++
				} else {
					this.factorys = [...this.factorys, ...content.content]
					if (content.totalPages == this.factorys.length) {
						this.listStatus = 'noMore'
					}
					this.factoryPage++
				}
			}
		},
		onLoad() {
			this.getPageData()
		},
		onReachBottom() {
			if (this.listStatus === 'noMore') return
			this.listStatus = 'loading'
			this.getPageData()
		}
	}
</script>

<style scoped lang="scss">
	.header {
		height: 96rpx;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		overflow: hidden;
		border-bottom: 1px solid #f2f2f2;

		.btn {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-grow: 1;
			line-height: 96rpx;
			background: white;
		}

		.active {
			border-bottom: 4px solid #b60001;
		}

		.normal {
			border-bottom: 4px solid #fff;
		}
	}

	.content {}
</style>