<template>
	<view class="stock-page">
		<view class="header">
			<view class="back" @click="goBack">
				<text class="iconfont icon-xiangzuo"></text>
			</view>
			<view class="title">库存查询</view>
			<view class="right"></view>
		</view>
		
		<view class="content">
			<!-- 搜索和筛选 -->
			<view class="search-section">
				<view class="search-box">
					<input type="text" v-model="searchKeyword" placeholder="搜索物资名称" />
					<view class="search-btn" @click="searchStock">搜索</view>
				</view>
				<view class="filter-box">
					<view class="filter-item" @click="toggleFilter('category')">
						<text>{{ selectedCategory || '全部类别' }}</text>
						<text class="iconfont icon-xiangxia"></text>
					</view>
					<view class="filter-item" @click="toggleFilter('location')">
						<text>{{ selectedLocation || '全部位置' }}</text>
						<text class="iconfont icon-xiangxia"></text>
					</view>
				</view>
			</view>
			
			<!-- 库存预警 -->
			<view class="alert-section" v-if="alertItems.length > 0">
				<view class="alert-title">
					<text class="iconfont icon-jinggao"></text>
					<text>库存预警</text>
				</view>
				<view class="alert-list">
					<view class="alert-item" v-for="(item, index) in alertItems" :key="index">
						<text class="item-name">{{ item.name }}</text>
						<text class="item-stock">当前库存：{{ item.stock }}件</text>
						<text class="item-min">最低库存：{{ item.minStock }}件</text>
					</view>
				</view>
			</view>
			
			<!-- 库存列表 -->
			<view class="stock-section">
				<view class="stock-title">库存列表</view>
				<view class="stock-list">
					<view class="stock-item" v-for="(item, index) in stockItems" :key="index">
						<view class="item-header">
							<text class="item-name">{{ item.name }}</text>
							<text class="item-status" :class="item.stock <= item.minStock ? 'status-warning' : 'status-normal'">
								{{ item.stock <= item.minStock ? '库存不足' : '库存正常' }}
							</text>
						</view>
						<view class="item-body">
							<view class="info-item">
								<text class="label">当前库存：</text>
								<text class="value">{{ item.stock }}件</text>
							</view>
							<view class="info-item">
								<text class="label">最低库存：</text>
								<text class="value">{{ item.minStock }}件</text>
							</view>
							<view class="info-item">
								<text class="label">库存位置：</text>
								<text class="value">{{ item.location }}</text>
							</view>
							<view class="info-item">
								<text class="label">物资类别：</text>
								<text class="value">{{ item.category }}</text>
							</view>
							<view class="info-item">
								<text class="label">最后更新：</text>
								<text class="value">{{ item.updateTime }}</text>
							</view>
						</view>
						<view class="item-footer">
							<view class="detail-btn" @click="viewStockDetail(item.id)">查看详情</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			searchKeyword: '',
			selectedCategory: '',
			selectedLocation: '',
			alertItems: [
				{ id: 1, name: '有机蔬菜', stock: 20, minStock: 30, location: '仓库A区', category: '食材' },
				{ id: 3, name: '肉类食材', stock: 15, minStock: 20, location: '冷库C区', category: '食材' }
			],
			stockItems: [
				{ id: 1, name: '有机蔬菜', stock: 20, minStock: 30, location: '仓库A区', category: '食材', updateTime: '2026-03-07 10:00' },
				{ id: 2, name: '新鲜水果', stock: 40, minStock: 25, location: '仓库B区', category: '食材', updateTime: '2026-03-07 09:30' },
				{ id: 3, name: '肉类食材', stock: 15, minStock: 20, location: '冷库C区', category: '食材', updateTime: '2026-03-06 18:00' },
				{ id: 4, name: '海鲜产品', stock: 25, minStock: 15, location: '冷库D区', category: '食材', updateTime: '2026-03-06 17:30' },
				{ id: 5, name: '维修耗材', stock: 50, minStock: 20, location: '仓库E区', category: '耗材', updateTime: '2026-03-05 14:00' },
				{ id: 6, name: '办公用品', stock: 30, minStock: 15, location: '仓库F区', category: '办公', updateTime: '2026-03-05 13:30' }
			]
		};
	},
	methods: {
		goBack() {
			uni.navigateBack();
		},
		searchStock() {
			uni.showToast({
				title: '搜索功能开发中',
				icon: 'none'
			});
		},
		toggleFilter(type) {
			uni.showToast({
				title: '筛选功能开发中',
				icon: 'none'
			});
		},
		viewStockDetail(id) {
			uni.showToast({
				title: '查看库存详情',
				icon: 'none'
			});
		}
	}
};
</script>

