<template>
	<view>
		<view class="jf flex align-center justify-between">
			<view class="jf-l">
				<view class="jf-l-t">
					当前余额
				</view>
				<view class="jf-l-b">
					{{amount || '0.00'}}
				</view>
			</view>
			<view class="jf-r" @click="withdraw()">
				提现
			</view>
		</view>
		<view class="listTitle flex align-center">
			<u-icon name="order" color="#2e2f33" size="50"></u-icon>
			<text>
				余额明细
			</text>
		</view>
		<view class="list">
			<scroll-view @scrolltolower="scrolltolower" :refresher-enabled="refresherTriggered"
				@scrolltoupper="scrolltoupper" scroll-y="true"
				style="width: 100%;height: 100%;background-color: #ffffff;padding-bottom: 30rpx;">
				<view class="list-item flex align-center justify-center" v-for="(item,index) in list" :key="index">
					<view class="list-item-box flex align-center justify-between">
						<view class="list-item-box-l">
							<view class="list-item-box-l-t">
								{{item.content}}
							</view>
							<view class="list-item-box-l-b">
								{{item.createTime}}
							</view>
						</view>
						<view class="list-item-box-r" v-if="item.type == 1">
							+{{item.num}}
						</view>
						<view class="list-item-box-r" v-else>
							-{{item.num}}
						</view>
					</view>
				</view>
				<view class="" style="width: 100%;height: 30rpx;" v-if="list.length>0"></view>
				<u-loadmore v-if="list.length>0" :status="status" />
				<empty :isShow="true" title="暂无明细" v-if="list.length == 0" />
			</scroll-view>

		</view>

	</view>
</template>

<script>
	import empty from '../../components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				boxStyle: {
					margin: 0,
					padding: '200rpx 0 0 0',
				},
				amount: 0,
				list: [],
				status: 'loadmore',
				page: 1,
				limit: 10,
				pages: 1,
				refresherTriggered: true
			};
		},
		onLoad(options) {
			console.log(options)
			if ( options && options.amount) {
				this.amount = options.amount
			}
		},
		onShow() {
			this.getAmount()
			this.getList()
		},
		onPullDownRefresh() {
			this.getAmount()
		},
		methods: {

			/**
			 * 获取当前钱包信息
			 */
			getAmount() {
				this.$Request.getT('app/moneyDetails/selectUserMoney').then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 0) {
						this.amount = res.data.amount || 0
					} else {
						this.amount = '0.00'
					}
				})
			},
			withdraw() {
				let params = {
					amount: this.amount
				}
				this.$Request.getT('app/cash/withdraw', params).then(res => {
					console.log(res)
					if (res.code == 0) {
						// this.amount = res.data.amount
					} else {
						// this.amount = '0.00'
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			/**
			 * 获取余额明细
			 */
			getList() {
				let data = {
					page: this.page,
					limit: this.limit
				}
				this.$Request.getT('app/moneyDetails/queryUserMoneyDetails', data).then(res => {
					setTimeout(() => {
						this.refresherTriggered = false
					}, 1500)
					if (res.code == 0) {
						this.pages = res.data.pages
						if (this.page < this.pages) {
							this.status = 'loadmore'
						} else {
							this.status = 'nomore'
						}
						if (this.page == 1) {
							this.list = res.data.records
						} else {
							this.list = [...this.list, ...res.data.records]
						}
					}
				})
			},
			goNav(url) {
				uni.navigateTo({
					url: url
				})
			},
			//上拉刷新
			scrolltoupper() {
				this.page = 1
				this.refresherTriggered = true
				this.getList()
			},
			//加载更多
			scrolltolower() {
				if (this.page < this.pages) {
					this.status = 'loading'
					this.page += 1
					this.getList()
				} else {
					this.status = 'nomore'
				}

			},
			
			
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.jf {
		width: 100%;
		height: 252rpx;
		background: linear-gradient(90deg, rgba(255, 117, 129, 0.6) 0%, #ff7581 100%);
		padding: 0 40rpx;

		.jf-l-t {
			color: #ffffff;
			font-size: 28rpx;
		}

		.jf-l-b {
			font-size: 40rpx;
			color: #ffffff;
			font-weight: 600;
			margin-top: 30rpx;
		}

		.jf-r {
			padding: 20rpx 40rpx;
			border-radius: 40rpx;
			color: #ff7581;
			background-color: #ffffff;
			font-size: 28rpx;
			font-weight: 500;

		}
	}

	.listTitle {
		width: 100%;
		height: 110rpx;
		margin-top: -40rpx;
		background-color: #ffffff;
		border-radius: 30rpx 30rpx 0 0;
		border-bottom: 1px solid hsla(0, 0%, 90.2%, .8);
		padding-left: 20rpx;

		text {
			color: #2e2f33;
			font-size: 32rpx;
			font-weight: bold;
			margin-left: 20rpx;
			padding-top: 8rpx;

		}
	}

	.list {
		width: 100%;
		/* #ifdef H5 */
		height: calc(100vh - 252rpx - 70rpx - 88rpx);
		/* #endif */
		/* #ifndef H5 */
		height: calc(100vh - 252rpx - 70rpx);
		/* #endif */
		background-color: #ffffff;

		.list-item {
			width: 100%;
		}

		.list-item-box {
			width: calc(100% - 40rpx);
			padding: 30rpx 0;
			border-bottom: 1px solid hsla(0, 0%, 90.2%, .8);

			.list-item-box-l-t {
				color: #2e2f33;
				font-size: 28rpx;
			}

			.list-item-box-l-b {
				font-size: 24rpx;
				color: #aeb2c1;
				margin-top: 30rpx;
			}

			.list-item-box-r {
				color: #2e2f33;
				font-weight: 600;
				font-size: 36rpx;
			}
		}
	}
</style>