<template>
	<view class="container" style="position: relative;">
		<view class="top" >
			<text class="iconfont icon-youjiantou zuojiantou" @click="goBack()"></text>
			<text>兑换记录</text>
		</view>
		<view class="record_wrapper" v-if="cffpFortuneDeductionList?.length > 0">
			<view class="recordContent" v-for="(item,index) in cffpFortuneDeductionList" :key="index">
				<image :src="item.deductionUrl" mode="widthFix"></image>
				<view class="detail">
					<h4>{{item.productTypeName}}</h4>
					<view class="">
						{{item.deductionDate}}
					</view>
					<view style="color: #0A2F99;" v-if="item.reviewStatus == 2 && !item.reviewMessage">
						兑换失败
					</view>
					<view style="color: #0A2F99;" v-if="item.reviewStatus == 2 && item.reviewMessage">
						兑换失败,原因: {{item.reviewMessage}}
					</view>
					<view style="color: #0A2F99;" v-else-if="item.productType == '1' && item.reviewStatus == 1">
						兑换成功
					</view>
					<view style="color: #0A2F99;" v-else-if="item.productType == '2' && item.reviewStatus == 1 && item.isPaid == 1 && item.status == 1">
						兑换成功
					</view>
					<view style="color: #0A2F99;" v-else>
						兑换中
					</view>
				</view>
				<view class="score" @click="toWithdralDtl(item)">
					-{{item.integralExchange}}积分
					<text v-if="item.productType=='2' || item.productTypeName=='兑换提现'">></text>
				</view>
			</view>
		</view>
		<view class="noListTip" v-else>暂无数据！</view>
	</view>
</template>

<script>
	import api from '../../api/api';
	export default{
		data(){
			return {
				userId: uni.getStorageSync('cffp_userId'),
				cffpFortuneDeductionList:[],
			}
		},
		components:{},
		onLoad(){
			this.findByUserIdForWithdralHis()
		},
		methods:{
			findByUserIdForWithdralHis(){
				api.findByUserIdForWithdralHis({userId:this.userId}).then((res)=>{
					if(res['success']){
						this.cffpFortuneDeductionList = res['data']['cffpFortuneDeductionList']
					}
				})
			},
			toWithdralDtl(item){
				if(item.productType == '2' || item.productTypeName =='兑换提现' ){
					uni.navigateTo({
						url:`/pages/withdrawal/withdrawalDetail?partnerTradeNo=${item.partnerTradeNo}`
					})
				}
			},
			goBack(){
				let back = getCurrentPages();  
					if(back && back.length>1) {
						uni.navigateBack({  
						delta: 1  
						});
					}else{
						history.back();  
				}
			}
		}
	}
</script>

<style lang="scss">
	.container{
		height:100%;
		.top{
			display: flex;
			height: 80rpx;
			justify-content: space-between;
			align-items: center;
			position: relative;
			width: 100%;
			margin: 0 auto;
			background: #fff;
			text:nth-child(2){
				width: 100%;
				text-align: center;
				position: absolute;
			}
		}
	}
	.record_wrapper{
		margin-top:0rpx;
		.recordContent{
			display: flex;
			margin-bottom: 20rpx;
			background: #fff;
			justify-content: space-between;
			padding: 30rpx;
			align-items: center;
			uni-image {
			    width: 28%!important;
				border-radius: 10rpx;
			}
			.detail{
				width: 40%;
				h4{
					margin-bottom: 20rpx;
				}
				view{
					color: #666;
				}
			}
			.score{
				width: 28%;
				color: #06A632;
				text-align: right;
			}
		}
	}
</style>