<template>
	<view class="pos-r padding-lr-sm" v-if="fetch && fetch.info" @click="Dever.close()">
		<use-tabbar :tabbar="false" />

		<!-- 我的余额区域 -->
		<view class="gold-section">

			<view class="dflex-b">

				<u-popover position="right" width="200px" v-if="fetch.info.exp > 0">
					<view class="title">{{fetch.info.name}}
						<view style="margin-left:5px;display: inline-block;">
							<u-icon name="question-circle"></u-icon>
						</view>
					</view>

					<template v-slot:content>
						<view style="color: white;">
							<u-parse :content="fetch.info.exp_tip"></u-parse>
						</view>

					</template>
				</u-popover>

				<view class="title" v-else>{{fetch.info.name}}</view>
				<!--
				<text class="link" @click="goToExplain">{{fetch.info.name}}说明</text>
				-->

			</view>


			<view class="balance-number margin-top-sm">
				<text class="price" v-if="fetch.user.status == 1">
					{{fetch.user.yue}}
				</text>
				<text class="price" v-if="fetch.user.status == 2">
					{{fetch.user.yue}} <span style="color:#bababa;margin-left:20rpx">[封]</span>
				</text>
			</view>

			<view class="dflex-b amount-summary">
				<view class="summary-item">
					<view class="label">入账</view>
					<view class="value">{{fetch.user.total}}</view>
				</view>
				<view class="summary-item">
					<view class="label">出账</view>
					<view class="value">{{fetch.user.used}}</view>
				</view>
				<view class="summary-item">
					<view class="label">冻结</view>
					<view class="value">{{fetch.user.frozen}}</view>
				</view>
			</view>
		</view>

		<!-- 功能卡片 -->
		<view class="dflex-b margin-top-sm" style="align-items: stretch;" v-if="fetch.info.button == 1">
			<view class="card-tile flex1" v-if="fetch.info.recharge == 1"
				@click="Dever.location('score/recharge?id=' + id)">
				<view class="iconfont iconmingxi icon" style="color: #ff696b;"></view>
				<view class="text-content">
					<view class="title">充值</view>
					<view class="desc">查看充值记录</view>
				</view>
			</view>

			<view class="card-tile flex1" v-if="fetch.info.withdraw == 1"
				@click="Dever.location('score/withdraw?id=' + id)">
				<view class="iconfont iconmingxi icon" style="color: #6f96f1;"></view>
				<view class="text-content">
					<view class="title">提现</view>
					<view class="desc">查看提现记录</view>
				</view>
			</view>

			<view class="card-tile flex1" v-if="fetch.info.exchange == 1"
				@click="Dever.location('score/exchange?id=' + id)">
				<view class="iconfont iconmingxi icon" style="color: #ffbc49;"></view>
				<view class="text-content">
					<view class="title">兑换</view>
					<view class="desc">查看兑换记录</view>
				</view>
			</view>

		</view>

		<view class="dflex-b margin-top-sm" style="align-items: stretch;" v-if="fetch.info.button == 2">
			<view class="card-tile wpre-50 dflex-flow-c">
				<view class="desc">待审：<text class="price">{{fetch.user.withdraw_cash}}</text></view>
				<view class="dflex margin-top-sm" @click="Dever.location('score/withdraw?id=' + id)">
					<view class="iconfont iconmingxi icon" style="color: #6f96f1;"></view>
					<view class="text-content">
						<view class="title">提现</view>
						<view class="desc">查看提现记录</view>
					</view>
				</view>
			</view>

			<view class="wpre-50 ">
				<view class="card-tile" @click="Dever.location('score/recharge?id=' + id)">
					<view class="iconfont iconmingxi icon" style="color: #ff696b;"></view>
					<view class="text-content">
						<view class="title">充值</view>
						<view class="desc">查看充值记录</view>
					</view>
				</view>

				<view class="card-tile" @click="Dever.location('score/exchange?id=' + id)">
					<view class="iconfont iconmingxi icon" style="color: #ffbc49;"></view>
					<view class="text-content">
						<view class="title">兑换</view>
						<view class="desc">查看兑换记录</view>
					</view>
				</view>
			</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-subsection :list="list" :current="current" @change="sectionChange" activeColor="#f56c6c"></u-subsection>

			<u-empty v-if="fetch['list_' + current] && fetch['list_' + current].length <= 0" marginTop="30" mode="data"
				text="暂无记录"></u-empty>

			<view v-else>
				<view class="record-item" v-for="(item, index) in fetch['list_' + current]" :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.amount }}</text>
					</view>
				</view>
			</view>
		</view>

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

	</view>
</template>


<script>
	export default {
		data() {
			return {
				list: ['全部', '入账', '出账', '冻结'],
				fetch: {},
				id: 0,
				current: 0,
			}
		},
		onLoad(options) {
			if (options && options.id) {
				this.id = options.id;
			} else {
				this.Dever.location('source/home');
				return;
			}
		},
		onShow() {
			this.loadData();
			this.loadList(1);
		},
		//下拉刷新
		onPullDownRefresh() {
			this.loadList(1);
		},
		//加载更多
		onReachBottom() {
			this.loadList(2);
		},
		methods: {
			loadData() {
				this.DeverApi.get(this, 'score.info', {
					id: this.id
				});
			},
			loadList(page) {
				this.DeverApi.page([page, 'list_' + this.current], this, 'score.log', {
					id: this.id,
					type: this.current
				});
			},
			sectionChange(index) {
				this.current = index;
				this.loadList(1)
			}
		}
	}
</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>