<template>
	<view class="app-container">
		<view class="list-container">
			<block v-for="(item, index) in profitList" :key='index'>
				<view class="item" @tap="toDetail(item.orderId, item.orderRefundId)">
					<view class="left">
						<view class="row">订单编号：{{item.orderId}}</view>
						<view class="row">订单金额：¥{{item.payment | numToFixed}}</view>
						<view class="row">支付时间：{{item.createTime}}</view>
					</view>
					<view class="right">
						<view class="state wait" v-if="item.status == 'ING'">待结算</view>
						<view class="state over" v-if="item.status == 'OVER'">已结算</view>
						<view class="state cancel" v-if="item.status == 'CANCEL'">已取消</view>
						<view class="price" v-if="item.status !== 'CANCEL'">+{{item.amount | numToFixed}}</view>
						<view class="price" v-else></view>
					</view>
				</view>
			</block>
		</view>
		<no-data v-if="!profitList.length" :showText="'暂无记录'"></no-data>
		<loading-text v-if="profitList.length"  :loading="loading" :noMore="noMore" ></loading-text>
	</view>
</template>

<script>
	import {mapState} from 'vuex';
	
	export default {
		data() {
			return {
				profitList: [], // 收益列表
				pageNum: 1,
				pageSize: 10,
				noMore: false,
				loading: false,
			}
		},
		
		computed:{
			...mapState(['userInfo', 'isLogin', 'userId'])
		},
		
		onLoad() {
			this.getProfitList();
		},
		
		// 下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1;
			this.getProfitList();
		},
		
		// 上拉加载
		onReachBottom() {
			this.getProfitList(1);
		},
		
		methods: {
			// 获取列表
			getProfitList(loadMore) {
				if(this.noMore && loadMore)return;
				this.noMore = false
				if(!loadMore){
					this.pageNum = 1;
				}else{
					this.loading = true;
				}
				this.$axios({
					url: '/user/profit/list',
					method: 'get',
					params: {
						pageNum: this.pageNum,
						pageSize: this.pageSize,
						userId: this.userId,
						status: 'CANCEL'
					},
					isLoading: !loadMore
				}).then(res => {
					let _list = res.data.records;
					let pageTotal = res.data.pages;
					if(this.pageNum >= pageTotal){
						this.noMore = true;
					}
					if (_list.length) {
						this.pageNum += 1
					}
					if (loadMore) {
						this.profitList = this.profitList.concat(_list);
						this.loading = false;
					} else {
						this.profitList = _list;
					}
					
					uni.stopPullDownRefresh();
				})
			},
			
			toDetail(orderId, orderRefundId) {
				uni.navigateTo({
					url:'/pages/mine/profit/detail?orderId=' + orderId + '&orderRefundId=' + orderRefundId
				})
			},
		}
	}
</script>

<style lang="scss">
	.app-container {
		background: #F4F2F2;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.top-container {
		background: #FFFFFF;
		border-bottom: 1px solid #F4F2F2;
		height: 160rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		border-radius: 10rpx;
		.item {
			width: 33.33%;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			box-sizing: border-box;
			&:nth-child(2) {
				border-left: 1px solid #E5E5E5;
				border-right: 1px solid #E5E5E5;
			}
			.money {
				font-size: 40rpx;
				color: #FE781F;
				line-height: 40rpx;
			}
			.text {
				font-size: 28rpx;
				color: #666666;
				line-height: 28rpx;
				margin-top: 16rpx;
			}
		}
	}
	.out-title {
		font-size: 28rpx;
		color: #333333;
		font-weight: bold;
		padding: 20rpx 10rpx 10rpx;
		display: flex;
		justify-content: space-between;
		.right {
			font-weight: normal;
		}
	}
	.list-container {
		padding: 20rpx;
		.item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 160rpx;
			margin-bottom: 20rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0 20rpx;
			.left {
				height: 134rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.row {
					font-size: 28rpx;
					color: #666666;
				}
			}
			.right {
				height: 134rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: flex-end;
				.state {
					font-size: 28rpx;
					&.wait {
						color: #FE781F;
					}
					&.over {
						color: #3F9EFF;
					}
					&.cancel {
						color: #999999;
					}
				}
				.price {
					font-size: 32rpx;
					color: #333333;
				}
			}
		}
	}
</style>
