<template>
	<view class="page" :style="{'min-height':(h)+'px','padding-top':mt+'px'}">
		<c-nav-bar title="核销记录"></c-nav-bar>
		<view class="top">
			<view style="display: flex;align-items: center;">
				<view class="time" @click="show=true">
					<u-icon name="calendar" :label="dateStr" labelPos="right" labelColor="#666" color="#666" space="3px"
						size="25px"></u-icon>
					<u-icon name="arrow-right" color="#999" size="32rpx" style="margin:2rpx 0 0 20rpx;"></u-icon>
				</view>
				<view style="margin: 0 14rpx 0 10rpx;font-size: 30rpx;color: #666;">至</view>
				<view class="time" @click="show2=true">
					<u-icon :label="dateStr2" labelPos="right" labelColor="#666" color="#666" space="3px"
						size="25px"></u-icon>
					<u-icon name="arrow-right" color="#999" size="32rpx"></u-icon>
				</view>
			</view>
			<view class="right">共{{totalNum}}单 收入¥{{totalAmount}}</view>
		</view>
		<view class="list">
			<block v-if="data.length>0">
				<view class="item" v-for="(item,index) in data" :key="index" @tap="toDetails(item)">
					<image :src="item.goodsType==2?'../../static/bao.png':'../../static/pin.png'"></image>
					<view class="mid">
						<text>{{item.playDate}} {{item.playTime}}出发/{{item.goodsType==2?'包船':'拼船'}}/{{item.boatNo}}</text>
						<text>{{item.num}}人 · 出游{{item.playLength}}小时</text>
						<text>核销时间：{{item.updateDate}}</text>
					</view>
					<view class="price">¥{{item.realPrice}}</view>
				</view>
			</block>
			<block v-else>
				<NoData/>
			</block>
		</view>
		<u-datetime-picker @confirm="confirmDate" @cancel="show=false" :show="show" v-model="value1"
			visibleItemCount="6" mode="date"></u-datetime-picker>
		<u-datetime-picker @confirm="confirmDate2" @cancel="show2=false" :show="show2" v-model="value2"
			visibleItemCount="6" mode="date"></u-datetime-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dateStr: new Date().Format('yyyy-MM-dd'),
				dateStr2: new Date().Format('yyyy-MM-dd'),
				date: new Date().Format('yyyy-MM-dd'),
				date2: new Date().Format('yyyy-MM-dd'),
				show: false,
				show2: false,
				k: '',
				data: [],
				value1: Number(new Date()),
				value2: Number(new Date()),
				merchantId: uni.getStorageSync('merchantId'),
				totalAmount: 0,
				totalNum: 0
			}
		},
		onLoad() {
			this.getdata();
		},
		methods: {
			getdata() {
				this.$api.get('/scenic/order/writeOffRecordPage', {
					limit:50,
					page:1,
					merchantId: this.merchantId,
					// queryDate: this.date,
					startDate: this.date,
					endDate: this.date2
				}).then(res => {
					if (res.data.code == 0) {
						this.totalAmount = res.data.data.totalAmount;
						this.totalNum = res.data.data.totalNum;
						this.data=res.data.data.pageData.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}-${day}`;
				
				if(Date.parse(formattedTime) - Date.parse(this.date2)>0){
					return this.$showToast('开始日期不能大于结束日期');
				}
				
				this.dateStr = `${year}-${month}-${day}`
				this.date = formattedTime;
				this.show = false;
				this.getdata()
			},
			confirmDate2(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}-${day}`;
				
				if(Date.parse(formattedTime) - Date.parse(this.date)<0){
					return this.$showToast('结束日期不能小于开始日期');
				}
				
				this.dateStr2 = `${year}-${month}-${day}`
				this.date2 = formattedTime;
				this.show2 = false;
				this.getdata()
			},
			toDetails(item){
				uni.navigateTo({
					url:'/pagesHouse/Verification/recordDetails?orderCode='+item.orderCode
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	/deep/ .uicon-arrow-right{
		margin-top: 4rpx !important;
	}
	
	.page{
		box-sizing: border-box;
	}
	.top {
		padding: 24rpx 30rpx;

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

		.right {
			color: #999;
			font-size: 24rpx;
			margin-top: 10rpx;
			margin-left: 6rpx;
		}

	}

	.list {
		padding: 0 30rpx;

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

			image {
				width: 80rpx;
				min-width: 80rpx;
				height: 80rpx;

			}

			.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 {
				font-size: 32rpx;
			}
		}
	}
</style>