<template>
	<div class="income">
		<view class="list">
			<view class="tabs">
				<view class="tabsItem" :class="{'active': tabsIndex === index}" v-for="(item,index) in tabs" :key="index" @click="handlechange(item, index)">{{ item }}</view>
			</view>
			<view class="all">
				<view class="incomeList">
					<view class="listItem" v-for="(item, index) in incomeList" :key="index">
						<view class="date">{{ item.date }}</view>
						<view class="subList">
							<view class="subItem" v-for="(sub, subindex) in item.records" :key="subindex">
								<view class="top">
									<view class="left">
										<view class="name">提现申请</view>
										<view :class="{'one': sub.nStatus == 0, 'two': sub.nStatus == 1, 'three': sub.nStatus == 2}">{{ sub.nStatus == 0?'审核中':sub.nStatus == 1?'已通过':'已驳回' }}</view>
									</view>
									<view class="right">
										+{{ sub.wprice }}
									</view>
								</view>
								<view class="bottom">
									<view class="subDate">{{ sub.dtCreateTime }}</view>
									<view v-if="sub.nStatus == 2" class="reason" @click="viewReason(sub)">查看理由<u-icon name="arrow-right" size="24rpx" top="1" color="#999"></u-icon></view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="pending">
				<view class="incomeList">
					<view class="listItem" v-for="(item, index) in incomeList" :key="index">
						<view class="date">{{ item.date }}</view>
						<view class="subList">
							<view class="subItem" v-for="(sub, subindex) in item.list" :key="subindex">
								<view class="top">
									<view class="left">
										<view class="name">提现申请</view>
										<view :class="{'one': sub.nStatus == 0, 'two': sub.nStatus == 1, 'three': sub.nStatus == 2}">{{ sub.nStatus == 0?'审核中':sub.nStatus == 1?'已通过':'已驳回' }}</view>
									</view>
									<view class="right">
										+{{ sub.wprice }}
									</view>
								</view>
								<view class="bottom">
									<view class="subDate">{{ sub.dtCreateTime }}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="pass">
				<view class="incomeList">
					<view class="listItem" v-for="(item, index) in incomeList" :key="index">
						<view class="date">{{ item.date }}</view>
						<view class="subList">
							<view class="subItem" v-for="(sub, subindex) in item.list" :key="subindex">
								<view class="top">
									<view class="left">
										<view class="name">提现申请</view>
										<view :class="{'one': sub.nStatus == 0, 'two': sub.nStatus == 1, 'three': sub.nStatus == 2}">{{ sub.nStatus == 0?'审核中':sub.nStatus == 1?'已通过':'已驳回' }}</view>
									</view>
									<view class="right">
										+{{ sub.wprice }}
									</view>
								</view>
								<view class="bottom">
									<view class="subDate">{{ sub.dtCreateTime }}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="cancel">
				<view class="incomeList">
					<view class="listItem" v-for="(item, index) in incomeList" :key="index">
						<view class="date">{{ item.date }}</view>
						<view class="subList">
							<view class="subItem" v-for="(sub, subindex) in item.list" :key="subindex">
								<view class="top">
									<view class="left">
										<view class="name">提现申请</view>
										<view :class="{'one': sub.nStatus == 0, 'two': sub.nStatus == 1, 'three': sub.nStatus == 2}">{{ sub.nStatus == 0?'审核中':sub.nStatus == 1?'已通过':'已驳回' }}</view>
									</view>
									<view class="right">
										+{{ sub.wprice }}
									</view>
								</view>
								<view class="bottom">
									<view class="subDate">{{ sub.dtCreateTime }}</view>
									<view class="reason" @click="viewReason(sub)">查看理由<u-icon name="arrow-right" size="24rpx" top="1" color="#999"></u-icon></view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view>
			<uni-popup ref="popup" type="dialog">
				<view class="reasonText">
					<view class="title">驳回理由</view>
					<view class="words">
						{{ reasonText }}
					</view>
					<view class="btn" @click="closePopup">关闭</view>
				</view>
			</uni-popup>
		</view>
	</div>
