<template>
	<view class="wallet">
		<view class="a">
			<view class="fl">总资产(元)<text>{{userInfo.money}}</text></view>
			<view class="fr" @click="openPage()">提现</view>
		</view>
		<view class="b">
			<view class="title">收入明细</view>
			<view class="list">
				<view class="item" v-for="(a,i) in list" :key="i">
					<view class="hd">用户查看事件<text>+{{a.money}}</text></view>
					<view class="bd">
						<view class="dd">
							<view class="l">事件标题</view>
							<view class="r">{{a.memo}}</view>
						</view>
						<view class="dd">
							<view class="l">支付时间</view>
							<view class="r">{{a.createtime}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="empty" v-if="total == 0">
				<image src="https://www.lijkj.cn/static/empty.png"></image>
				<view class="txt">暂无数据 ~</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {},
				list: [],
				offset: 1,
				total: 1,
			};
		},
		mounted() {
			this.getList();
		},
		onReachBottom() {
			const that = this;
			uni.showLoading({
				title: "加载中"
			})
			if(that.list.length <= that.total){
				that.offset ++
				setTimeout(()=>{
					that.getList(1)
				},1000)
			}
		},
		onShow() {
			this.getUserInfo();
		},
		methods:{
			//数组对象去重
			arrayUnique (arr, name) {
				var hash = {};
				return arr.reduce(function (item, next) {
					hash[next[name]]
						? ""
						: (hash[next[name]] = true && item.push(next));
					return item;
				}, []);
			},
			async getList(type) {
				const { code, data, msg } = await this.$api.getshourulist({
					offset: this.offset,
					limit: 20,
					token: uni.getStorageSync("token")
				})
				if(type==1){
					uni.hideLoading();
				}
				if(code == 1){
					this.list = this.arrayUnique([...this.list,...data.rows],'id');
					this.total = data.total;
				}
			},
			//获取用户信息
			async getUserInfo() {
				const { code, data , msg } = await this.$api.getMemberInfo({token: uni.getStorageSync("token")});
				if(code == 1){
					this.userInfo = data.user;
				}else{
					uni.showToast({
						title: msg,
						icon: "none",
					})
				}
			},
			openPage() {
				uni.navigateTo({
					url: "/pages/user/withdrawal"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.wallet{
	padding: 0 25rpx 25rpx;
	overflow: hidden;
	.empty{
		padding: 150rpx 0;
		text-align: center;
		font-size: 26rpx;
		color: #666;
		image{
			width: 460rpx;
			height: 400rpx;
			margin-bottom: 30rpx;
		}
	}
	.b{
		.title{
			padding: 25rpx 0;
			font-weight: 500;
			font-size: 32rpx;
			color: #222222;
		}
		.item{
			width: 100%;
			height: 210rpx;
			background: #FFFFFF;
			box-shadow: 0px 3rpx 10rpx 0px rgba(9,44,39,0.05);
			border-radius: 20rpx;
			padding: 30rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
			&:first-child{
				margin-top: 0;
			}
			.hd{
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;
				text{
					font-weight: 500;
					font-size: 28rpx;
					color: #D80C0C;
				}
			}
			.bd{
				margin-top: 10rpx;
				overflow: hidden;
				.dd{
					padding: 13rpx 0;
					display: flex;
					align-items: center;
					.l{
						width: 160rpx;
						font-weight: 500;
						font-size: 28rpx;
						color: #999999;
					}
					.r{
						flex: 1;
						font-weight: 500;
						font-size: 28rpx;
						color: #333333;
					}
				}
			}
		}
	}
	.a{
		width: 100%;
		height: 180rpx;
		background: #00C6A9;
		border-radius: 20rpx;
		padding: 40rpx 50rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		.fl{
			font-weight: 400;
			font-size: 24rpx;
			color: #FFFFFF;
			text-align: left;
			line-height: 50rpx;
			text{
				display: block;
				font-weight: 400;
				font-size: 48rpx;
				color: #FFFFFF;
				margin-top: 10rpx;
			}
		}
		.fr{
			width: 160rpx;
			line-height: 50rpx;
			text-align: center;
			background: #FFFFFF;
			border-radius: 50px;
			border: 1px solid #FFFFFF;
			font-weight: 400;
			font-size: 24rpx;
			color: #00C6A9;
			text-align: center;
		}
	}
}
</style>
