<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">
				<view class="title-container uni-row" style="justify-content: flex-start;">
					<view class="title uni-row">
						<text class="label">批次号：</text>
						<text class="label code">{{ item['batchNumber'] }}</text>
					</view>
					<view class=" uni-row" style="margin-left: 16rpx;">
						<view v-if="item['status'] == 0" class="tag"><text class="label">进行中</text></view>
						<view v-else-if="item['status'] == 1" class="tag turnover "><text class="label">周转中</text>
						</view>
						<view v-else type="default" class="tag finished"><text class="label">已完成</text></view>
					</view>
				</view>
				<view class="item-info uni-row">
					<text class="label">箱号</text>
					<text class="label right">{{ item['caseNumber'] }}</text>
				</view>
				<view class="item-info uni-row">
					<text class="label">总工时</text>
					<text class="label right">{{ item['totalWorkingHours']}}h</text>
				</view>
				<view class="item-info uni-row">
					<text class="label">合格数/投入数</text>
					<text class="label right">{{ item['qualifiedQuantity'] }}/{{item['invest']}}</text>
				</view>
				<view class="item-info uni-row">
					<text class="label">上道工序</text>
					<text class="label right">{{ item['previousProcess'] }}</text>
				</view>
				<view class="item-info uni-row">
					<text class="label">当前工序</text>
					<text class="label right">{{ item['currentProcess']}}</text>
				</view>
				<view class="item-info uni-row">
					<text class="label">下道工序</text>
					<text class="label right">{{ item['NextProcess'] }}</text>
				</view>
				<view class="status-btn uni-row">
					<view v-if="item['status'] == 0" class=" uni-row">
						<button class="turnover-tag" size="mini" @click="handleShowTurnoverApplication(null)">周转申请</button>
						<button class="reporting-tag" size="mini">去报工</button>
					</view>
					<view v-else-if="item['status'] == 1" class=" uni-row">
						<button class="turnover-tag" size="mini">取消周转</button>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="bottom uni-row">
			<button class="start-batch-btn" @click="handleShowLotDialog(null)">开始新批次</button>
		</view>
		<dialog-lot ref="lotDialog"/>
		<dialog-turnoverApplication ref="turnoverApplicationDialog" />
	</view>
	
</template>

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

	})
	const turnoverApplicationDialog = ref(null)
	const lotDialog = ref(null)
	const listData = ref([
		{
			batchNumber: "DC23727410070",
			caseNumber: "X12522、X522、X15522、J5211、J5112",
			totalWorkingHours: 135.5,
			qualifiedQuantity: 600,
			invest: 1000,
			previousProcess: "NC车1",
			currentProcess: "热处理",
			NextProcess: "清洗",
			status: 0
		},
		{
			batchNumber: "DC23727410070",
			caseNumber: "X12522、X522、X15522、J5211、J5112",
			totalWorkingHours: 135.5,
			qualifiedQuantity: 600,
			invest: 1000,
			previousProcess: "NC车1",
			currentProcess: "热处理",
			NextProcess: "清洗",
			status: 1
		},
		{
			batchNumber: "DC23727410070",
			caseNumber: "X12522、X522、X15522、J5211、J5112",
			totalWorkingHours: 135.5,
			qualifiedQuantity: 600,
			invest: 1000,
			previousProcess: "NC车1",
			currentProcess: "热处理",
			NextProcess: "清洗",
			status: 2
		}
	])
	const handleShowTurnoverApplication = (data) => {
		let _data = data ?? {}
		// 调用子组件中的方法
		turnoverApplicationDialog.value.open(_data)
	}
	const handleShowLotDialog = (data) => {
		let _data = data ?? {}
		// 调用子组件中的方法
		lotDialog.value.open(_data)
	}

</script>

<style lang="scss">
	.scroll-container {
		width: 92%;
		margin: 24rpx auto 0 auto;
		height: 90%;
	}

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

		.title-container {
			
			margin-top: 8rpx;
			margin-bottom: 16rpx;

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

				.label {
					font-size: 32rpx;
					font-weight: bold;

					&.code {
						margin-left: 8rpx;
					}
				}
			}

			.tag {
				border: 1px solid #1CE5B0;
				background-color: #F6FFFD;
				padding: 8rpx;
				border-radius: 8rpx;

				.label {
					color: #1CE5B0;
					font-size: 24rpx;
				}

				&.finished {
					border: 1px solid #BBBBBB;
					background-color: #F5F5F5;

					.label {
						color: #BBBBBB;
					}
				}

				&.turnover {
					border: 1px solid #FF7901;
					background-color: #F6FFFD;

					.label {
						color: #FF7901;
					}
				}
			}
		}

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

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

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

		.status-btn {
			justify-content: flex-end;
			align-items: center;

			.turnover-tag {
				padding-right: 12rpx;
				padding-left: 12rpx;
				border-radius: 8rpx;
				border: 1rpx solid #FF7901;
				background-color: #FF7901;
				font-size: 28rpx;
				color: #FFFFFF;

			}

			.reporting-tag {
				padding-right: 12rpx;
				padding-left: 12rpx;
				border-radius: 8rpx;
				margin-left: 16rpx;
				border: 1rpx solid #1684fc;
				background-color: #1684fc;
				font-size: 28rpx;
				color: #FFFFFF;

			}
		}
	}

	.bottom {
		height: 10%;
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		height: 80rpx;
		border-top: 1px solid #999999;
		padding: 16rpx 32rpx;
		align-items: center;
		background-color: #fff;

		.start-batch-btn {
			flex: 1;
			background-color: #1684fc;
			height: 100%;
			justify-content: center;
			align-items: center;
			border-radius: 8rpx;
			color: #FFFFFF;
			font-size: 28rpx;
		}
	}
</style>