<template>
	<view class="">
		<!-- <view style="width: 100%;position: fixed;top: 0;z-index: 99;">
			<view class="title-box">
				<uni-search-bar class="uni-mt-10" radius="5" placeholder="请输入名称和手机号查询" cancelButton="none"
					@confirm="search" />
			</view>
		</view> -->
		<view>
			<view style="overflow:scroll;">
				<view class="list-1" v-for="item in userList" :key="item" @tap="clickList(item)"
					style="display: flex;flex-direction: column;height: auto;min-height: 240rpx;padding-bottom: 20rpx;">
					<view class="name-tel" style="width: 100%;">
						<text style="line-height: 75rpx;">{{item.shipperOrReceiverName}}</text>
						<text>{{item.mobile == null?'':item.mobile}}</text>
					</view>
					<view class="name-tel" style="width: 100%;display: flex;flex-direction: column;height:auto;font-size: 30rpx;">
						<text>{{item.addressInfo}}</text>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				pageNum: 1,
				userList:[],
				pages:1,
				userType:'' //是从发货人点进来的还是收货人点进来的
			}
		},
		onReachBottom() {
			if (this.pageNum >= this.pages) return;
			this.status = 'loading';
			this.pageNum++
			this.getUSerList();
		},
		onShow(){
			this.getUSerList()
		},
		onLoad(option) {
			this.userType = option.userType
		},
		methods: {
			//点击选择列表，带参数 返回上一页
			clickList(item) {
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2];
					item.userType = this.userType
					prevPage.$vm.userData = item
					uni.navigateBack({
						delta: 1
					})
			},
			//获取地址簿列表
			getUSerList(){
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsAddressBook/getLogisticsAddressBookPageList',
					data:{
						pageNum:this.pageNum,
						pageSize:10,
						mobile: "",
						keyWord: "",
						companyId:uni.getStorageSync('transCompany'),
						addressType:this.userType=='ji'?1:2
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST',
					dataType: 'json',
					success: (res) => {
						this.status = 'loading';
						if(res.data.code == 401){
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200){
							this.status = 'nomore';
							if (this.pages == 1) {
								this.userList = res.data.result.records
							} else {
								this.userList = [...this.userList, ...res.data.result.records]
							}
							this.pages = res.data.result.pages
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			// //顶部搜索框
			// search(res) {
			// 	this.pages = 1
			// 	this.searchName = res.value
			// 	this.userList = []
			// 	this.getPeopleType()
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.list-1 {
		display: flex;
		height: 150rpx;
		border-bottom: 1px solid #eee;
		background: #fff;
		font-size: 32rpx;
		margin: 20rpx auto 0;
		width: 95%;
		padding-left: 30rpx;
		position: relative;
	}
	.name-tel {
		width: 75%;
		display: flex;
		flex-direction: column;
		height: auto;
		font-size: 15px;
	}
	.title-box {
		background: #fff;
	}
</style>
