<template>
	<view>
		<loadlogo v-if="!loadlogo" />
		<view class="cardlist-content">
			<block v-if="!!cardList && cardList.length>0">
				<business-card :businCard_list="cardList" @chrbusinCard="chrbusinCard" :is_have="is_have"></business-card>
				<load-more :isMore="loadingMore"></load-more>
			</block>
			<block v-else>
				<none-mores></none-mores>
			</block>
		</view>
		<TabBars :tabBarAct="0" pageType="13"></TabBars>
		<far-bottom></far-bottom>
	</view>
</template>

<script>
	import App from "@/common/js/app.js"
	import businessCard from "@/components/page/pageComponents/businessCard.vue"
	import noneMores from '@/components/template/nonemores.vue'
	import Loadlogo from '@/components/template/loadlogo'
	import loadMore from '@/components/template/loadmore.vue'
	import TabBars from '@/components/template/tabBar.vue'
	export default {
		data() {
			return {
				loadlogo: false,
				cardList: [],
				loadingMore: true,
				current_page: 1,
				total: null,
				is_have: null,
			}
		},
		methods: {
			chrbusinCard(Newdata) {
				this.setData({
					cardList: Newdata
				})
			},
			getCardList(page = 1, isPage = false) {
				let _this = this,
					agencyData = _this.agencyData,
					requestData = {
						page,
						lat: agencyData.lat,
						lng: agencyData.lng,
						city_id: agencyData.areaid,
						is_collect: '1'
					};
				App._post_form('&p=citycard&do=homeList', requestData, res => {

					let cardList = res.data.list;
					_this.is_have = res.data.is_have;
					if (isPage) {
						if (cardList.length > 0) {
							_this["cardList"].push(...cardList);
						} else {
							_this.loadingMore = true;
						}
					} else {
						_this.setData({

							cardList,
							loadingMore: cardList.length === 0 || _this.current_page === res.data.total,
							total: res.data.total
						})
					}
				}, false, () => {
					_this.loadlogo = true;
				})
			}
		},
		computed: {
			agencyData() {
				return uni.getStorageSync('agencyData')
			}
		},
		components: {
			businessCard,
			noneMores,
			Loadlogo,
			loadMore,
			TabBars
		},
		onLoad(e) {
			let _this = this;
			_this.getCardList()
		},
		onReachBottom() {
			console.log('Bottom')
			let _this = this,
				{
					current_page,
					total
				} = _this;
			if (current_page >= total) {
				_this.loadingMore = true;
				return false;
			}
			_this.getCardList(++_this.current_page, true)
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}

	.cardlist-content {
		margin-bottom: 140upx;
	}
</style>
