<template>
	<view class="pick-card-container">
		<checkbox-group v-for="(item, index) in list" :key="index" @change="e => selectVal(e, item, index)">
			<label class="card-label">
				<view class="card-wrapper" :class="{'card-active': item.checked}" @click="openDetails(item.pickStatus, item.id)">
					<!-- 卡片头部 -->
					<view class="card-header">
						<view class="header-left">
							<checkbox v-if='item.pickStatus == 0' :checked="item.checked" class="card-checkbox" />
							<text class="order-code">{{ item.code }}</text>
						</view>
						<view class="status-badge" :class="getStatusClass(item.pickStatus)">
							{{ getStatusText(item.pickStatus) }}
						</view>
					</view>

					<!-- 卡片内容 -->
					<view class="card-content">
						<!-- 产品信息行 -->
						<view class="info-row">
							<view class="info-item">
								<text class="info-label">产品编码</text>
								<text class="info-value">{{ item.productCode }}</text>
							</view>
							<view class="info-item">
								<text class="info-label">名称</text>
								<text class="info-value">{{ item.productName }}</text>
							</view>
						</view>

						<!-- 规格信息行 -->
						<view class="info-row">
							<view class="info-item">
								<text class="info-label">牌号</text>
								<text class="info-value">{{ item.brandNo }}</text>
							</view>
							<view class="info-item">
								<text class="info-label">型号</text>
								<text class="info-value">{{ item.model }}</text>
							</view>
						</view>

						<!-- 数量状态行 -->
						<view class="info-row">
							<view class="info-item">
								<text class="info-label">生产数量</text>
								<text class="info-value">{{ item.formingNum }} {{ item.unit }}</text>
							</view>
							<view class="info-item">
								<text class="info-label">状态</text>
								<text class="info-value">{{ statusList[item.status] }}</text>
							</view>
						</view>

						<!-- 工艺路线 -->
						<view class="info-row route-row">
							<text class="info-label">工艺路线</text>
							<text class="route-value">{{ item.produceRoutingName }}</text>
						</view>
					</view>
				</view>
			</label>
		</checkbox-group>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default: () => []
			},
		},

		data() {
			return {
				statusList: {
					4: '待生产',
					5: '生产中',
					6: '已完成',
					7: '已延期',
					8: '待下达'
				}
			}
		},
		methods: {
			selectVal(e, val, index) {
				this.list[index].checked = !this.list[index].checked
			},
			
			openDetails(pickStatus, id) {
				if(pickStatus == 1 || pickStatus == 2) {
					 let url =  `/pages/pda/picking/bill/index?id=${id}&status=${pickStatus}`
					uni.navigateTo({
						url
					})
				}
			},
			
			// 获取状态文本
			getStatusText(pickStatus) {
				const statusMap = {
					0: '未领料',
					1: '已领料',
					2: '已出库'
				}
				return statusMap[pickStatus] || ''
			},
			
			// 获取状态样式类
			getStatusClass(pickStatus) {
				const classMap = {
					0: 'status-pending',
					1: 'status-picked',
					2: 'status-out'
				}
				return classMap[pickStatus] || ''
			}
		}

	}
</script>


<style lang="scss" scoped>
	.pick-card-container {
		width: 100%;
		padding: 0;
	}

	.card-label {
		display: block;
		width: 100%;
	}

	.card-wrapper {
		margin: 24rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		box-shadow: 0 4rpx 12rpx 0 rgba(0, 0, 0, 0.05);
		overflow: hidden;
		transition: all 0.3s ease;
		
		&.card-active {
			box-shadow: 0 4rpx 16rpx 0 rgba(64, 158, 255, 0.2);
			border: 2rpx solid rgba(64, 158, 255, 0.3);
		}
	}

	/* 卡片头部 */
	.card-header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx 28rpx;
		background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
		border-bottom: 1rpx solid #f0f0f0;
	}

	.header-left {
		display: flex;
		align-items: center;
		flex: 1;
		min-width: 0;
	}

	.card-checkbox {
		flex-shrink: 0;
		margin-right: 16rpx;
		transform: scale(1.1);
	}

	.order-code {
		font-size: 30rpx;
		font-weight: 600;
		color: #303133;
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	/* 状态徽章 */
	.status-badge {
		flex-shrink: 0;
		padding: 8rpx 20rpx;
		border-radius: 24rpx;
		font-size: 24rpx;
		font-weight: 500;
		margin-left: 16rpx;
		
		&.status-pending {
			background: #FFF7E6;
			color: #FA8C16;
		}
		
		&.status-picked {
			background: #E6F7FF;
			color: #1890FF;
		}
		
		&.status-out {
			background: #F6FFED;
			color: #52C41A;
		}
	}

	/* 卡片内容 */
	.card-content {
		padding: 24rpx 28rpx;
	}

	.info-row {
		display: flex;
		align-items: flex-start;
		margin-bottom: 20rpx;
		
		&:last-child {
			margin-bottom: 0;
		}
		
		&.route-row {
			flex-direction: column;
			padding-top: 8rpx;
			border-top: 1rpx solid #f5f5f5;
		}
	}

	.info-item {
		flex: 1;
		display: flex;
		flex-direction: column;
		min-width: 0;
		padding-right: 16rpx;
		
		&:last-child {
			padding-right: 0;
		}
	}

	.info-label {
		font-size: 24rpx;
		color: #909399;
		margin-bottom: 8rpx;
		line-height: 1.4;
	}

	.info-value {
		font-size: 28rpx;
		color: #303133;
		font-weight: 500;
		line-height: 1.5;
		word-break: break-all;
	}

	.route-value {
		font-size: 28rpx;
		color: $theme-color;
		font-weight: 500;
		margin-top: 8rpx;
		line-height: 1.6;
		word-break: break-all;
	}

	/* 复选框选中样式 */
	/deep/ .uni-checkbox-input {
		border-radius: 6rpx;
	}
	
	/deep/ .uni-checkbox-input-checked {
		background-color: $theme-color !important;
		border-color: $theme-color !important;
	}

	/* 响应式适配 */
	@media screen and (max-width: 375px) {
		.card-wrapper {
			margin: 20rpx;
		}
		
		.card-header,
		.card-content {
			padding: 20rpx 24rpx;
		}
		
		.order-code {
			font-size: 28rpx;
		}
		
		.info-value,
		.route-value {
			font-size: 26rpx;
		}
	}
</style>