<template>
	<view>
		<view class="customer-ul">
			<view class="customer-li" v-for="(item, index) in account_list" :key="index" @click="changeSupplier(item)">
				<view class="customer-name">{{ item.name }}</view>
				<view class="accountNumber">{{ item.accountNumber }}</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,
			account_list: [],
			shopId: ''
		};
	},
	onLoad(options) {
		if (options.shopId) {
			this.shopId = options.shopId;
		}
		this.getAllAccount();
	},
	onPullDownRefresh() {
		this.getAllAccount();
	},
	// 上拉加载
	onReachBottom() {
		if (this.total / this.pageSize > this.page) {
			this.page += 1;
			this.getAllAccount();
		}
	},
	methods: {
		changeSupplier(item) {
			// 选择返回上一页
			this._prePage().AccountData = item;
			uni.navigateBack();
		},
		search() {
			this.page = 1;
			this.getAllAccount();
		},
		getAllAccount() {
			this.loading_status = 'loading';
			this.$u.api
				.getAllAccount({
					page: this.page,
					pageSize: this.pageSize,
					enableStatus: 5,
					shopId: this.shopId
				})
				.then(res => {
					uni.stopPullDownRefresh();
					if (this.page === 1) {
						this.account_list = res.data;
					} else {
						this.account_list = this.account_list.concat(res.data);
					}
					this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
					this.total = res.pageTotal;
				})
				.catch(err => {
					uni.stopPullDownRefresh();
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.customer-ul {
	padding-bottom: 20rpx;
	.customer-li {
		border-bottom: 1px solid #eeeeee;
		background-color: #ffffff;
		border-radius: 10rpx;
		padding: 20rpx;
		&:last-child {
			border-bottom: 0 none;
		}
		.customer-name {
			padding-bottom: 10rpx;
		}
		.accountNumber {
			font-size: 24rpx;
			color: #999999;
		}
	}
}
</style>
