<template>
	<view class="selSupplier">
		<view class="supplier-ul">
			<view class="supplier-li" v-for="(item, index) in werahouse_list" :key="index" @click="changeSupplier(item)">
				<view class="supplier-name">{{ item.warehouseName }}</view>
				<view class="other">
					<view class="concat clearfix">
						<text class="float_left">{{ item.contactName||'--' }}</text>
						<view class="float_right" v-if="item.contactMobile" @click.stop="callPhone(item.contactMobile)">
							<u-icon name="phone-fill" size="26"></u-icon>
							<text class="phone-text">{{ item.contactMobile }}</text>
						</view>
					</view>
					<view class="address">{{ item.area.provinceName }}-{{ item.area.cityName }}-{{ item.area.districtName }}-{{ item.area.contactAddress }}</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,
			werahouse_list: []
		};
	},
	onLoad() {
		this.getAllWarehouse();
	},
	onPullDownRefresh() {
		this.getAllWarehouse();
	},
	// 上拉加载
	onReachBottom() {
		if (this.total / this.pageSize > this.page) {
			this.page += 1;
			this.getAllWarehouse();
		}
	},
	methods: {
		changeSupplier(item) {
			// 选择供应商返回上一页
			this._prePage().werahouseData = item;
			uni.navigateBack();
		},
		search() {
			this.page = 1;
			this.getAllWarehouse();
		},
		getAllWarehouse() {
			this.loading_status = 'loading';
			this.$u.api
				.getAllWarehouse({
					page: this.page,
					pageSize: this.pageSize,
					keyword: this.keyword,
					enableStatus:5
				})
				.then(res => {
					uni.stopPullDownRefresh();
					this.total = res.pageTotal;
					if (this.page === 1) {
						this.werahouse_list = res.data;
					} else {
						this.werahouse_list = this.werahouse_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>

.supplier-ul {
	padding-bottom: 20rpx;
	.supplier-li {
		width: 702rpx;
		margin: 0 auto;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-top: 20rpx;
		.supplier-name {
			padding: 0 20rpx;
			line-height: 80rpx;
			border-bottom: 1px solid #f5f5f5;
		}
		.other {
			font-size: 24rpx;
			padding: 10rpx 20rpx;
			line-height: 50rpx;
			.concat {
				.float_right {
					color: $uni-color-primary;
					.phone-text {
						margin-left: 10rpx;
					}
				}
			}
		}
	}
}
</style>
