<template>
	<view class="pos-r padding-lr-sm">
		<use-tabbar :tabbar="false" />

		<!-- 我的余额区域 -->
		<view class="gold-section" v-if="fetch && fetch.cash">
			<view class="item dflex dflex-flow-c">
				<text>总收益：{{fetch.cash}}</text>
			</view>
		</view>
		<!-- 记录列表 -->

		<view class="record-list margin-top-sm" v-if="fetch">
			<view class="record-title fs fwbd ft-black margin-bottom-sm">收益记录</view>
			<u-empty v-if="fetch['list'] && fetch['list'].length <= 0" marginTop="30" mode="data" text="暂无记录"></u-empty>
			
			<view v-else>
				<view class="record-item" v-for="(item, index) in fetch['list']" :key="index">
					<view class="record-left">
						<view class="record-name">{{ item.action_name }}</view>
						<view class="record-desc" v-if="item.desc">{{ item.desc }}</view>
						<view class="record-time">{{ item.cdate }}</view>
					</view>
					<view class="record-amount" :class="{ income: item.type == 1, expense: item.type == 2, lock: item.type == 3 }">
						<text v-if="item.type == 1">+</text>
						<text v-if="item.type == 3">待入账</text>
						<text>{{ item.money }}</text>
					</view>
				</view>
			</view>
		</view>

		<view class="safe-area-inset-bottom"></view>

	</view>
</template>


<script>
	export default {
		data() {
			return {
				fetch: {},
				type: 0,
				id: 0,
			}
		},
		onLoad(options) {
			this.type = options.type;
			this.id = options.id;
			if (!this.type || !this.id) {
				return Dever.goUser()
			}
		},
		onShow() {
			this.loadList(1);
		},
		//下拉刷新
		onPullDownRefresh() {
			this.loadList(1);
		},
		//加载更多
		onReachBottom() {
			this.loadList(2);
		},
		methods: {
			loadList(page) {
				this.DeverApi.page([page, 'list'], this, 'sales.getProfit', {sales_type:this.type, sales_id: this.id});
			},
		}
	}
</script>


<style lang="scss">
	.gold-section {
		background: #ffffff;
		border-radius: 24rpx;
		padding: 32rpx;

		.dflex-b {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.title {
			font-size: 32rpx;
			font-weight: bold;
			color: #333;
		}

		.link {
			font-size: 24rpx;
			color: #ff9800;
			text-decoration: underline;
		}

		.balance-number {
			margin-top: 20rpx;

			.price {
				font-size: 48rpx;
				color: #ff9800;
				font-weight: bold;
			}
		}

		.amount-summary {
			display: flex;
			justify-content: space-between;
			margin-top: 32rpx;

			.summary-item {
				flex: 1;
				display: flex;
				flex-direction: column;

				.label {
					font-size: 24rpx;
					color: #888;
				}

				.value {
					margin-top: 10rpx;
					font-size: 30rpx;
					font-weight: 600;
					color: #333;
				}
			}
		}
	}

	.card-tile {
		border-radius: 24rpx;
		padding: 30rpx;
		background: #ffffff;
		display: flex;
		align-items: center;
		justify-content: center;
		transition: all 0.2s ease-in-out;

		.icon {
			font-size: 60rpx;
			margin-right: 24rpx;
		}

		.text-content {
			display: flex;
			flex-direction: column;

			.title {
				font-size: 30rpx;
				font-weight: 600;
				color: #333;
			}

			.desc {
				font-size: 24rpx;
				color: #999;
				margin-top: 6rpx;
			}
		}

		&:active {
			transform: scale(0.97);
		}

		&:first-child {
			margin-right: 10rpx;
		}
	}

	.wpre-50 .card-tile {
		&:first-child {
			margin-bottom: 12rpx;
			margin-right: 0rpx;
		}
	}

	.record-list {
		background: #ffffff;
		border-radius: 20rpx;
		padding: 30rpx;

		.record-title {
			font-size: 30rpx;
			font-weight: bold;
			color: #333;
		}

		.record-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1px solid #f0f0f0;

			&:last-child {
				border-bottom: none;
			}

			.record-left {
				display: flex;
				flex-direction: column;

				.record-name {
					font-size: 28rpx;
					color: #333;
				}

				.record-desc {
					font-size: 28rpx;
					color: #999;
				}

				.record-time {
					font-size: 24rpx;
					color: #999;
					margin-top: 6rpx;
				}
			}

			.record-amount {
				font-size: 28rpx;
				font-weight: bold;

				&.income {
					color: #4caf50;
				}

				&.expense {
					color: #f44336;
				}
				
				&.lock {
					color: #999;
				}
			}
		}
	}

	.empty-record {
		text-align: center;
		padding: 60rpx 0;

		.empty-icon {
			width: 160rpx;
			height: 160rpx;
			margin-bottom: 20rpx;
			opacity: 0.6;
		}

		.empty-text {
			font-size: 28rpx;
			color: #999;
		}
	}
</style>