<template>
	<view class="statement">
		<view class="statement-header">
			<view class="statement-header-text">
				<view class="statement-header-text-neishi" @click="topgi">
					<view class="statement-header-text-icon">
						<image src="https://cdn.bjtdba.com/vod/image/2022-08-11/20220811133828415.png" mode="widthFix">
						</image>
					</view>
				</view>
				<view class="statement-header-text-title">
					经营报表
				</view>
			</view>
		</view>
		<view class="statement-item">
			<view class="statement-item-left">
				经营统计
			</view>
			<view class="statement-item-right">
				<view class="icojo">
					<image src="https://cdn.bjtdba.com/vod/image/2022-08-11/20220811140945433.png" mode="widthFix">
					</image>
				</view>
				<view class="" style="margin-left: 8rpx;">
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{date}}</view>
					</picker>
				</view> 至
				<view class="">
					<picker mode="date" :value="dates" :start="startDates" :end="endDates" @change="bindDateChanges">
						<view class="uni-input">{{dates}}</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="cashier-list-tbot">
			<view class="yis">
				<view class="sgjd">
					¥{{dataList.orderLineOrderSun.orderLine==undefined?0:dataList.orderLineOrderSun.orderLine}}
				</view>
				<view class="sf">
					线上营收
				</view>
			</view>
			<view class="yis">
				<view class="sgjd">
					¥{{dataList.belowTheLineSum.belowTheLine==undefined?0:dataList.belowTheLineSum.belowTheLine}}
				</view>
				<view class="sf">
					线下营收
				</view>
			</view>
			<!-- <view class="yis" @click="xiaofeifen">
				<view class="sgjd">
					¥{{dataList.consumption==null?0:dataList.consumption}}
				</view>
				<view class="sf">
					消费分
				</view>
			</view> -->
			<view class="yis">
				<view class="sgjd">
					{{dataList.sun==undefined?0:dataList.sun}}
				</view>
				<view class="sf">
					锁定会员数
				</view>
			</view>
			<view class="yis">
				<view class="sgjd">
					{{dataList.visitorNumber==undefined?0:dataList.visitorNumber}}
				</view>
				<view class="sf">
					访客数
				</view>
			</view>
			<view class="yis">
				<view class="sgjd">
					{{dataList.number==undefined?0:dataList.number}}
				</view>
				<view class="sf">
					支付人数
				</view>
			</view>
			<!-- 默认 -->
			<view class="yis">
				<view class="sgjd">
					
				</view>
				<view class="sf">
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		selectMerchantOrder,
	} from '@/commit/shop.js'
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			const currentDates = this.getDates({
				format: true
			})
			return {
				date: currentDate,
				dates: currentDates,
				sna: "",
				mer_id: '', //店铺ID
				start_time: "",
				start_times: "",
				end_time: "",
				end_times: "",
				dataList: []
			}
		},
		onLoad(e) {
			this.sna = e.sna
			let daySart = new Date
			this.start_time = this.$time.dateFormat("yyyy-MM-dd", daySart)
			this.end_time = this.$time.dateFormat("yyyy-MM-dd", daySart)
			let selectmerchant = uni.getStorageSync('selectmerchant')
			this.mer_id = selectmerchant.merId
			this.selectMerchantOrder()
		},
		computed: {
			startDate() {
				return this.getDate('start');
				return this.getDates('start');
			},
			endDate() {
				return this.getDate('end');
				return this.getDates('end');
			}
		},
		methods: {
			// 今日昨日收益
			selectMerchantOrder() {
				uni.showLoading({
					title: '加载中',
				});
				selectMerchantOrder({
					start_time: this.start_times ? this.start_times : this.start_time,
					end_time: this.end_times ? this.end_times : this.start_time,
					mer_id: this.mer_id
				}).then(res => {
					if (res.data.status == 200) {
						this.dataList = res.data.data
						uni.hideLoading(); //关闭上拉加载
					}
				}, fail => {
					console.log(fail)
					uni.hideLoading(); //关闭上拉加载
				})
			},
			topgi() {
				if (this.sna == 1) {
					uni.switchTab({
						url: "/pages/cashier/index"
					})
				} else {
					uni.switchTab({
						url: "/pages/storemanagement/index"
					})
				}

			},
			bindDateChange: function(e) {
				this.date = e.detail.value
				this.start_times = e.detail.value
				this.selectMerchantOrder()
			},
			bindDateChanges: function(e) {
				this.dates = e.detail.value
				this.end_times = e.detail.value
				this.selectMerchantOrder()
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			getDates(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
		}
	}
</script>

<style>
	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.statement {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;

		.statement-header {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 111;
			width: 100%;
			height: 176rpx;
			background: #FFFFFF;
			display: flex;
			justify-content: center;

			.statement-header-text {
				width: 686rpx;
				font-size: 36rpx;
				font-weight: 500;
				color: #333333;
				display: flex;
				margin-top: 107rpx;
				align-items: center;

				.statement-header-text-neishi {
					width: 45rpx;
					height: 45rpx;
					margin-right: 17rpx;

					.statement-header-text-icon {
						width: 36rpx;
						height: 36rpx;
						margin-top: 2rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}

		.statement-item {
			width: 686rpx;
			height: 32rpx;
			margin-top: 202rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #333333;

			.statement-item-left {
				font-size: 32rpx;
				font-weight: 400;
			}

			.statement-item-right {
				.icojo {
					width: 20rpx;
					height: 20rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				font-size: 24rpx;
				font-weight: 400;
				display: flex;
			}
		}

		.cashier-list-tbot {
			width: 686rpx;
			height: 287rpx;
			background: #FFFFFF;
			margin-top: 26rpx;
			border-radius: 16px;
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			justify-content: space-between;

			.yis {
				width: 33%;
				height: 82rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;
				color: #333333;

				.sgjd {
					font-size: 36rpx;
					font-weight: bold;
				}

				.sf {
					font-size: 26rpx;
					font-weight: 400;
				}
			}
		}
	}
</style>
