<template>
	<view class="page-container">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<template #top>
				<view class="header">
					<view class="search-bar">
						<view class="filter-dropdown" @click="showPicker = true">
							<text>{{ dateText }}</text>
							<u-icon name="arrow-down-fill" size="24rpx" color="#666" top="1"></u-icon>
						</view>
						<u-search 
							actionText="搜索" 
							:animation="true"
							bgColor="#f2f2f2"
							placeholder="订单号搜索" 
							v-model="keyword" 
						></u-search>
					</view>
				</view>
			</template>
			<view class="list-content">
				<view v-for="(item, index) in dataList" :key="index" class="record-card flex">
					<view class="card-left">
						<u-avatar :src="item.avatar" size="68rpx" default-url="/static/common/avatar.png"></u-avatar>
					</view>
					<view class="card-body">
						<view class="left flex">
							<view class="order">
								<text class="label">订单号：</text>
								<text class="value">{{ item.orderNo }}</text>
							</view>
						</view>
						<view class="right flex">
							<view class="time">
								<text class="label">时间：</text>
								<text class="value">{{ item.time }}</text>
							</view>
							<view class="other">
								<text class="symbol">¥</text>
								<text class="amount">{{ item.amount }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>

		<u-datetime-picker
			mode="year-month"
			:show="showPicker"
			v-model="currentDate"
			@confirm="confirmDate"
			@cancel="showPicker = false"
		></u-datetime-picker>
	</view>
</template>

<script>
export default {
	data() {
		return {
			keyword: '',
			dateText: '全部日期',
			showPicker: false,
			currentDate: Number(new Date()),
			dataList: []
		};
	},
	methods: {
		confirmDate(e) {
			this.dateText = new Date(e.value).Format('YYYY-MM');
			this.showPicker = false;
			// 此处触发搜索逻辑
		},
		queryList(pageNo, pageSize) {
			console.log(pageNo, pageSize)
			// 这里的pageNo和pageSize会自动计算好，直接传给服务器即可
			// 这里的请求只是演示，请替换成自己的项目的网络请求，并在网络请求回调中通过this.$refs.paging.complete(请求回来的数组)将请求结果传给z-paging
			// this.$request.queryList({ pageNo,pageSize }).then(res => {
			// 	// 请勿在网络请求回调中给dataList赋值！！只需要调用complete就可以了
				let res = {
					data: {
						list: [
							{ orderNo: '32025050702041853308351', time: '2025-09-14 12:08', amount: '493.4' },
							{ orderNo: '32025050702041853308351', time: '2025-09-14 12:08', amount: '493.4' },
							{ orderNo: '32025050702041853308351', time: '2025-09-14 12:08', amount: '493.4' },
							{ orderNo: '32025050702041853308351', time: '2025-09-14 12:08', amount: '493.4' },
						]
					}
				}
				this.$refs.paging.complete(res.data.list);
			// }).catch(res => {
			// 	// 如果请求失败写this.$refs.paging.complete(false)，会自动展示错误页面
			// 	// 注意，每次都需要在catch中写这句话很麻烦，z-paging提供了方案可以全局统一处理
			// 	// 在底层的网络请求抛出异常时，写uni.$emit('z-paging-error-emit');即可
			// 	this.$refs.paging.complete(false);
			// })
		}
	}
};
</script>

<style lang="scss" scoped>
.page-container {
	min-height: 100vh;
	background: linear-gradient(152deg, #DCFFF8 0%, #F1FEFF 100%);

	.header {
		padding: 20rpx 24rpx;
		background-color: #ffffff;

		.search-bar {
			display: flex;
			align-items: center;
			
			.filter-dropdown {
				height: 66rpx;
				padding: 0rpx 24rpx;
				margin-right: 24rpx;
				border-radius: 134rpx;
				white-space: nowrap;
				background-color: #f2f2f2;
				display: flex;
				align-items: center;
				
				text {
					width: 105rpx;
					font-size: 26rpx;
					color: #333333;
					margin-right: 6rpx;
				}
			}
		}
	}

	.list-content {
		padding: 24rpx;
	}

	.record-card {
		padding: 24rpx;
		margin-bottom: 20rpx;
		border-radius: 12rpx;
		background-color: #ffffff;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);

		&:last-child {
			margin-bottom: 0;
		}

		.card-left {
			margin-right: 20rpx;
		}

		.card-body {
			flex: 1;

			.left {
				margin-bottom: 8rpx;
			}

			.right {
				align-items: baseline;
				justify-content: space-between;
			}
		}
			
		.order {
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;

			.value {
				word-break: break-all;
			}
		}
		
		.time {
			font-weight: 400;
			font-size: 26rpx;
			color: #333333;
		}

		.other {
			display: flex;
			align-items: baseline;
			
			.symbol {
				font-size: 20rpx;
				color: #F53E54;
				font-weight: bold;
			}
			
			.amount {
				font-size: 32rpx;
				color: #F53E54;
				font-weight: bold;
				margin-left: 4rpx;
			}
		}
	}
}
</style>