<template>
	<view class="service-list-container">
		<view class="service-status-toolbar">
			<text class="toolbar-total">共{{ total || list.length }}条</text>
			<input
				class="toolbar-input"
				v-model="salesName"
				placeholder="所属销售姓名"
				placeholder-style="color: #b0b0b0"
				confirm-type="search"
				@confirm="handleRefresh"
				@input="onInputChange"
			/>
			<input
				class="toolbar-input"
				v-model="customerName"
				placeholder="客户姓名"
				placeholder-style="color: #b0b0b0"
				confirm-type="search"
				@confirm="handleRefresh"
				@input="onInputChange"
			/>
			<view class="toolbar-actions">
				<view class="toolbar-btn toolbar-btn--refresh" @click="handleRefresh">
					<uni-icons type="refresh" size="18" color="#2A68FF"></uni-icons>
					<text>刷新</text>
				</view>
			</view>
		</view>
		<scroll-view class="service-list" scroll-y @scrolltolower="onReachBottom">
			<view 
				class="service-item" 
				v-for="(item, index) in list" 
				:key="index"
				@click="$emit('itemClick', item)">
				<view class="service-header">
					<text class="service-title">{{ item.title }}</text>
					<view class="service-actions">
						<text class="archive-text">档案</text>
						<uni-icons type="right" size="16" color="#999"></uni-icons>
					</view>
				</view>
				<view class="service-meta">
					<text class="service-date">{{ item.date }}</text>
				</view>
				<view class="service-content">
					<text class="service-desc">{{ item.description }}</text>
				</view>
				<view class="service-customer">
					<view class="customer-avatar">
						<text class="avatar-text">{{ item.customerName.charAt(0) }}</text>
					</view>
					<text class="customer-name">{{ item.customerName }}</text>
				</view>
				<view class="ai-tag">
					<text>以上内容由AI生成</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name: 'ServiceList',
		props: {
			list: {
				type: Array,
				default: () => []
			},
			total: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				salesName: '',
				customerName: ''
			}
		},
		methods: {
			onInputChange() {
				// 输入框变化时，可以在这里添加实时搜索逻辑（如果需要）
			},
			handleRefresh() {
				// 触发刷新事件，并传递查询参数
				this.$emit('filterClick', {
					salesName: this.salesName.trim(),
					customerName: this.customerName.trim()
				});
			},
			onReachBottom() {
				this.$emit('reachBottom');
			}
		}
	}
</script>

<style scoped>
	.service-list-container {
		/* 使用绝对定位，从tab页底部开始，到底部导航栏结束 */
		position: absolute;
		top: 160rpx; /* 导航栏(88rpx) + tab页(72rpx) = 160rpx */
		left: 0;
		right: 0;
		bottom: 96rpx; /* 底部导航栏高度 */
		display: flex;
		flex-direction: column;
		background-color: #F5F5F5;
		padding: 24rpx 16rpx;
		box-sizing: border-box;
	}
	
	.service-status-toolbar {
		display: flex;
		flex-wrap: nowrap;
		align-items: center;
		gap: 8rpx; /* 增加间距，避免元素被挤压 */
		padding: 12rpx 8rpx; /* 增加内边距，给搜索框更多空间 */
		margin-bottom: 24rpx; /* 与列表项间距保持一致（24rpx） */
		background-color: #F8F8FA;
		border-radius: 8rpx;
		border: 1px solid #EFEFF2;
		overflow-x: auto;
		min-height: 64rpx; /* 设置最小高度，确保搜索区域不被挤压 */
		box-sizing: border-box;
		flex-shrink: 0; /* 防止被压缩 */
	}
	
	.toolbar-total {
		font-size: 24rpx;
		color: #666;
		white-space: nowrap;
		flex-shrink: 0;
		margin-right: 8rpx; /* 增加右边距，与搜索框保持距离 */
		line-height: 1.2;
		padding: 0 4rpx; /* 增加左右内边距 */
	}
	
	.toolbar-input {
		flex: 1;
		min-width: 120rpx; /* 增加最小宽度，避免被挤压变形 */
		max-width: 200rpx; /* 设置最大宽度，保持合理比例 */
		height: 56rpx; /* 稍微增加高度，提升可用性 */
		line-height: 56rpx;
		background-color: #F5F6FA;
		border-radius: 8rpx;
		padding: 0 12rpx; /* 增加左右内边距 */
		font-size: 24rpx;
		border: 1px solid transparent;
		box-sizing: border-box;
		flex-shrink: 1; /* 允许适当收缩，但保持最小宽度 */
	}
	
	.toolbar-actions {
		display: flex;
		align-items: center;
		margin-left: auto;
		flex-shrink: 0;
		gap: 8rpx; /* 增加按钮之间的间距 */
	}
	
	.toolbar-btn {
		padding: 0 12rpx; /* 增加左右内边距 */
		height: 56rpx; /* 与输入框高度保持一致 */
		min-width: 56rpx;
		color: #2A68FF;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 4rpx; /* 增加图标和文字之间的间距 */
		font-size: 24rpx;
		font-weight: 400;
		line-height: 1;
		box-sizing: border-box;
	}
	
	.toolbar-btn text {
		color: #2A68FF;
	}
	
	.service-list {
		/* 使用flex填充剩余空间 */
		flex: 1;
		background-color: transparent;
		box-sizing: border-box;
		overflow-y: auto;
	}
	
	.service-item {
		width: 100%;
		box-sizing: border-box;
		background-color: #FFFFFF;
		border-radius: 16rpx;
		padding: 32rpx;
		margin-bottom: 24rpx;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
	}
	
	.service-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 16rpx;
	}
	
	.service-title {
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
	}
	
	.service-actions {
		display: flex;
		align-items: center;
	}
	
	.archive-text {
		font-size: 26rpx;
		color: #999;
		margin-right: 8rpx;
	}
	
	.service-meta {
		display: flex;
		align-items: center;
		margin-bottom: 16rpx;
	}
	
	.service-date {
		font-size: 24rpx;
		color: #999;
		margin-right: 16rpx;
	}
	
	.service-duration {
		font-size: 24rpx;
		color: #999;
	}
	
	.service-content {
		margin-bottom: 24rpx;
	}
	
	.service-desc {
		font-size: 28rpx;
		color: #666;
		line-height: 1.6;
	}
	
	.service-customer {
		display: flex;
		align-items: center;
		margin-bottom: 16rpx;
	}
	
	.customer-avatar {
		width: 64rpx;
		height: 64rpx;
		background-color: #2196F3;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 16rpx;
	}
	
	.avatar-text {
		font-size: 32rpx;
		color: #FFFFFF;
		font-weight: 500;
	}
	
	.customer-name {
		font-size: 28rpx;
		color: #333;
	}
	
	.ai-tag {
		padding-top: 16rpx;
		border-top: 1px solid #F0F0F0;
	}
	
	.ai-tag text {
		font-size: 24rpx;
		color: #999;
	}
</style>

