<template>
	<view>
		<view class="customer-ul">
			<view class="customer-li" v-for="(item, index) in staff_list" :key="index" @click="changeSupplier(item)">
				<view class="customer-name clearfix">
					<text class="float_left">{{ item.name }}</text>
					<view class="float_right">
						<u-tag v-if="item.type === 1" size="mini" text="系统" mode="plain" type="primary" />
						<u-tag style="margin-left: 10rpx;" v-if="item.defaultStatus === 5" size="mini" text="默认" mode="plain" type="success" />
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="load_status" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			keyword: '',
			load_status: 'nomore',
			page: 1,
			pageSize: 10,
			total: 0,
			staff_list: []
		};
	},
	onLoad() {
		this.getCustomerSourceList();
	},
	onPullDownRefresh() {
		this.getCustomerSourceList();
	},
	// 上拉加载
	onReachBottom() {
		if (this.total / this.pageSize > this.page) {
			this.page += 1;
			this.getCustomerSourceList();
		}
	},
	methods: {
		changeSupplier(item) {
			// 选择返回上一页
			this._prePage().customerTypeData = item;
			uni.navigateBack();
		},
		search() {
			this.page = 1;
			this.getCustomerSourceList();
		},
		getCustomerSourceList() {
			this.loading_status = 'loading';
			this.$u.api
				.getCustomerSourceList({
					page: this.page,
					pageSize: this.pageSize
				})
				.then(res => {
					uni.stopPullDownRefresh();
					if (this.page === 1) {
						this.staff_list = res.data;
					} else {
						this.staff_list = this.staff_list.concat(res.data);
					}
					this.total = res.pageTotal;
					this.load_status = this.$utils.loadStatus(this.page,this.pageSize,this.total);
				})
				.catch(err => {
					uni.stopPullDownRefresh();
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.search-view {
	position: fixed;
	z-index: 99;
	top: 0;
	left: 0;
	width: 100%;
	background-color: #ffffff;
	border-bottom: 1px solid #f5f5f5;
	padding: 20rpx 0;
	.input-view {
		padding: 0 24rpx;
		input {
			height: 60rpx;
			line-height: 60rpx;
			padding: 0 24rpx;
			display: inline-block;
			width: 580rpx;
			border: 1px solid #f5f5f5;
			vertical-align: middle;
			border-radius: 8rpx;
			background-color: #f7f8fa;
		}
		.add-icon {
			margin-left: 14rpx;
			display: inline-block;
			vertical-align: middle;
		}
	}
}
.customer-ul {
	padding-bottom: 20rpx;
	.customer-li {
		border-bottom: 1px solid #eeeeee;
		background-color: #ffffff;
		border-radius: 10rpx;
		&:last-child{
			border-bottom: 0 none;
		}
		.customer-name {
			padding: 0 20rpx;
			line-height: 100rpx;
		}
	}
}
</style>
