<template>
	<view class="center">
		<view class="top">
			<image src="../../static/img/sybg.png" mode="" class="sybg"></image>
			<!-- <picker mode="date" :value="now_date" @change="bindDateChange" :fields="'month'" :end="date">
				<view class="uni-input choose-time">{{ now_date }} ></view>
			</picker> -->
			<view class="top-card">
				<view class="card-tit">
					<view class="tit-point"></view>
					营业额总览
				</view>
				<view class="card-icon"><image src="../../static/icon/moneyget.png" mode=""></image></view>
				<view class="now-tit">店铺余额</view>
				<view class="now-money">{{ month_momey }}</view>
				<view class="btn" @click="navTo('/pages/merchant/withdrawal')">立即提现</view>
				<!-- <view class="card-btm flex">
					<view class="card-info flex">
						<image src="../../static/icon/dayget.png" mode=""></image>
						<view class="info-wrap">
							<view class="info-tit">今日营业额</view>
							<view class="info-val">￥{{ today_momey || 0 }}</view>
						</view>
					</view>
					<view class="card-info flex">
						<image src="../../static/icon/daydd.png" mode=""></image>
						<view class="info-wrap">
							<view class="info-tit">今日订单</view>
							<view class="info-val dan">{{ today_count }}</view>
						</view>
					</view>
				</view> -->
			</view>
		</view>
		<!-- <view class="mid-tit flex">
			<view class="mid-left flex">
				<image src="../../static/icon/time.png" mode=""></image>
				<view class="left-tit">本月订单数</view>
			</view>
			<view class="mid-right">{{ month_count }}单</view>
		</view> -->
		<view class="btm-tab">
			<!-- <view class="tab-tit flex">
				<view class="tab-top-left tab-content">订单类型</view>
				<view class="tab-top-center tab-content">订单数</view>
				<view class="tab-top-right tab-content">金额</view>
			</view> -->
			<scroll-view scroll-y="true" class="list-wrapper" :style="{ height: height }">
				<!-- 空白页 -->
				<empty v-if="loaded && monthList.length == 0"></empty>
				<view v-for="item in monthList" class="flex list" :key="item.time">
					<view class="tab-top-left ">{{ item.title }}</view>
					<!-- <view class="tab-top-center ">{{ item.count || 0 }}单</view> -->
					<view class="tab-top-right money">{{ item.pm == 0 ? '-' : '+' }}{{ item.number }}</view>
				</view>
				<uni-load-more :status="loadingType" v-if="loadingType == 'loading'"></uni-load-more>
			</scroll-view>
		</view>
	</view>
</template>

<script>
import { bill, storeIndex } from '@/api/merchant.js';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
export default {
	components: {
		empty,
		uniLoadMore
	},
	data() {
		return {
			loadingType: 'more',
			page: 1,
			limit: 1000,
			monthList: {},
			loaded: false,
			month_momey: ''
		};
	},
	onReady(res) {
		var _this = this;
		uni.getSystemInfo({
			success: resu => {
				const query = uni.createSelectorQuery();
				query.select('.list-wrapper').boundingClientRect();
				query.exec(function(res) {
					console.log(res, 'ddddddddddddd');
					_this.height = resu.windowHeight - res[0].top + 'px';
					console.log('打印页面的剩余高度', _this.height);
				});
			},
			fail: res => {}
		});
	},
	onLoad() {
		console.log(this.tiday_start, 'start');
		console.log(this.now_date);
		this.loadData();
	},
	methods: {
		// 切换月份
		bindDateChange(e) {
			console.log(e.detail, 'dddddddddddd');
			this.now_date = e.detail.value;
			this.month_momey = 0;
			this.month_count = 0;
			this.loadData();
		},
		loadData() {
			const obj = this;
			storeIndex({}).then(({ data }) => {
				obj.month_momey = data.balance;
				console.log(data);
			});
			bill({ page: obj.pages, limit: obj.limit }).then(data => {
				console.log(data);
				obj.monthList = data.data.data;
				data.data.data.forEach(e => {
					console.log(e);
					obj.month_count += e.count;
					if (e.price != null) {
						obj.month_momey += e.price * 1;
					}
				});
			});
		},
		navTo(url) {
			uni.navigateTo({
				url
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.top {
	height: 585rpx;
	// background-color: #f6f7f8;
	position: relative;

	.sybg {
		position: absolute;
		width: 100%;
		height: 265rpx;
	}
	.top-card {
		width: 688rpx;
		height: 398rpx;
		padding: 32rpx;
		background: #ffffff;
		box-shadow: -2rpx 4rpx 18rpx 0px rgba(0, 110, 238, 0.2);
		border-radius: 24rpx;
		position: absolute;
		right: 0;
		left: 0;
		bottom: 40rpx;
		margin: 0 auto;

		.now-tit {
			text-align: right;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
		}

		.now-money {
			padding-top: 10rpx;
			text-align: right;
			font-size: 72rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #52c696;

			&::before {
				content: '￥';
				font-size: 44rpx;
				position: relative;
				bottom: 5rpx;
			}
		}

		.card-icon {
			position: absolute;
			top: 100rpx;
			left: 48rpx;
			width: 224rpx;
			height: 122rpx;

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

		.card-tit {
			display: flex;
			align-items: center;

			.tit-point {
				display: inline-block;
				width: 12rpx;
				height: 32rpx;
				background: #52c696;
				border-radius: 3rpx;
				margin-right: 17rpx;
			}

			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
		}
		.btn {
			margin: 60rpx auto 0;
			width: 622rpx;
			height: 85rpx;
			background: #24a17d;
			border-radius: 15rpx;
			text-align: center;
			line-height: 85rpx;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #ffffff;
		}
	}
}

.mid-tit {
	background-color: #fff;
	height: 80rpx;
	padding: 0 30rpx 0 33rpx;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 12rpx;

	.mid-left {
		image {
			margin-right: 13rpx;
			width: 33rpx;
			height: 33rpx;
		}
	}
}

.btm-tab {
	background-color: #fff;
	// padding: 0 30rpx 0 35rpx;
	.tab-top-left {
		width: 100%;
		text-align: left;
		padding-left: 35rpx;
	}

	.tab-top-center {
		text-align: center;
	}

	.tab-top-right {
		flex-shrink: 0;
		text-align: right;
		padding-right: 30rpx;
	}

	.tab-tit {
		height: 72rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}
}

.list-wrapper {
	background-color: #fff;

	.list {
		margin: 20rpx 0 0;

		.money {
			color: #52c696;
		}
	}
}
.choose-time {
	position: absolute;
	top: 90rpx;
	line-height: 1.5;
	padding-left: 32rpx;
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #ffffff;
}
</style>
