<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="[publishedActive && 'active']" @click="setPublishedStatus">已发布</view>
				<view :class="[processingActive && 'active']" @click="setProcessingStatus">进行中</view>
				<view :class="[completedActive && 'active']" @click="setCompletedStatus">已完成</view>
			</view>
		</view>
		
		<!-- 发布订单按钮 -->
		<view class="publish-btn-container">
			<view class="publish-btn" @click="publishOrder">
				<uv-icon name="plus" size="20" color="#fff"></uv-icon>
				<text>发布订单</text>
			</view>
		</view>
		
		<!-- 已发布订单列表 -->
		<view v-if="showPublishedList" class="m20">
			<view v-if="publishedEmpty" class="re-empty">
				<view>暂无数据</view>
			</view>
			<view v-for="(item, index) in publishedOrders" :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.requireTime }}</view>
				<view>计划数量：{{ item.quantity }}m³</view>
				<view>报价：{{ item.price }}元/m³</view>
				<view class="item-status published">已发布</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.driver }}</view>
				<view>进度：{{ item.progress }}</view>
				<view>预计完成：{{ item.estimatedTime }}</view>
				<view class="item-status processing">进行中</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.driver }}</view>
				<view>评价：{{ item.rating }}</view>
				<view class="item-status completed">已完成</view>
				<view class="item-button" @click="viewOrder(item)">查看</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'EnterpriseHall',
		data() {
			return {
				showFilterIcon: true,
				showFilterText: true,
				searchActive: false,
				searchValue: '',
				publishedActive: true,
				processingActive: false,
				completedActive: false,
				showPublishedList: true,
				showProcessingList: false,
				showCompletedList: false,
				publishedEmpty: false,
				processingEmpty: false,
				completedEmpty: false,
				publishedOrders: [
					{
						id: 1,
						title: '长沙市雨花区建设项目混凝土需求',
						time: '2024-01-15 08:00',
						requireTime: '2024-01-16 09:00',
						quantity: '200',
						price: '350'
					},
					{
						id: 2,
						title: '长沙市岳麓区商业中心项目',
						time: '2024-01-15 10:00',
						requireTime: '2024-01-17 08:00',
						quantity: '150',
						price: '380'
					}
				],
				processingOrders: [
					{
						id: 3,
						title: '长沙市开福区住宅项目',
						time: '2024-01-14 14:00',
						driver: '张师傅',
						progress: '运输中 70%',
						estimatedTime: '2024-01-14 18:00'
					}
				],
				completedOrders: [
					{
						id: 4,
						title: '长沙市天心区办公楼项目',
						time: '2024-01-13 09:00',
						completedTime: '2024-01-13 17:00',
						driver: '李师傅',
						rating: '5星好评'
					}
				]
			}
		},
		methods: {
			showFilter() {
				console.log('显示筛选');
			},
			onSearch() {
				console.log('搜索:', this.searchValue);
			},
			onInput() {
				this.searchActive = this.searchValue.length > 0;
			},
			setPublishedStatus() {
				this.publishedActive = true;
				this.processingActive = false;
				this.completedActive = false;
				this.showPublishedList = true;
				this.showProcessingList = false;
				this.showCompletedList = false;
			},
			setProcessingStatus() {
				this.publishedActive = false;
				this.processingActive = true;
				this.completedActive = false;
				this.showPublishedList = false;
				this.showProcessingList = true;
				this.showCompletedList = false;
			},
			setCompletedStatus() {
				this.publishedActive = false;
				this.processingActive = false;
				this.completedActive = true;
				this.showPublishedList = false;
				this.showProcessingList = false;
				this.showCompletedList = true;
			},
			viewOrder(item) {
				uni.navigateTo({
					url: `/pages_order/order/orderDetail?id=${item.id}`
				});
			},
			publishOrder() {
				uni.navigateTo({
					url: '/pages_order/staff/create'
				});
			},
			// 供外部调用的方法
			loadPage() {
				console.log('企业订单大厅页面刷新');
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 20rpx;
		height: 100%;
		box-sizing: border-box;
		overflow-y: auto;
	}
	
	.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: #f8f8f8;
			transition: all 0.3s;
			
			&.active {
				color: #007AFF;
				background-color: #e6f3ff;
				border: 1rpx solid #007AFF;
			}
		}
	}
	
	.publish-btn-container {
		padding: 0 20rpx 20rpx;
	}
	
	.publish-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 10rpx;
		padding: 20rpx;
		background-color: #007AFF;
		color: #fff;
		border-radius: 10rpx;
		font-size: 28rpx;
		font-weight: bold;
	}
	
	.m20 {
		margin: 20rpx;
	}
	
	.mb20 {
		margin-bottom: 20rpx;
	}
	
	.m10 {
		margin: 10rpx;
	}
	
	.item-card {
		background-color: #fff;
		border-radius: 10rpx;
		padding: 20rpx;
		position: relative;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
	}
	
	.ellipsis {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		font-weight: bold;
		font-size: 30rpx;
	}
	
	.item-time {
		font-size: 24rpx;
		color: #999;
	}
	
	.item-status {
		position: absolute;
		top: 20rpx;
		right: 20rpx;
		padding: 8rpx 16rpx;
		border-radius: 20rpx;
		font-size: 22rpx;
		color: #fff;
		
		&.published {
			background-color: #ff9500;
		}
		
		&.processing {
			background-color: #007AFF;
		}
		
		&.completed {
			background-color: #34c759;
		}
	}
	
	.item-button {
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
		padding: 10rpx 20rpx;
		background-color: #007AFF;
		color: #fff;
		border-radius: 20rpx;
		font-size: 24rpx;
	}
	
	.re-empty {
		text-align: center;
		padding: 100rpx 0;
		color: #999;
		font-size: 28rpx;
	}
	
	.b-relative {
		position: relative;
	}
</style>