<template>
	<view class="center">
		<view v-for="(item,index) in applyList" class="fleet">
			<u-swipe-action>
				<u-swipe-action-item :options="options1" :disabled="item.status == '已申请'" @click="delInfo(item)">
					<!-- <view class="swipe-action u-border-top u-border-bottom flex"> -->
					<!-- 	<view class="swipe-action__content">
							<text class="swipe-action__content__text">基础使用</text>
						</view> -->
					<view class="flex">
						<view class="fleet_img">
							<u--image class="flex-end" :showLoading="true" :src="item.coverUrl" width="60px"
								height="60px" shape='circle'>
							</u--image>
						</view>
						<view class="fleet_right">
							<view class="flex">
								<view class="fleet_name">
									{{item.fleetName}}
								</view>
								<view class="btnChange flex">
									<view class="refuse" v-if="item.status == '已申请'" @click="refuse(item)">拒绝
									</view>
									<view class="adopt" v-if="item.status == '已申请'" @click="accept(item)">接受
									</view>
									<view class="fleet_invite" v-else>{{item.status}}</view>
								</view>


							</view>
						</view>
					</view>

				</u-swipe-action-item>
			</u-swipe-action>
		</view>
		<u-loadmore :status="status" :nomore-text="nomoreText" />
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				commonId: "",
				applyList: [],
				options1: [{
					text: '删除',
					style: {
						width: '145rpx',
						// height:'180rpx',
						backgroundColor: '#FE5C5C',
					}
				}],
				status: 'loadmore',
				nomoreText: '暂无记录',
				isLoadMore: false, //是否加载中
				pages: 1, //分页
				limit: 10, //每次取条目数
			}
		},
		// onPullDownRefresh() { //下拉刷新
		//     this.$refs.udb.loadData({
		//       clear: true //可选参数，是否清空数据
		//     }, () => {
		//       uni.stopPullDownRefresh()
		//     })
		//   },
		//   onReachBottom() { //滚动到底翻页
		//     this.$refs.udb.loadMore()
		//   },
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.pages += 1
				this.getList()
			}
		},
		onPullDownRefresh() {
			this.pages = 1
			this.isLoadMore = false
			this.status = 'loading'
			this.getList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShow() {

		},
		onLoad() {
			this.commonId = uni.getStorageSync("firstAuthentication").commonId
			this.read() //点击进来已读信息
			this.getList()
		},
		methods: {
			delInfo(item) {
				this.$request.baseRequest('post', '/fleetMemberInfo/api/listDelete', {
						id: item.id
					}).then(res => {
						if (res.code == 200) {
							this.$refs.uToast.show({
								type: 'success',
								message: "删除成功！",
							})
							this.getList()
						}
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			read() {
				this.$request.baseRequest('post', '/fleetMemberInfo/api/read', {
						commonId: this.commonId,
						readFlag: 2
					}).then(res => {})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			refuse(item) {
				this.$request.baseRequest('post', '/fleetMemberInfo/api/editFleetMemberInfo', {
						examineFlag: 2,
						id: item.id
					}).then(res => {
						if (res.code == 200) {
							this.$refs.uToast.show({
								type: 'success',
								message: "拒绝成功！",
								complete() {
									uni.$u.route("pages/riders/myTeam")
								}
							})
						}
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			accept(item) {
				this.$request.baseRequest('post', '/fleetMemberInfo/api/editFleetMemberInfo', {
						examineFlag: 1,
						id: item.id
					}).then(res => {
						if (res.code == 200) {
							this.$refs.uToast.show({
								type: 'success',
								message: "通过成功！",
								complete() {
									uni.$u.route("pages/riders/myTeam")
								}
							})
						}
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			getList() {
				this.status = 'loading'
				this.$request.baseRequest('get', '/fleetMemberInfo/selectFleetMemberInfo', {
						commonId: this.commonId,
						flag: 2,
						pageSize: 10,
						currentPage: this.pages
					}).then(res => {
						if (res.code == 200) {
							this.applyList = res.data.records
							if (res.data.total == 0) {
								this.status = 'nomore'
							} else {
								this.status = 'loadmore'
							}
						}
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.center {
		padding: 30rpx;
	}

	.fleet {
		margin: 30rpx 0;

		.fleet_img {
			width: 20%;
		}

		.fleet_right {
			margin-top: 20rpx;
			width: 80%;

			.fleet_name {
				width: 50%;
				margin-top: 20rpx;
				color: #333333;
				font-size: 34rpx;
				font-weight: 600;
			}

			.btnChange {
				width: 50%;
				justify-content: flex-end;
			}

			.fleet_invite {
				text-align: right;
				color: #BABABA;
				margin-right: 30rpx;
				margin-top: 20rpx;
			}

			.refuse,
			.adopt {
				padding: 10rpx 30rpx;
				height: 60rpx;
				color: #FFFFFF;
				line-height: 60rpx;
				text-align: center;
				border-radius: 40rpx;
			}

			.refuse {
				background-color: #FE5C5C;
				margin-right: 20rpx;
			}

			.adopt {
				background: #F5BA3C;
			}
		}
	}

	.u-swipe-action {
		height: 170rpx;
		border-bottom: 1px solid #E6E6E6;
	}
</style>
