<template>
	<view class="uni-column" style="height: 100%; background-color: #f5f5f5;">
		<scroll-view class="scroll-container" scroll-y>
			<view v-for="(item, index) in listData" :key="index" :class="{'list-item':true,'selected':isSelected(index)}"
				@click="handleSelection(index)">
				<view class="title-container uni-row">
					<view class="title uni-row">
						<text class="label">{{ item['door'] }}</text>
						<text class="label code">{{ item['process'] }}</text>
						<text class="label code" style="margin-left: 16rpx;">→</text>
						<text class="label code" style="margin-left: 16rpx;">{{ item['car'] }}</text>
					</view>

					<view class="right-info uni-row">
						<view class="uni-row"><text class="label right">删除</text></view>
					</view>
				</view>
				<view class="item-info uni-row"> <text class="label ">产品描述</text>
					<text class="label right" style="color: #000000;">{{ item['description'] }}</text>
				</view>
				<view class="item-info uni-row"> <text class="label">批次</text>
					<text class="label right ">{{ item['batch'] }}</text>
				</view>
				<view class="item-info uni-row">
					<text class="label">箱数</text>
					<text class="label right">{{ item['cases'] }}</text>
				</view>
				<view class="item-info uni-row">
					<text class="label">箱号</text>
					<text class="label right">{{ item['caseNumber']}}</text>
				</view>
			</view>
		</scroll-view>
		<view class="bottom uni-row">
			<button class="bottom-btn left-btn ">继续扫码</button>
			<button class="bottom-btn right-btn" @click="handleTurnoverTask(null)">确认周转</button>
		</view>
		<dialog-turnoverTask ref="turnoverTaskDialog" />
	</view>


</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad,
		onReady
	} from '@dcloudio/uni-app'


	onLoad(() => {

	})
	const active = ref(false)
	const selection =ref([])
	const turnoverTaskDialog = ref(null)
	const listData = ref([{
			door: "A门",
			process: "粗磨",
			car: "NC车",
			description: "万博_039561419_15*110.1",
			batch: "DC23727410070",
			cases: 5,
			caseNumber: "X12522、X55222、X15522、J5211、J5211"

		},
		{
			door: "A门",
			process: "粗磨",
			car: "NC车",
			description: "万博_039561419_15*110.1",
			batch: "DC23727410070",
			cases: 5,
			caseNumber: "X12522、X55222、X15522、J5211、J5211"

		},
		{
			door: "A门",
			process: "粗磨",
			car: "NC车",
			description: "万博_039561419_15*110.1",
			batch: "DC23727410070",
			cases: 5,
			caseNumber: "X12522、X55222、X15522、J5211、J5211"

		},
		{
			door: "A门",
			process: "粗磨",
			car: "NC车",
			description: "万博_039561419_15*110.1",
			batch: "DC23727410070",
			cases: 5,
			caseNumber: "X12522、X55222、X15522、J5211、J5211"

		},
		{
			door: "A门",
			process: "粗磨",
			car: "NC车",
			description: "万博_039561419_15*110.1",
			batch: "DC23727410070",
			cases: 5,
			caseNumber: "X12522、X55222、X15522、J5211、J5211"

		}

	])
	const handleStartTurnover = (data) => {
		let _data = data ?? {}
		// 调用子组件中的方法
		turnoverTaskDialog.value.open(_data)
	}
	const isSelected = (index) => {
	return	selection.value.includes(index)
	}
	const handleSelection = (index) => {
		console.log(index)
		
		  const buttonIndex = selection.value.indexOf(index);
		      if (buttonIndex > -1) {
		        selection.value.splice(buttonIndex, 1); // 取消选中
		      } else {
		        selection.value.push(index); // 选中
		      }
			  console.log(selection.value)
	}
</script>

<style lang="scss">
	.scroll-container {
		position: absolute;
		top: 24rpx;
		right: 0;
		bottom: 160rpx;
		left: 0;
	}

	.selected {
		border: 1px solid #1684fc;
	}

	.list-item {
		background-color: #fff;
		position: relative;
		padding: 16rpx;
		padding-bottom: 24rpx;
		margin: 0 24rpx;
		margin-bottom: 24rpx;
		border-radius: 8rpx;

		.title-container {
			justify-content: space-between;
			margin-top: 8rpx;
			margin-bottom: 16rpx;

			.title {
				height: 48rpx;
				align-items: center;

				.label {
					color: #1684fc;
					font-size: 32rpx;
					font-weight: bold;

					&.code {
						color: #000000;
						margin-left: 32rpx;
					}
				}
			}
		}

		.item-info {
			margin-bottom: 16rpx;

			.label {
				font-size: 28rpx;
				width: 152rpx;
				color: #808080;

				&.right {
					flex: 1;
					color: #808080;
				}
			}
		}

		.right-info {
			justify-content: flex-end;
			margin-top: 2rpx;

			.label {
				font-size: 28rpx;
				color: #ff0000;
			}
		}
	}

	.bottom {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		height: 100rpx;
		padding: 16rpx 24rpx;
		align-items: center;
		background-color: #FFFFFF;
		justify-content: space-between;

		.bottom-btn {
			flex: 1;
			font-size: 28rpx;
			color: #FFFFFF;

			&.left-btn {
				background-color: #1684fc;
			}

			&.right-btn {
				background-color: rgb(255, 121, 1);
				margin-left: 24rpx;

			}
		}
	}
</style>