<template>
	<view class="page" :style="{'min-height':(h)+'px','padding-top':mt+'px'}">
		<c-nav-bar title="核销记录"></c-nav-bar>
		<view class="top">
			<view class="time" @click="show=true">
				<!-- <view class="time"> -->
				<u-icon name="calendar" :label="dateStr" labelPos="right" labelColor="#666" color="#666" space="7px"
					size="25px"></u-icon>
				<!-- <u-icon name="arrow-down" color="#999" size="20px" style="margin-left: 20rpx;"></u-icon> -->
			</view>
			<view class="right">共{{totalNum}}单 收入¥{{totalAmount}}</view>
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in data" :key="index">
				<image :src="item.cover"></image>
				<view class="" style="width: 100%; display: flex; justify-content: space-between;">
					<view class="mid">
						<view style="font-size: 30rpx; color: #111111; font-weight: bold; margin: 24rpx 0 30rpx;">
							{{item.comboName}}
						</view>
						<!-- <text>{{item.num}}人 · 出游{{item.playLength}}小时</text> -->
						<view>核销时间:{{item.checkinTime}}</view>
					</view>
					<view class="price">¥{{item.orderAmount}}</view>
				</view>

			</view>
		</view>
		<view class="nodata" v-if='data.length==0'>
			<NoData></NoData>
		</view>
		<u-datetime-picker @confirm="confirmDate" @cancel="show=false" :show="show" v-model="value1"
			visibleItemCount="6" mode="year-month"></u-datetime-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dateStr: new Date().Format('yyyy年-MM月'),
				date: new Date().Format('yyyy-MM'),
				show: false,
				k: '',
				data: [],
				value1: Number(new Date()),
				merchantId: uni.getStorageSync('merchantId'),
				totalAmount: 0,
				totalNum: 0,
				repastMonth: ''
			}
		},
		onLoad() {
			this.getdata();
		},
		methods: {
			getdata() {
				this.$api.get('/merchant/hotel/order/getMerchantOrderPageList', {
					limit: 50,
					page: 1,
					homestayId: uni.getStorageSync('homestayId'),
					orderStatus: 2,
					orderType: 201,
					repastMonth: this.date
				}).then(res => {

					if (res.data.code == 0) {
						var arr = []
						var number = 0
						res.data.data.list.forEach((item, index) => {
							number += item.orderAmount
						});
						this.totalAmount = parseFloat(number).toFixed(2)
						this.totalNum = res.data.data.total;
						this.data = res.data.data.list;
					}
				})
			},

			confirmDate(e) {
				// 创建一个Date对象并传入时间戳
				const date = new Date(e.value);
				// 使用Date对象的方法获取年、月、日、小时、分钟和秒
				const year = date.getFullYear();
				const month = ('0' + (date.getMonth() + 1)).slice(-2);
				const day = ('0' + date.getDate()).slice(-2);
				// 格式化时间
				let formattedTime = "";
				formattedTime = `${year}-${month}`;
				this.dateStr = `${year}年-${month}月`
				this.date = formattedTime;
				console.log(this.date);
				this.show = false;
				this.getdata()
			},

		}
	}
</script>

<style lang="less" scoped>
	.page {
		box-sizing: border-box;
	}

	.top {
		padding: 24rpx 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.time {
			display: flex;
			align-items: center;
			gap: 0 10rpx;
		}

		.right {
			color: #999;
			font-size: 24rpx;

		}

	}

	.list {
		padding: 0 30rpx;

		.item {
			padding: 30rpx 0;
			border-bottom: 1rpx solid #EFEFEF;
			display: flex;
			justify-content: space-between;

			image {
				border-radius: 16rpx;
				width: 136rpx;
				min-width: 136rpx;
				height: 136rpx;

			}

			.mid {
				margin: 0 30rpx 0 20rpx;

				text {
					display: inline-block;
					font-size: 28rpx;
					color: #777;

					&:first-child {
						font-size: 30rpx;
						color: #111;
						font-weight: bold;
					}

					&:nth-child(2) {
						margin: 18rpx 0;
					}
				}
			}

			.price {
				line-height: 80rpx;
				font-size: 32rpx;
				color: #111111;
				font-weight: bold;
			}
		}
	}
</style>