<template>
	<view class="add_box">
		<view class="address_box" v-for="item in addressData" :key="item.name">
			<view class="address_item">
				<view class="top">
					<span>{{item.name}}</span>
					<span>{{item.phone}}</span>
					<span v-if="item.status == 0">默认</span>
					<span>{{item.label}}</span>
				</view>
				<view class="bottom">
					<view class="left_bot">
						{{item.address}}
					</view>
					<view class="right_bot">

					</view>
				</view>
			</view>
		</view>
		<uni-load-more iconType="circle" :status="status" @clickLoadMore="loadMore"
			:content-text="contentText"></uni-load-more>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressData: [],
				current: 0,
				size: 10,
				hasMore: true,
				status: '',
				contentText: {
					contentdown: "点击查看更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了",
				}
			}
		},
		onLoad() {
			let userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				this.userInfo = JSON.parse(userInfo);
				if (this.userInfo.id != undefined) {
					this.loadMore();
				}
			}
		},
		methods: {
			//加载更多
			loadMore() {
				console.log('loadmore')
				if (this.hasMore) {
					this.current = this.current + 1;
					this.staus = 'loading';
					uni.request({
						url: getApp().globalData.baseUrl + '/address/list?userId=' + this.userInfo.id + '&current=' + this
							.current + '&size=' + this.size,
						method: 'GET',
						success: (res) => {
							if (res.data.code == 200) {
								this.addressData = this.addressData.concat(res.data.data.records);
								if (res.data.data.records.length == 0 || res.data.data.total < this.size) {
									this.hasMore = false;
									this.status = 'nomore';
								} else {
									this.status = 'more';
								}
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								})
							}
						},
					})
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.add_box {
		width: 100%;
		background: #fff;

		.address_box {
			width: 95%;
			margin: 0 auto;
			margin-top: 40rpx;

			.address_item {
				width: 100%;
				height: 200rpx;
				border-bottom: 2rpx solid #ccc;

				.bottom {
					width: 100%;

					.left_bot {
						width: 90%;
					}
				}
			}
		}
	}
</style>