<template>
	<view class="content">
		<!-- 顶部搜索和筛选 -->
		<view class="head flex-sb sticky box-shadow-light">
			<view class="flex" @click="showFilter">
				<view class="mr5">
					<uv-icon v-if="showFilterIcon" name="funnel" size="24" color="#666"></uv-icon>
				</view>
				<view v-if="showFilterText" style="font-size:28rpx">筛选</view>
				<input 
					:class="['search-input', searchActive && 'active']"
					maxlength="10" 
					type="text" 
					confirm-type="search" 
					@confirm="onSearch"
					v-model="searchValue" 
					@input="onInput" 
					placeholder="搜索订单"
				/>
			</view>
			<view class="flex status">
				<view :class="[pendingActive && 'active']" @click="setPendingStatus">待接单</view>
				<view :class="[processingActive && 'active']" @click="setProcessingStatus">进行中</view>
				<view :class="[completedActive && 'active']" @click="setCompletedStatus">已完成</view>
			</view>
		</view>
		
		<!-- 待接单列表 -->
		<view v-if="showPendingList" class="m20">
			<view v-if="pendingEmpty" class="re-empty">
				<view>暂无数据</view>
			</view>
			<view v-for="(item, index) in pendingOrders" :key="index" class="b-relative item-card mb20">
				<view class="m10 flex-sb">
					<view class="ellipsis">{{ item.title }}</view>
					<view class="item-time">{{ item.time }}</view>
				</view>
				<view>到场时间：{{ item.arrivalTime }}</view>
				<view>计划数量：{{ item.quantity }}m³/趟</view>
				<view class="item-button" @click="viewOrder(item)">查看</view>
			</view>
		</view>
		
		<!-- 进行中列表 -->
		<view v-if="showProcessingList" class="m20">
			<view v-if="processingEmpty" class="re-empty">
				<view>暂无数据</view>
			</view>
			<view v-for="(item, index) in processingOrders" :key="index" class="b-relative item-card mb20">
				<view class="m10 flex-sb">
					<view class="ellipsis">{{ item.title }}</view>
					<view class="item-time">{{ item.time }}</view>
				</view>
				<view>进度：{{ item.progress }}</view>
				<view>预计完成：{{ item.estimatedTime }}</view>
				<view class="item-button" @click="viewOrder(item)">查看</view>
			</view>
		</view>
		
		<!-- 已完成列表 -->
		<view v-if="showCompletedList" class="m20">
			<view v-if="completedEmpty" class="re-empty">
				<view>暂无数据</view>
			</view>
			<view v-for="(item, index) in completedOrders" :key="index" class="b-relative item-card mb20">
				<view class="m10 flex-sb">
					<view class="ellipsis">{{ item.title }}</view>
					<view class="item-time">{{ item.time }}</view>
				</view>
				<view>完成时间：{{ item.completedTime }}</view>
				<view>评价：{{ item.rating }}</view>
				<view class="item-button" @click="viewOrder(item)">查看</view>
			</view>
		</view>
	</view>
</template>

<script>
	import navbar from '@/components/base/navbar.vue'
	
	export default {
		name: 'StaffHall',
		components: {
			navbar
		},
		data() {
			return {
				showFilterIcon: true,
				showFilterText: true,
				searchActive: false,
				searchValue: '',
				pendingActive: true,
				processingActive: false,
				completedActive: false,
				showPendingList: true,
				showProcessingList: false,
				showCompletedList: false,
				pendingEmpty: false,
				processingEmpty: false,
				completedEmpty: false,
				pendingOrders: [
					{
						id: 1,
						title: '长沙市雨花区建设项目',
						time: '2024-01-15 08:00',
						arrivalTime: '2024-01-15 09:00',
						quantity: '50'
					},
					{
						id: 2,
						title: '长沙市岳麓区商业中心',
						time: '2024-01-15 10:00',
						arrivalTime: '2024-01-15 11:00',
						quantity: '30'
					}
				],
				processingOrders: [
					{
						id: 3,
						title: '长沙市开福区住宅项目',
						time: '2024-01-14 14:00',
						progress: '进行中 60%',
						estimatedTime: '2024-01-14 18:00'
					}
				],
				completedOrders: [
					{
						id: 4,
						title: '长沙市天心区办公楼',
						time: '2024-01-13 09:00',
						completedTime: '2024-01-13 17:00',
						rating: '5星好评'
					}
				]
			}
		},
		methods: {
			showFilter() {
				console.log('显示筛选');
			},
			onSearch() {
				console.log('搜索:', this.searchValue);
			},
			onInput() {
				this.searchActive = this.searchValue.length > 0;
			},
			setPendingStatus() {
				this.pendingActive = true;
				this.processingActive = false;
				this.completedActive = false;
				this.showPendingList = true;
				this.showProcessingList = false;
				this.showCompletedList = false;
			},
			setProcessingStatus() {
				this.pendingActive = false;
				this.processingActive = true;
				this.completedActive = false;
				this.showPendingList = false;
				this.showProcessingList = true;
				this.showCompletedList = false;
			},
			setCompletedStatus() {
				this.pendingActive = false;
				this.processingActive = false;
				this.completedActive = true;
				this.showPendingList = false;
				this.showProcessingList = false;
				this.showCompletedList = true;
			},
			viewOrder(item) {
				uni.navigateTo({
					url: `/pages_order/order/orderDetail?id=${item.id}`
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 20rpx;
		min-height: 100vh;
		background-color: #f5f5f5;
	}
	
	.head {
		background-color: #fff;
		padding: 20rpx;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
	}
	
	.sticky {
		position: sticky;
		top: 0;
		z-index: 999;
	}
	
	.box-shadow-light {
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}
	
	.flex {
		display: flex;
		align-items: center;
	}
	
	.flex-sb {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.mr5 {
		margin-right: 5rpx;
	}
	
	.search-input {
		flex: 1;
		height: 60rpx;
		padding: 0 20rpx;
		border: 1rpx solid #e0e0e0;
		border-radius: 30rpx;
		margin-left: 20rpx;
		font-size: 28rpx;
		
		&.active {
			border-color: #007AFF;
		}
	}
	
	.status {
		margin-top: 20rpx;
		gap: 30rpx;
		
		view {
			padding: 15rpx 25rpx;
			border-radius: 25rpx;
			font-size: 26rpx;
			color: #666;
			background-color: #f0f0f0;
			transition: all 0.3s;
			
			&.active {
				background-color: #007AFF;
				color: #fff;
			}
		}
	}
	
	.m20 {
		margin: 20rpx 0;
	}
	
	.m10 {
		margin: 10rpx 0;
	}
	
	.mb20 {
		margin-bottom: 20rpx;
	}
	
	.b-relative {
		position: relative;
	}
	
	.item-card {
		background-color: #fff;
		border-radius: 10rpx;
		padding: 30rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
		font-size: 28rpx;
		line-height: 1.6;
	}
	
	.ellipsis {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		flex: 1;
		font-weight: bold;
		color: #333;
	}
	
	.item-time {
		font-size: 24rpx;
		color: #999;
	}
	
	.item-button {
		position: absolute;
		right: 30rpx;
		bottom: 30rpx;
		background-color: #007AFF;
		color: #fff;
		padding: 15rpx 25rpx;
		border-radius: 25rpx;
		font-size: 26rpx;
	}
	
	.re-empty {
		text-align: center;
		padding: 100rpx 0;
		color: #999;
		font-size: 28rpx;
	}
</style>