<template>
	<view>
		<ujp-navbar title="退费记录"></ujp-navbar>
		<view class="balance">
			<view class="balanceHead">
				<view>
					<view class="payPrice">
						<font>{{account.availableAmountSubIncome!=null ? account.availableAmountSubIncome.toFixed(2) : '0.00'}}</font><span>元</span>
					</view>
					<view class="tips">
						<p>充值退款(元)</p><u-icon name="question-line" custom-prefix="custom-icon" color="#00B962" size="32" @click="showtip = true"></u-icon>
					</view>
				</view>
				<view v-if="account.availableAmountIncome">
					<view class="payPrice">
						<font>{{account.availableAmountIncome!=null ? account.availableAmountIncome.toFixed(2) : '0.00'}}</font><span>元</span>
					</view>
					<view class="tips">
						<p>现金分红(元)</p><u-icon name="question-line" custom-prefix="custom-icon" color="#00B962" size="32" @click="showtip2 = true"></u-icon>
					</view>
				</view>
			</view>
			<view class="balanceMain">
				<view class="balanceMain-title">
					<view class="title">
						<u-icon name="todo-fill" custom-prefix="custom-icon" color="#6BC6A7" size="40"></u-icon>
						<span>退费记录</span>
					</view>
				</view>
				<view class="refundList">
					<view class="refundList-item" v-for="(item,index) in items" :key="index" @click="refundItem(item)"> 
						<view class="refundList-row">
							<font>原路退回</font>
							<span :class=" 'state'+item.status ">{{item.statusText}}</span>
						</view>
						<view class="refundList-row" >
							<p>{{item.applicationTime}}</p>
							<p>{{item.refundAmount!=null ? item.refundAmount.toFixed(2) : '0.00'}}元</p>
						</view>
					</view>
					
					
					<!-- <view class="refundList-none">
						<u-image width="200px" height="200px" src="/static/img/none.svg"></u-image>
					</view> -->
				</view>
			</view>
		</view>	
		<view>
			<u-modal v-model="show" :title="title" :content="content"  :show-confirm-button="true" :show-cancel-button='true' @confirm="confirm"></u-modal> 
		</view>
		<view>
			<u-modal v-model="showtip" :title="title" :show-confirm-button="true" confirm-text="知道了" confirm-color="#00B962">
				<view class="slot-content">
					<rich-text :nodes="content1"></rich-text>
				</view>
			</u-modal> 
			<u-modal v-model="showtip2" :title="title" :show-confirm-button="true" confirm-text="知道了" confirm-color="#00B962">
				<view class="slot-content">
					<rich-text :nodes="content2"></rich-text>
				</view>
			</u-modal> 
		</view>
				
		<view style="bottom:0;position:absolute;width: 100%;padding: 40rpx;" v-show="account.availableAmount>0">
			
			<u-button shape="circle"  v-if="account.availableAmountIncome"
			  style="background-color:#00b962;color:white" @click="gotoRefundInfo()">申请退款</u-button>
			  
			<u-button shape="circle" v-else   style="background-color:#00b962;color:white" @click="show=true">申请退款</u-button>
			  
		</view>
	</view>
</template>