<style lang="scss">
.stock-page {
	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 88rpx;
		padding: 0 30rpx;
		background-color: #409EFF;
		color: #fff;
		
		.back {
			width: 60rpx;
			height: 100%;
			display: flex;
			align-items: center;
			
			.iconfont {
				font-size: 32rpx;
				color: #fff;
			}
		}
		
		.title {
			font-size: 32rpx;
			font-weight: 600;
		}
		
		.right {
			width: 60rpx;
		}
	}
	
	.content {
		padding: 30rpx;
		
		.search-section {
			margin-bottom: 30rpx;
			
			.search-box {
				display: flex;
				margin-bottom: 20rpx;
				
				input {
					flex: 1;
					height: 60rpx;
					border: 1rpx solid #ddd;
					border-radius: 30rpx;
					padding: 0 30rpx;
					font-size: 24rpx;
				}
				
				.search-btn {
					width: 120rpx;
					height: 60rpx;
					background-color: #409EFF;
					color: #fff;
					border-radius: 30rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-left: 20rpx;
					font-size: 24rpx;
				}
			}
			
			.filter-box {
				display: flex;
				
				.filter-item {
					display: flex;
					align-items: center;
					padding: 10rpx 20rpx;
					background-color: #fff;
					border-radius: 20rpx;
					margin-right: 20rpx;
					box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
					
					text {
						font-size: 24rpx;
						color: #333;
						margin-right: 10rpx;
					}
					
					.iconfont {
						font-size: 20rpx;
						color: #666;
					}
				}
			}
		}
		
		.alert-section {
			background-color: #FFF7E6;
			border-radius: 10rpx;
			padding: 20rpx;
			margin-bottom: 30rpx;
			border-left: 4rpx solid #FA8C16;
			
			.alert-title {
				display: flex;
				align-items: center;
				margin-bottom: 15rpx;
				
				.iconfont {
					font-size: 28rpx;
					color: #FA8C16;
					margin-right: 10rpx;
				}
				
				text {
					font-size: 26rpx;
					font-weight: 600;
					color: #333;
				}
			}
			
			.alert-list {
				.alert-item {
					display: flex;
					align-items: center;
					background-color: #fff;
					border-radius: 8rpx;
					padding: 15rpx;
					margin-bottom: 10rpx;
					
					.item-name {
						flex: 1;
						font-size: 24rpx;
						color: #333;
						font-weight: 600;
					}
					
					.item-stock {
						font-size: 22rpx;
						color: #FA8C16;
						margin-right: 20rpx;
					}
					
					.item-min {
						font-size: 22rpx;
						color: #666;
					}
				}
			}
		}
		
		.stock-section {
			.stock-title {
				font-size: 28rpx;
				font-weight: 600;
				color: #333;
				margin-bottom: 20rpx;
			}
			
			.stock-list {
				.stock-item {
					background-color: #fff;
					border-radius: 10rpx;
					padding: 20rpx;
					margin-bottom: 20rpx;
					box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
					
					.item-header {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-bottom: 15rpx;
						
						.item-name {
							font-size: 26rpx;
							font-weight: 600;
							color: #333;
						}
						
						.item-status {
							padding: 5rpx 15rpx;
							border-radius: 15rpx;
							font-size: 20rpx;
						}
						
						.status-warning {
							background-color: #FFF7E6;
							color: #FA8C16;
						}
						
						.status-normal {
							background-color: #F6FFED;
							color: #52C41A;
						}
					}
					
					.item-body {
						margin-bottom: 15rpx;
						
						.info-item {
							display: flex;
							margin-bottom: 10rpx;
							
							.label {
								width: 120rpx;
								font-size: 24rpx;
								color: #666;
							}
							
							.value {
								flex: 1;
								font-size: 24rpx;
								color: #333;
							}
						}
					}
					
					.item-footer {
						.display: flex;
						justify-content: flex-end;
						
						.detail-btn {
							padding: 8rpx 16rpx;
							background-color: #409EFF;
							color: #fff;
							border-radius: 16rpx;
							font-size: 20rpx;
						}
					}
				}
			}
		}
	}
}
</style>