<template>
	<view class="selSupplier">
		<view class="search-view">
			<view class="input-view">
				<input type="text" confirm-type="search" placeholder-class="input-pl" placeholder="请输入品牌名称" v-model="keyword" />
				<u-icon class="add-icon" name="search" size="40" color="#666666" @click="search"></u-icon>
			</view>
		</view>
		<view class="supplier-ul">
			<view class="supplier-li" v-for="(item, index) in brand_list" :key="index" @click="changeBrand(item)">
				<view class="supplier-name">{{ item.title }}</view>
				<view class="other">
					{{item.code}}
				</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,
			brand_list: []
		};
	},
	onLoad() {
		this.getAllBrand();
	},
	onPullDownRefresh() {
		this.getAllBrand();
	},
	// 上拉加载
	onReachBottom() {
		if (this.total / this.pageSize > this.page) {
			this.page += 1;
			this.getAllBrand();
		}
	},
	methods: {
		changeBrand(item) {
			// 选择供应商返回上一页
			this._prePage().brandData = item;
			uni.navigateBack();
		},
		search() {
			this.page = 1;
			this.getAllBrand();
		},
		getAllBrand() {
			this.loading_status = 'loading';
			this.$u.api
				.getAllBrand({
					page: this.page,
					pageSize: this.pageSize,
					keyword: this.keyword
				})
				.then(res => {
					uni.stopPullDownRefresh();
					this.total = res.pageTotal;
					if (this.page === 1) {
						this.brand_list = res.data;
					} else {
						this.brand_list = this.brand_list.concat(res.data);
					}
					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;
		}
	}
}
.supplier-ul {
	padding-top: 90rpx;
	padding-bottom: 20rpx;
	.supplier-li {
		width: 702rpx;
		margin: 0 auto;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-top: 20rpx;
		line-height: 50rpx;
		padding: 20rpx;
		.other {
			font-size: 24rpx;
		}
	}
}
</style>
