<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">
				<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">
			<block v-if="data.length>0">
				<view class="item" v-for="(item,index) in data" :key="index">
					<image :src="item.productImg|delArr"></image>
					<view class="mid">
						<text>{{item.productName}}</text>
						<text>核销时间：{{item.writeOffTime}}</text>
					</view>
					<view class="price">¥{{item.realityPay}}</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="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
			}
		},
		filters: {
			delArr(val) {
				if (val) {
					return val.split(',')[0]
				}
		
			}
		},
		onLoad() {
			this.getdata();
		},
		methods: {
			getdata() {
				this.$api.post('/api/merchant/food/getMerchantFoodWriteOffList', {
					dateType:1,
					merchantId: this.merchantId,
					queryDate: this.date
				}).then(res => {
					if (res.data.code == 0) {
						this.totalAmount = res.data.data.orderAmount;
						this.totalNum = res.data.data.orders;
						this.data=res.data.data.merchantOrderDTOS;
					}
					console.log(res)
				})
			},
			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;
				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 {
				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;
						margin: 18rpx 0;
					}
				}
			}

			.price {
				font-size: 32rpx;
				margin-top: 10rpx;
			}
		}
	}
</style>