<template>
	<view class="content">
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<!-- 空白页 -->
			<empty v-if="navList[0].loaded === true && navList[0].orderList.length === 0"></empty>
			<!-- 订单列表 -->
			<view class="listItem flex" v-for="(item, index) in navList[0].orderList">
				<view>
					<image class="avatar" :src="item.to_user.avatar" mode="scaleToFill"></image>
				</view>
				<view class="conetnt">
					<view class="name">
						{{item.nickname}}
					</view>
					<view class="user">
						手机号：{{item.to_user.phone}}
					</view>
				</view>
				<view class="rightButtom" @click="outAuth(item)">
					解除
				</view>
			</view>
			<uni-load-more :status=" navList[0].loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import {
		del_auth_car,
		get_auth
	} from '@/api/user.js';
	export default {
		data() {
			return {
				tabCurrentIndex: 0,
				navList: [{
					state: 0,
					text: '授权用户',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				}],
				id: '',
			};
		},

		onLoad(options) {
			this.id = options.id || '';
			this.loadData();
		},
		methods: {
			// 是否取消授权
			outAuth(item) {
				uni.showModal({
					title: '提示',
					content: `是否取消${item.nickname}授权？`,
					success: res => {
						if (res.confirm) {
							uni.showLoading({
								title: '取消授权中',
								mask:true
							});
							del_auth_car({
								id:item.id
							}).then((e) => {
								uni.hideLoading()
								
							}).catch((e) => {
								console.log(e);
								uni.hideLoading()
							})
							console.log('取消授权');
						}
						
					},
				});
			},
			//获取列表
			loadData(source) {
				//这里是将订单挂载到tab列表下
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				let state = navItem.state;
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				if (navItem.loadingType === 'loading') {
					//防止重复加载
					return;
				}
				if (navItem.loadingType === 'noMore') {
					//防止重复加载
					return;
				}
				// 修改当前对象状态为加载中
				navItem.loadingType = 'loading';

				get_auth({
						car_number: this.id,
						page: navItem.page,
						limit: navItem.limit
					})
					.then(({
						data
					}) => {
						let arr = data.data.map(e => {
							return e;
						});
						navItem.orderList = navItem.orderList.concat(arr);
						// console.log(navItem.orderList);
						navItem.page++;
						if (navItem.limit == arr.length) {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'more';
							return;
						} else {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'noMore';
						}
						uni.hideLoading();
						this.$set(navItem, 'loaded', true);
					})
					.catch(e => {
						console.log(e);
					});
			},
			//订单状态文字和颜色
		}
	}
</script>

<style lang="scss">
	page,
	.content {
		height: 100%;
	}

	.list-scroll-content {
		padding-top: 30rpx;
		height: 100%;
	}

	.listItem {
		padding: $page-row-spacing;
		margin: $page-row-spacing;
		margin-top: 0;
		background-color: #FFFFFF;
		border-radius: 20rpx;

		.avatar {
			border-radius: 100rpx;
			width: 120rpx;
			height: 120rpx;

		}

		.rightButtom {
			padding: 20rpx 0;
			text-align: center;
			color: $color-red;
			border-radius: 100rpx;
			border: 1px solid $color-red;
			width: 200rpx;

		}

		.conetnt {
			padding-left: 20rpx;
			flex-grow: 1;

			.name {
				font-size: 32rpx;
				color: $font-color-dark;
			}

			.user {
				font-size: 24rpx;
				color: $font-color-disabled;
				margin-top: 30rpx;
			}


		}
	}
</style>
