<template>
	<view class="column flex-1 hb">
		<view class="p20 bgf">
			<u-subsection :list="list" :current="actnav" @change="sectionChange" bgColor='#def1ff' inactiveColor="#666"></u-subsection>
		</view>
		<view class="column  scrolly">
			<scroll-view scroll-y="true" class="hb" :refresher-enabled="isEnabled" :refresher-triggered="triggered"
				refresher-background="rgba(0,0,0,0)" @refresherrefresh="pullDownRefresh"
				@refresherrestore="triggered = false" :upper-threshold="100" :lower-threshold="100"
				@refresherabort="triggered = false" @scrolltolower="reachBottom">
				<view v-for="(item,index) in listgood" :key="index" class="listcss" @click="getlist(item)">
					<view class="justify-between align-center">
						<view class="w180 justify-between fs28 align-center ">
							<u-avatar :src="item.fromAvatar" size="25"></u-avatar>
							<text class="ml10 single-ellipsis">{{item.fromName}}</text>
						</view>
						<view class="column align-center">
							<text class="fs24 base-color-9">更换为</text>
							<image :src="imgPath+'/app/images/jiantou.png'" class="w60 h40"></image>
						</view>
						<view class="w180 justify-between fs28 align-center ">
							<u-avatar :src="item.toAvatar" size="25"></u-avatar>
							<text class="ml10 single-ellipsis">{{item.toName}}</text>
						</view>
					</view>
					<view class="justify-between">
						<view class="fs24 base-color-9">{{item.applyTime}}</view>
						<view class="fs24 base-color-9 " style="color: orange;" v-if="actnav==0">待审核</view>
						<view class="fs24 base-color-9 base-color" v-if="actnav==1">审核通过</view>
						<view class="fs24 base-color-9 base-color-red" v-if="actnav==2">审核未通过</view>
					</view>
					
				</view>
			</scroll-view>
			<u-loadmore :status="status" />
		</view>
		<u-popup :show="show" @close="close" @open="open" :closeOnClickOverlay="true"
		mode="center" round='10'>
			<view class="poplist scrolly">
				<view class="center mb20">更换会员</view>
				<view v-for="(item,index) in nowlist" :key="index" class="mtb16" >
					<view class="justify-start align-center">
						<u-avatar :src="item.avatar" size="25"></u-avatar>
						<view class="fs28 ml16">昵称：</view>
						<view class="fs28 ">{{item.userName}}</view>
					</view>
					<view class="justify-start align-center fs24 mt8 base-color-6 ">
						<view>所属项目：</view>
						<view >{{item.projectName}}</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getchangeslist
	} from "@/api/manageCompany.js"
	export default {
		data() {
			return {
				list: ['待审核', '通过审核', '审核未通过'],
				actnav:0,
				triggered: false,
				status: 'loadmore',
				isEnabled: true,
				pageNum: 1,
				pageSize: 10,
				listgood:[],
				show:false,
				nowlist:[]
			}
		},
		onShow() {
			this.getexaminelist()
		},
		computed: {
		    imgPath() {
		      return this.$store.state.imgpath
		    }
		},
		methods: {
			getlist(item){
				this.show=!this.show
				this.nowlist=item.users
				console.log(this.nowlist)
			},
			close(){
				this.show=!this.show
				console.log(this.show)
			},
			open(){},
			pullDownRefresh() {
				// 下拉刷新
				this.triggered = true; //下拉了状态为true
				setTimeout(() => {
					this.triggered = false;
					uni.stopPullDownRefresh()
					this.pageNum = 1;
					this.getexaminelist('refresh') //触底  不穿执行else
					// 请求接口里面需要判断是不是最后一页   是最后一页 status赋值为‘loadmore’没有更多了
					// 请求接口
				}, 1000)
			},
			reachBottom() {
				// status这个是加载状态
				console.log(111);
				if (this.status === 'loadmore') {
					this.status = 'loading'
					uni.showNavigationBarLoading()
					setTimeout(() => {
						this.pageNum++
						this.getexaminelist() //触底  不穿执行else
						uni.hideNavigationBarLoading()
					}, 1000);
				}
			},
			sectionChange(index){
				this.listgood=[]
				this.actnav=index
				this.getexaminelist()
			},
			getexaminelist(type){
				this.listgood=[]
				const data={
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					status:this.actnav
				}
				getchangeslist(data).then(res=>{
					if(res.code==200){
						// refresh 下拉
						if (type == 'refresh') {
							this.listgood = res.data.list
						} else {
							// 加载更多 当前页和下一页合并
							this.listgood = [...this.listgood, ...res.data.list]
						}
						if (res.data.isLastPage) {
							this.status = 'nomore'
						} else {
							this.status = 'loadmore'
						}
					}else{
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	// page{
	// 	background-color: #fff;
	// }
	.listcss{
		background-color: #fff;
		margin: 20rpx;
		padding: 20rpx;
		border-radius: 10rpx;
	}
	.poplist{
		width: 500rpx;
		height: 600rpx;
		border-radius: 20rpx;
		padding: 20rpx;
	}
</style>
