<template>
	<view>
		<u-navbar title="提现记录"></u-navbar>
		<view class="detailed">
			<view style="text-align: center;margin-top: 100px" v-if="!list.length">
				<img src="@/assets/img/blankpage.png">
				<view>没有提现记录</view>
			</view>
			<view class="detailed-list"  
			:key="index" 
			v-for="(item ,index) in list" >
				<view class="detailed-time"  v-if="item.show">
					<p>{{showTime(item.showtime)}}</p>
					<p>共提现 {{showMap.get(item.showtime).toFixed(2)}}元</p>
				</view>
				<view class="detailed-item"  @click="gotoItem(item)" >
					<view class="detailed-item-name">
						<view class="u-flex">
							<h4>{{item.applicationTypeText}}</h4>
							 <span  :class="{
								 success:item.status==1,
								  error:item.status==2,
								   error2:item.status==0
							 }">({{item.statusText}})</span>
							
						</view>
						<p>{{item.stationName}}</p>
					</view>
					<view class="detailed-item-num">
						<h2>{{item.applicationAmount.toFixed(2)}}元</h2>
						
						<p>{{showTime2(info.createTime)}}</p>
					</view>
				</view>
			
			</view>
			<u-divider v-if="list.length&&list.length == recordsTotal" color="#B6BDC3" style="margin-top:20px;" bg-color="#f7f7f7">已经到底了</u-divider>
			
		 
		</view>
		
		<u-button  v-if="info.status" @click="gotoUrl('pagesFinance/user/applicationForWithdrawal')" >创建提现单</u-button>
	</view>
</template>

<script>
	import * as API from '@/apis/finance.js'
	
	export default {
		data() {
			return {
				pageIndex: 1,
				recordsTotal: 0,
				list: [],
				info:{},
				form: {
					name: '',
					intro: '',
				},
				showMap:null,
			 
			}
		},
		onLoad(){
			this.info=this.carhelp.getPersonInfo("merchantUser")
			
		},
		onReady() {
			this.getList()
		},
		
		onReachBottom() {
			if (this.list.length < this.recordsTotal) {
				this.myLoadmore();
			}
		},
		methods: {
			showTime(name){
				if(!name){
					return ''
				}
				return name.replace('-','年')+'月';
			},
			showTime2(name){
				if(!name){
					return ''
				}
				return name.substring(5);
			},
			gotoItem(item){
				if(item.status=='-1'){
					this.gotoUrl('pagesFinance/user/applicationForWithdrawal?id='+item.id)
				}else{
					this.gotoUrl('pagesFinance/user/applicationDetails?id='+item.id)
				}
			},
			getList() {
			
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				
				
				API.withdrawRecord({
					pageIndex:this.pageIndex
				}).then((res) => {
					
					this.list = [
						...this.list,
						...res.data.data
					];
					
					var showMap=new Map()
					this.list.forEach(item=>{
						var ktime=item.applicationMonth;
						
						if(showMap.has(ktime)){
							item.show=false;
							// var m=showMap.get(ktime)*100+item.applicationAmount*100;
							// showMap.set(ktime,m/100)
						}else{
							showMap.set(ktime,item.totalApplicationAmount)
							
							item.show=true;
							item.showtime=ktime;
						}
					})
					this.showMap=showMap;
					this.recordsTotal = res.data.recordsTotal
					uni.hideLoading()
					
				}).catch(error => {
					uni.showToast({
					
						title: error
					})
				})
			},
		}
	}
</script>
<style>
	page{
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	
	.detailed-time{
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px 20px;
		p{
			color:#666;
		}
	}
	.detailed-item{
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		padding: 10px 20px;
		border-bottom: 1px solid #ededed;
		.detailed-item-name{
			font-size: 14px;
			h4{
				
				font-weight: normal;
			}
			p{
				font-size: 12px;
				margin-top: 4px;
				color:#666;
			}
			span{
				margin-left: 10px;
			}
			.success{color:#27b148}
			.error{color:#FF6200;}
			.error2{color:#1ba7f4;}
		}
		.detailed-item-num{
			text-align: right;
			align-items: center;
			h2{
				
				
			}
		}
	}
	
	.u-btn{
		margin: 0 16px;
		position: fixed;
		bottom: 12px;
		left: 0;
		right: 0;
		height: 44px;
		line-height: 44px;
		border-radius: 8px;
		background-color: rgba(24, 90, 198, 100);
		color: rgba(255, 255, 255, 100);
	}
</style>