<script>
	let _self;
	import * as api from "@/apis/refund.js"
	export default {
		data() {
			return {
				elderMode:false,
				content2:`首次申请现金分红退费需填写收款人账户信息，申请成功后工作人员将在5~10个工作日内完成转账打款。`,
				
				content1:`本平台仅支持充值金额全额退费,申请成功后退费金额将于5个工作日内退还至您的充值账户.在本平台,三个月内的支付宝充值,微信支付可申请退费.<br />退费成功后,您可以在退费记录查看退费信息和审核进度.`,
				title:'提示',
				content:'是否确定提交退费申请？申请成功后退费金额将于5个工作日内退还至您的充值账户',
				show:false,
				showtip:false,
				showtip2:false,
				userId:'',
				account:{},
				items:[],
			}
		},
		onLoad(){
			_self = this;
		},
		onShow(){
			api.personAccount().then(function(res){
				if(res.result)
				{
					_self.account = res.data;
					
				}
				//('个人余额信息'+JSON.stringify(res));
			},function(err){
				uni.showToast({
					title: err,
					icon: "none"
				})
				////('err'+JSON.stringify(err));
			});
		},
		onReady(){
		
			this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
			if(this.elderMode)
				this.theme('elder')
			else
				this.theme('standard')

			if (this.carhelp.getPersonInfo()) {
				this.userId = this.carhelp.getPersonInfo().id;
				//('userId'+this.userId)
			}
 
		
			let data = {pageIndex:1,pageSize:10};
			api.personAccountRefundList(data).then(function(res){
				if(res.result){
					//('res'+JSON.stringify(res));
					_self.items = res.data.data;
					for(let i = 0;i< _self.items.length;i++){
						if(_self.items[i].refundChannel == 'wechat')
							_self.items[i].refundChannelText = "微信"
						else if (_self.items[i].refundChannel == 'alipay')
							_self.items[i].refundChannelText = "支付宝"
							
						if(_self.items[i].status == '0')
							_self.items[i].statusText = "退款中"
						else if (_self.items[i].status == '1')
							_self.items[i].statusText = "退款成功"
						else if (_self.items[i].status == '2')
							_self.items[i].statusText = "退款拒绝"
						else if (_self.items[i].status == '3')
							_self.items[i].statusText = "退款失败"
										 
					}
//					//('res'+JSON.stringify(_self.items));
				}
			},function(err){
				uni.showToast({
					title: err,
					icon: "none"
				})
				////('err'+JSON.stringify(err));
			});
		},
		methods: {
			gotoRefundInfo(){
				uni.redirectTo({
					url:'/pages/user/finance/refundInfo'
				})
			},
			theme(type) {
			  if(type == 'elder')	
			  {
				document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
				  
			  }
			  else
			  {
				document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
				  
			  } 
			},
			refundItem(item){
				uni.navigateTo({
					url:'refundDet?id='+item.id
				})
				
			},
			confirm(){
				uni.showLoading({
					
				})
				let data = {
					amount:_self.account.availableAmount
					,refundChannel:'wechat',
					applicationChannel:"E"
				}
				api.personAccountRefundApplication(data).then(function(res){
					uni.hideLoading()
					if(res.result){
						
						//('personAccountRefundApplication'+JSON.stringify(res));
						uni.redirectTo({
							url:'refundApp'
						})
						
					}
					
				},function(err){
					// uni.showToast({
					// 	title:err
					// })
						uni.hideLoading();
					uni.showModal({
							content:err,
						title:'提示',
						showCancel:false,
						confirmText:'知道了'
					})
				}
				);
				////('confirm')
			},
			showTips(){
				
			}
		}
	}
</script>

<style lang="scss" scoped> 
	@import "@/_theme.scss";
	.slot-content {
		@include themeify{
			font-size:themed('font-size2'); 
		}
/*		font-size: 28rpx;*/
		color: $u-content-color;
		padding-left: 30rpx;
		padding-right: 30rpx;
		padding-top: 40rpx;
		padding-bottom: 40rpx;
	}
	.refundList-none{
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.balanceHead{
		background-color: #fff;
		padding: 48rpx 0;
		display: flex;
		flex-direction: row;
		align-items: center;
		    justify-content: space-around;
	
		.payPrice{
			display: flex;
			align-items: flex-end;
			justify-content: center;
			font{
/*				font-size: 36px;
				line-height: 36px;*/
				@include themeify{
					font-size:themed('font-size13'); 
					line-height:themed('font-size13'); 
				}
			}
		}
		.tips{
			display: flex;
			align-items: center;
			margin-top: 8rpx;
			p{
				color:#999;
				margin-right: 8rpx;
			}
		}
	}
	.balanceMain{
		background-color: #fff;
		margin-top: 24rpx;
		.balanceMain-title{
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 96rpx;
			border-bottom: 2rpx solid #f7f7f7;
			padding: 0 32rpx;
			.title{
				display: flex;
				align-items: center;
				span{
					margin-left: 16rpx;
/*					font-size: 16px;*/
					@include themeify{
						font-size:themed('font-size3'); 
						font-weight: themed('fontWeight');
						letter-spacing: themed('letterSpacing');
 					}
				}
			}
		}
		.refundList-item{
			padding: 12px 16px;
			.refundList-row{
				display: flex;
				align-items: center;
				justify-content: space-between;
				p{
					@include themeify{
						font-size:themed('font-size1'); 
					}
/*					font-size: 12px;*/
					color:#888;
					margin-top: 6rpx;
				}
				.state0{
					color:#FF9600;
				}
				.state1{
					color:#00B962;
				}
				
				.state2{
					color:red;
				}
				.state3{
					color:red;
				}
			}
		}
		
	}
</style>