</template>

<script>
	import { withDraw } from '@/api/index.js'
	export default {
		data() {
			return {
				tabs: [
					'全部','审核中','已通过','已驳回'
				],
				tabsIndex: 0,
				incomeList: [],
				reasonText: ''
			}
		},
		onShow() {
			this.getWthDraw()
		},
		methods:{
			viewReason(sub) {
				this.reasonText = sub.reject
				this.$refs.popup.open()
			},
			closePopup() {
				this.$refs.popup.close()
			},
			handlechange(item, index) {
				this.tabsIndex = index
				this.getWthDraw()
			},
			getWthDraw() {
				let obj = null
				if(this.tabsIndex == 1) {
					obj = {
						nStatus: 0
					}
				}
				if(this.tabsIndex == 2) {
					obj = {
						nStatus: 1
					}
				}
				if(this.tabsIndex == 3) {
					obj = {
						nStatus: 2
					}
				}
				withDraw(obj).then(res => {
					if(res.data.code == 200) {
						if(res.data.data && res.data.data.length > 0) {
							this.incomeList = res.data.data
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.income{
		width: calc(100vw - 76rpx);
		height: calc(100vh - 60rpx);
		padding: 30rpx 38rpx;
		background: linear-gradient(152deg, #DCFFF8 0%, #F1FEFF 100%);
		.list{
			width: 100%;
			height: 100%;
			background: #ffffff;
			border-radius: 10rpx;
			overflow: hidden;
			.tabs{
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 18rpx 24rpx;
				.tabsItem{
					padding: 0 26rpx;
					border-bottom: 4rpx solid #ffffff;
				}
				.active{
					border-bottom: 4rpx solid #03C1B8;
				}
			}
			.all, .pending, .pass, .cancel{
				height: calc(100% - 100rpx);
				overflow-y: auto;
				.incomeList{
					.listItem{
						width: 100%;
						padding: 0 24rpx;
						.date{
							color: #333333;
							margin: 24rpx 0 16rpx;
						}
						.subList{
							.subItem{
								margin-bottom: 16rpx;
								.top{
									width: 100%;
									display: flex;
									align-items: center;
									justify-content: space-between;
									color: #333333;
									font-size: 28rpx;
									.left{
										display: flex;
										width: 70%;
										align-items: center;
										justify-content: flex-start;
										.name{
											margin-right: 16rpx;
											max-width: 70%;
											overflow: hidden;
											white-space: nowrap;
											text-overflow: ellipsis;
										}
										.one{
											padding: 4rpx;
											background: #EEEEEE;
											border-radius: 4rpx;
											font-size: 20rpx;
										}
										.two{
											padding: 4rpx;
											background: #ECFEFD;
											border-radius: 4rpx;
											font-size: 20rpx;
											color: #03C8BE;
										}
										.three{
											padding: 4rpx;
											background: #FFECE6;
											border-radius: 4rpx;
											font-size: 20rpx;
											color: #F16336;
										}
									}
								}
								.bottom{
									display: flex;
									align-items: center;
									justify-content: space-between;
									font-size: 24rpx;
									color: #999999;
									.subDate{
										margin-top: 8rpx;
									}
									.reason{
										display: flex;
										align-items: center;
										justify-content: flex-end;
									}
								}
							}
						}
					}
				}
			}
		}
		.reasonText{
			width: 80vw;
			background: #ffffff;
			border-radius: 10rpx;
			overflow: hidden;
			.title{
				background: #E6F8F7;
				line-height: 92rpx;
				text-align: center;
				font-size: 32rpx;
			}
			.words{
				text-align: center;
				margin: 64rpx 0;
			}
			.btn{
				width: 80%;
				line-height: 68rpx;
				background: linear-gradient( 90deg, #1AD7CE 0%, #21C9C1 100%);
				border-radius: 106rpx 106rpx 106rpx 106rpx;
				margin: 24rpx auto;
				text-align: center;
				color: #ffffff;
			}
		}
	}
</style>
