<template>
	<view>
		<u-picker v-model="showTime" mode="time" :params="params" :default-time="defaultTime" @confirm="confirmTime"></u-picker>
		<view class="top">
			<view class="value">
				<text>积分余额</text>
				<text>{{pointValue}}</text>
			</view>
		</view>
		<view class="data">
			<view class="left">
				<view @click.stop="showTime = true">
					<text>{{defaultTime}}</text>
					<text class="cuIcon-unfold padding-left-10"></text>
				</view>
				<!-- <view>
					<text>支出 ￥ 165.00 收入 ￥ 463.00</text>
				</view> -->
			</view>
			<view class="right" @click="$jump('/pagesA/pages/my-balance/statistics')">
				<text>统计</text>
				<text class="cuIcon-right"></text>
			</view>
		</view>

		<view class="card">
			<mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
				:up="upOption">
				<view @click="$jump('/pagesA/pages/bill/bill-detail?billDetail='+JSON.stringify(item)+'&type=balance')" class="item" hover-class="hoverClass"
					v-for="(item,index) in list" :key="index">
					<view class="area1">
						<view class="item-padding">
							<image  :src="item.logo" style="border-radius: 50%;" mode="aspectFit"></image>
							<view class="">
								<text>{{item.name}}</text>
								<text>{{item.updateTime}}</text>
							</view>
						</view>
					</view>
					<view  class="area3 text-area u-flex-1" >
						<view class="item-padding" style="text-align: right;flex:1;font-size: 34rpx;color: #F39248;margin-right: 20rpx;">-￥{{item.totalPrice}}</view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				list:[],
				downOption:{
					auto:false
				},
				showTime:false,
				params: {
					year: true,
					month: true,
				},
				defaultTime:'',
				pointValue:'',
				height:''
			}
		},
		onLoad(options) {
			if(options.pointValue){
				this.pointValue = options.pointValue
			}
			this.defaultTime =this.$dateTime.format(new Date(),'YYYY-mm')
		},
		onReady() {
			this.getElInfo()
		},
		methods: {
			async getElInfo() {
				let rectInfo = await this.$u.getRect('.card');
				this.height = this.$u.sys().windowHeight - rectInfo.top + 'px'
			},
			confirmTime(e){
				this.defaultTime = e.year + '-' +e.month
				this.mescroll.resetUpScroll();
			},
			upCallback(mescroll) {
				let params = {
					current:mescroll.num,
					size:mescroll.size,
					payId:this.vuex_userId,
					payStatus:'付款成功'
				}
				if (this.defaultTime) {
					params.createTime = this.$dateTime.format(new Date(this.defaultTime))
				} else {
					params.createTime = this.$dateTime.format(new Date())
				}
				
				try {
					this.$api.balanceBills.list(params).then(res => {
						let data = res.data.records
						let total = res.data.total
						mescroll.endBySize(data.length, total);
						if (mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(data); //追加新数据
					})
				} catch (e) {
					this.mescroll.endErr()
				}
			},
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
					this.$u.toast('刷新成功')
				},500)
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	
	.btn {
		background-color: #FC8D38;
		color: #FFFFFF;
		border-radius: 50rpx;
		border: 1rpx solid #FFFFFF;
	}
	
	.hoverClass1{
		box-shadow: 0rpx 0rpx 10rpx #DDDDDD;
	}

	.top {
		padding: 50rpx;
		background-color: #FC8D38;
		display: flex;
		justify-content: space-between;

		.value {
			display: flex;
			flex-direction: column;
			text-align: center;

			text:first-child {
				color: #FCE7D6;
				font-size: 32rpx;
			}

			text:last-child {
				padding-top: 10rpx;
				font-size: 70rpx;
				color: #FFFFFF;
			}
		}
	}

	.data {
		padding: 50rpx 0 25rpx 40rpx;
		display: flex;
		justify-content: space-between;

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

			view:first-child {
				font-size: 34rpx;
				color: #000;
				padding-bottom: 10rpx;
			}

			view:last-child {
				font-size: 26rpx;
				color: #666666;
			}
		}

		.right {
			padding-right: 20rpx;
			color: #666666;
			display: flex;
			justify-content: center;
			align-items: center;
			text-align: center;
		}
	}

	.card {
		background-color: #FFFFFF;

		.area-padding {
			padding: 40rpx 0 20rpx;
		}
		
		.text-area{
			display: flex;
			justify-content: flex-start;
			align-items: center;
		}

		.area1 {
			padding-left: 30rpx;
			width: 55%;

			view:first-child {
				display: flex;

				image {
					width: 80rpx;
					height: 80rpx
				}

				view {
					padding-left: 15rpx;
					padding-bottom: 5rpx;
					display: flex;
					flex-direction: column;

					text:first-child {
						font-size: 32rpx;
						padding-bottom: 10rpx;
						color: #000;
					}

					text:last-child {
						font-size: 22rpx;
						color: #888888;
					}
				}
			}
		}

		.area2 {
			width: 25%;
		}

		.area3 {
			width: 20%;
		}

		.item-padding {
			padding: 20rpx 0;
		}

		.item {
			padding: 5rpx;
			display: flex;
			border-bottom: 1rpx solid #DDDDDD;
		}
		
		.item:last-child{
			border: none;
		}



	}
</style>
