<template>
	<view class="feed-card-list">
		<checkbox-group v-for="(item, index) in list" :key="index" @change="e => selectVal(e, item, index)">
			<label>
				<view class="card-item" @click="openDetails(item.feedStatus, item.id)">
					<!-- 卡片头部：编码 + 状态 -->
					<view class="card-header">
						<view class="header-left">
							<checkbox v-if="item.feedStatus == 0" :checked="item.checked" class="card-checkbox" />
							<text class="order-code">{{ item.code }}</text>
						</view>
						<view class="status-tag" :class="item.feedStatus == 0 ? 'status-pending' : 'status-done'">
							{{ item.feedStatus == 0 ? '未投料' : item.feedStatus == 1 ? '已投料' : '' }}
						</view>
					</view>

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

						<view class="info-row">
							<view class="info-col">
								<text class="info-label">牌号</text>
								<text class="info-value">{{ item.brandNo }}</text>
							</view>
							<view class="info-col">
								<text class="info-label">型号</text>
								<text class="info-value">{{ item.model }}</text>
							</view>
						</view>

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

						<view class="info-row info-row--full">
							<view class="info-col info-col--full">
								<text class="info-label">工艺路线</text>
								<text class="info-value info-value--highlight">{{ item.produceRoutingName }}</text>
							</view>
						</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(feedStatus, id) {
				if (feedStatus == 1) {
					let url = `/pages/pda/feeding/bill/index?id=${id}`
					uni.navigateTo({
						url
					})
				}
			}
		}

	}
</script>


<style lang="scss" scoped>
	.feed-card-list {
		padding: 0 24rpx;
	}

	.card-item {
		background-color: #fff;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
	}

	.card-header {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx 28rpx;
		border-bottom: 1rpx solid #f0f0f0;

		.header-left {
			display: flex;
			flex-direction: row;
			align-items: center;
			flex: 1;
			overflow: hidden;
		}

		.card-checkbox {
			flex-shrink: 0;
			margin-right: 16rpx;
		}

		.order-code {
			color: $uni-text-color;
			font-size: $j-font-text-default;
			font-weight: 600;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.status-tag {
			flex-shrink: 0;
			font-size: $uni-font-size-ssm;
			padding: 6rpx 20rpx;
			border-radius: 20rpx;
			margin-left: 16rpx;
		}

		.status-pending {
			color: #E6A23C;
			background-color: rgba(230, 162, 60, 0.1);
		}

		.status-done {
			color: $theme-color;
			background-color: rgba(21, 122, 44, 0.1);
		}

		/deep/ .uni-checkbox-input-checked {
			background-color: $theme-color !important;
			border-color: $theme-color !important;
		}
	}

	.card-body {
		padding: 20rpx 28rpx 24rpx;
	}

	.info-row {
		display: flex;
		flex-direction: row;
		margin-bottom: 16rpx;

		&:last-child {
			margin-bottom: 0;
		}

		&--full {
			flex-direction: column;
		}
	}

	.info-col {
		flex: 1;
		display: flex;
		flex-direction: column;
		min-width: 0;

		&--full {
			flex: none;
			width: 100%;
		}

		.info-label {
			font-size: $uni-font-size-ssm;
			color: $uni-text-color-grey;
			line-height: 36rpx;
			margin-bottom: 4rpx;
		}

		.info-value {
			font-size: $uni-font-size-sm;
			color: $uni-text-color;
			line-height: 40rpx;
			word-break: break-all;

			&--highlight {
				color: $theme-color;
				font-weight: 500;
			}
		}
	}
</style>
