<template>
	<view class="main pt0">
		<view class="search">
			<u-search placeholder="搜索企业" v-model="param.name" bgColor="white" @search="refresh()" @clear="(param.name = ''), refresh()" :showAction="false"></u-search>
		</view>
		<view class="tab">
			<u-tabs :list="tab" @click="tabClick"></u-tabs>
			<view class="filters" @click="go('/pages/job/position/city')">
				<text class="icon">&#xe64b;</text>
				<text>{{ param.cityName || '南宁市' }}</text>
			</view>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/job/enterprise/detail?id=' + item.id)">
				<view class="title omit">{{ item.name }}</view>
				<view class="desc">
					<text class="icon">&#xe64f;</text>
					<text>{{ item.regionName }} · 招聘岗位：{{ item.positions }}</text>
				</view>
				<view class="distance" v-if="item.distance">距离你{{ item.distance }}km</view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			ip: this.http.ip,
			tab: [
				{ name: '最新', orderBy: 'id', recommend: '' },
				{ name: '推荐', orderBy: 'id', recommend: 1 },
				{ name: '附近', orderBy: 'distance', recommend: '' }
			],
			list: [],
			param: { pageNum: 1, pageSize: 10, orderBy: 'id' },
			loadMore: true,
			show: false
		};
	},
	onLoad(e) {
		if (this.getLocation()) {
			this.param.latitude = this.getLocation().latitude;
			this.param.longitude = this.getLocation().longitude;
		}
		uni.$on('select_city', (res) => {
			this.param.cityName = res.title;
			this.param.regionId = res.id;
			this.refresh();
		});
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/enterprise/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					this.list.push(...res.data.rows);
				}
			});
		},
		tabClick(e) {
			this.param.orderBy = e.orderBy;
			this.param.recommend = e.recommend;
			this.refresh();
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.scroll {
	background-color: white;
	margin-bottom: 10px;
	overflow: hidden;
	border-radius: 5px;
	padding-top: 10px;
	.gg {
		.title {
			font-size: 15px;
		}
	}
	.sitem {
		float: left;
		width: 90px;
		text-align: center;
		font-size: 14px;
		padding: 8px;
		image {
			width: 60px;
			height: 60px;
			border-radius: 8px;
		}
	}
}
.item {
	background-color: white;
	border-radius: 5px;
	padding: 12px;
	margin-bottom: 10px;
	.title {
		font-weight: bold;
		.icon {
			color: $main-color;
			padding-right: 5px;
		}
	}
	.desc {
		font-size: 14px;
		color: $font-c;
		padding-top: 7px;
		.icon {
			color: $main-color;
			padding-right: 3px;
		}
	}
	.distance {
		float: right;
		margin-top: -18px;
		font-size: 14px;
		color: $font-c;
	}
}
</style>
