<template>
	<view class="report-card" @click="handleCardClick">
		<!-- 带头像和名字的卡片 -->
		<view v-if="showAvatar" class="card-with-avatar">
			<view class="card-header">
				<view class="user-info">
					<image class="avatar" :src="item.avatar || '/static/images/logo.png'" mode="aspectFill"></image>
					<view class="user-details">
						<text class="nickname">{{ item.nickName }}</text>
						<text v-if="item.deptName" class="dept-name">({{ item.deptName }})</text>
					</view>
				</view>
				<view class="report-time">{{ formatDate(item.createTime) }}</view>
			</view>
			
			<view class="card-content">
				<view class="project-info">
					<view class="project-name">
						<text v-if="item.prePay > 0" class="star-icon">⭐</text>
						<text>{{ item.projectName }}</text>
					</view>
					<view class="project-details">
						<u-tag v-if="!item.projectCode" type="error" text="无" size="mini"></u-tag>
						<u-tag v-else :text="item.projectCode" size="mini"></u-tag>
						<text class="project-num">{{ item.projectNum }}</text>
					</view>
				</view>
				
				<view class="work-info">
					<view class="work-location">
						<text>{{ item.workPlace }}</text>
					</view>
					<u-tag :type="item.workType === 0 ? 'primary' : 'warning'" :text="item.workType === 0 ? '国内' : '国外'" size="mini"></u-tag>
				</view>
			</view>
		</view>
		
		<!-- 不带头像的卡片 -->
		<view v-else class="card-simple">
			<view class="card-header-simple">
				<view class="project-name">
					<text v-if="item.prePay > 0" class="star-icon">⭐</text>
					<text>{{ item.projectName }}</text>
				</view>
				<view class="report-time">{{ formatDate(item.createTime) }}</view>
			</view>
			
			<view class="card-content-simple">
				<view class="project-details">
					<u-tag v-if="!item.projectCode" type="error" text="无" size="mini"></u-tag>
					<u-tag v-else :text="item.projectCode" size="mini"></u-tag>
					<text class="project-num">{{ item.projectNum }}</text>
				</view>
				
				<view class="work-info">
					<view class="work-location">
						<text>{{ item.workPlace }}</text>
					</view>
					<u-tag :type="item.workType === 0 ? 'primary' : 'warning'" :text="item.workType === 0 ? '国内' : '国外'" size="mini"></u-tag>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'ReportCard',
	props: {
		// 报工数据
		item: {
			type: Object,
			required: true
		},
		// 是否显示头像和名字
		showAvatar: {
			type: Boolean,
			default: true
		}
	},
	methods: {
		// 格式化日期
		formatDate(date) {
			if (!date) return '';
			const d = new Date(date);
			return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
		},
		
		// 卡片点击事件
		handleCardClick() {
			this.$emit('card-click', this.item);
		}
	}
}
</script>

<style lang="scss" scoped>
.report-card {
	background-color: #fff;
	border-radius: 16rpx;
	margin-bottom: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
	overflow: hidden;
	transition: all 0.3s ease;
	
	&:active {
		transform: scale(0.98);
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.12);
	}
	
	// 带头像的卡片样式
	.card-with-avatar {
		.card-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 24rpx;
			border-bottom: 1rpx solid #f0f0f0;
			
			.user-info {
				display: flex;
				align-items: center;
				
				.avatar {
					width: 60rpx;
					height: 60rpx;
					border-radius: 50%;
					margin-right: 16rpx;
				}
				
				.user-details {
					.nickname {
						font-size: 28rpx;
						font-weight: 500;
						color: #333;
						display: block;
					}
					
					.dept-name {
						font-size: 24rpx;
						color: #666;
						margin-top: 4rpx;
						display: block;
					}
				}
			}
			
			.report-time {
				font-size: 24rpx;
				color: #999;
			}
		}
		
		.card-content {
			padding: 24rpx;
			
			.project-info {
				margin-bottom: 20rpx;
				
				.project-name {
					font-size: 30rpx;
					font-weight: 500;
					color: #333;
					margin-bottom: 12rpx;
					
					.star-icon {
						margin-right: 8rpx;
					}
				}
				
				.project-details {
					display: flex;
					align-items: center;
					gap: 12rpx;
					
					.project-num {
						font-size: 24rpx;
						color: #666;
					}
				}
			}
			
			.work-info {
				display: flex;
				justify-content: space-between;
				align-items: center;
				
				.work-location {
					display: flex;
					align-items: center;
					gap: 8rpx;
					font-size: 26rpx;
					color: #666;
				}
			}
		}
	}
	
	// 不带头像的卡片样式
	.card-simple {
		padding: 24rpx;
		
		.card-header-simple {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;
			
			.project-name {
				font-size: 30rpx;
				font-weight: 500;
				color: #333;
				
				.star-icon {
					margin-right: 8rpx;
				}
			}
			
			.report-time {
				font-size: 24rpx;
				color: #999;
			}
		}
		
		.card-content-simple {
			.project-details {
				display: flex;
				align-items: center;
				gap: 12rpx;
				margin-bottom: 16rpx;
				
				.project-num {
					font-size: 24rpx;
					color: #666;
				}
			}
			
			.work-info {
				display: flex;
				justify-content: space-between;
				align-items: center;
				
				.work-location {
					display: flex;
					align-items: center;
					gap: 8rpx;
					font-size: 26rpx;
					color: #666;
				}
			}
		}
	}
}
</style> 