<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="/static/icon/bills.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="bg-white safe-area-inset-bottom" style="height: 100%;">
			<mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
				:down="downOption" :up="upOption">
				<view style="font-size: 34rpx;font-weight: 800;padding: 40rpx 40rpx 20rpx">收入记录</view>
				<navigator :url="'/pages/my-bills/bills-detail?id='+item.id+'&type=all'" class="u-border-bottom flex" v-for="(item,index) in list" :key="index">
					<view class="area1">
						<image v-if="$isNotEmpty(item.avatar)"  :src="item.avatar" ></image>
						<block v-else>
							<image v-if="item.payWay=='WECHAT'"  src="@/static/icon/wx.png" ></image>
							<image v-else-if="item.payWay=='ALIPAY'"  src="@/static/icon/ALIPAY.png" ></image>
							<image v-else-if="item.payWay=='UNIONPAY'"  src="@/static/icon/UNIONPAY.png" ></image>
							<image v-else-if="item.payWay=='APPLEPAY'"  src="@/static/icon/apple.png" ></image>
							<image v-else  src="@/static/icon/avatar.png" ></image>
						</block>
						<view>
							<text  v-if="$isNotEmpty(item.nickName)">{{item.nickName}}</text>
							<block v-else >
								<text v-if="item.payWay=='WECHAT'">微信用户</text>
								<text v-else-if="item.payWay=='ALIPAY'">支付宝用户</text>
								<text v-else-if="item.payWay=='UNIONPAY'">银联用户</text>
								<text v-else-if="item.payWay=='APPLEPAY'">苹果用户</text>
								<text v-else>用户昵称</text>
							</block>
							<text>{{item.createTime}}</text>
						</view>
					</view>
					<view class="area2">
						<text>{{discount(item.discount)}}</text>
					</view>
					<view class="area3">
						<text class="text-base price" v-if="$isNotEmpty(item.receiveNumTotal)">{{item.receiveNumTotal}}</text>
						<text class="text-base price" v-else>{{item.cost || 0}}</text>
					</view>
				</navigator>
			</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 "@/components/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,
				},
				downOption:{
					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: 'actual_income',
					queryDate: this.$dateTime.format(new Date(this.defaultTime)),
					receiveId: this.vuex_shopId
				}
				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
				this.getData()
				this.downCallback()
			},
			upCallback(mescroll) {
				let params = {
					receiveId: this.vuex_shopId,
					current: mescroll.num,
					size: mescroll.size,
					payStatus:this.$global.PAY_STATUS.SUCCESS
				}
				if (this.defaultTime) {
					params.format = this.defaultTime
				}

				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;
			}
		}
	}
	.area1 {
		$img-width: 70rpx;
		width: 54%;
		display: flex;
		height: 120rpx;
		padding-left: 30rpx;
		justify-content: center;
		align-items: center;
	
		image {
			display: flex;
			align-items: center;
			justify-content: center;
			width: $img-width;
			height: $img-width;
			border-radius: 50%;
		}
	
		view {
			width: 80%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-left: 10rpx;
		}
	
		text:first-child {
			margin-bottom: 8rpx;
		}
	
		text:last-child {
			margin-top: 8rpx;
			color: #999;
		}
	}
	
	.area2 {
		display: flex;
		justify-content: center;
		align-items: center;
		text-align: center;
		width: 22%;
		margin-top: 10rpx;
		font-weight: 300;
		color: #666;
	}
	
	.area3 {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 24%;
		font-size: 32rpx;
		margin-top: 10rpx;
	}
	
	
</style>
