<template>
	<view >
		<view class="card">
			<view class="top" @click="showTime=true">
				<text>{{defaultTime}}</text>
				<text class="cuIcon-unfold margin-left-10"></text>
			</view>
			<view class="bottom">
				<text>共支出 {{statistics.payNum}} 笔，合计</text>
				<text class="text-price">{{statistics.totalMoney}}</text>
			</view>
			<image class="logo" src="/pagesA/static/icon/bill.png" mode=""></image>
		</view>
		<view class="echart">
			<view class="title">
				支出对比
			</view>
			<view class="" v-if="!$isEmpty(statistics.dataList)">
				<qiun-data-charts :inScrollView="true" type="column" :chartData="chartData" />
			</view>
			<view class="empty" v-else>
				<image src="/static/icon/empty5.png" mode="widthFix"></image>
				<text>暂无数据</text>
			</view>
		</view>
			
		<view class="card2">
			<mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
				:up="upOption">
				<view class="title">支出记录</view>
				<view  class="item" hover-class="hoverClass" v-for="(item,index) in list" :key="index">
					<view class="area1">
						<view class="item-padding">
							<image :src="item.receiverLogo" style="border-radius: 50%;" mode="aspectFit"></image>
							<view class="">
								<text>{{item.receiverName}}</text>
								<text>{{item.createTime}}</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>
				<view class="empty" style="margin-top: 80rpx;" v-if="$isEmpty(list)">
					<image src="/static/icon/empty5.png" mode="widthFix"></image>
					<text>暂无数据</text>
				</view>
			</mescroll-body>
		</view>
		<u-picker v-model="showTime" mode="time" :params="params"  @confirm="confirmTime"></u-picker>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	import qiunDataCharts from "../../comps/echarts/qiun-data-charts/qiun-data-charts.vue"
	export default {
		mixins: [MescrollMixin],
		components: {
			qiunDataCharts
		},
		data() {
			return {
				height:'',
				list:[],
				//统计数据
				statistics:{},
				//图表数据
				chartData: {},
				defaultTime:'',
				
				showTime:false,
				params: {
					year: true,
				},
				
				upOption:{
					empty:{
						use:false
					}
				}
			}
		},
		onLoad() {
			this.defaultTime =this.$dateTime.format(new Date(),'YYYY')
			this.getData()
		},
		methods: {
			async getElInfo() {
				let rectInfo = await this.$u.getRect('.card2');
				this.height = this.$u.sys().windowHeight - rectInfo.top + 'px'
				this.$forceUpdate()
			},
			async getData() {
				let params={
					queryColumn:'total_price',
					queryDate: this.$dateTime.format(new Date(this.defaultTime)),
					payId:this.vuex_userId
				}
				this.statistics=(await this.$api.statistics.getBillStatistics(params)).data
				this.chartData = {
					categories: this.statistics.monthList,
					series: [{
						color: "#facba8",
						name: "积分值(单位:元) ",
						data: this.statistics.dataList
					}]
				}
			},
			confirmTime(e){
				this.defaultTime = e.year + '-' +e.month
				this.getData()
				this.downCallback()
			},
			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.bills.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); //追加新数据
						this.getElInfo()
					})
				} catch (e) {
					this.mescroll.endErr()
				}
			},
		}
	}
</script>

<style lang="scss">
	.echart {
		margin-top: 30rpx;
		background-color: #FFFFFF;
		padding-bottom: 40rpx;

		.title {
			font-weight: 800;
			font-size: 34rpx;
			padding: 40rpx 40rpx 60rpx;
		}
	}
	
	.empty{
		margin: 60rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		
		
		image{
			width: 200rpx;
			height: 200rpx;
		}
		
		text{
			color: #999999;
			font-weight: 300;
			margin-top: 40rpx;
		}
	}

	.card {
		background-color: #FC8D38;
		padding: 60rpx 0 60rpx 50rpx;
		height: 360rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		position: relative;

		.logo{
			z-index: 999;
			position: absolute;
			right: 0rpx;
			bottom: 0rpx;
			width: 220rpx;
			height: 200rpx;
		}

		.top {
			color: #FFFFFF;
			font-size: 36rpx;
		}

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

			text:first-child {
				color: #FFD1AE;
				font-size: 28rpx;
			}

			text:last-child {
				margin-top: 16rpx;
				font-size: 56rpx;
				color: #FFFFFF;
			}
		}
	}
	
	.card2 {
		margin-top: 30rpx;
		background-color: #FFFFFF;
		
		.title{
			font-size: 34rpx;
			font-weight: 800;
			padding: 40rpx 40rpx 20rpx;
		}
	
		.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>
