<template>
	<dialog-base class="dialog-body" ref="baseDialog" title="周转任务">
		<view class="list-item">
			<view v-for="(item, index) in confirmTurnoverList" :key="index">
				<view class="list-title uni-row"><text class="label">{{ item['deptName'] }}</text>
					<text class="label">→</text>
					<text class="label">{{ item['deptName'] }}</text>
				</view>
				<view class="list-container">
					<view class="list-container-item uni-row">
						<text class="label">批次</text>
						<text class="label value">{{item['lotCode']}}</text>
					</view>
					<view class="list-container-item uni-row">
						<text class="label">箱数</text>
						<text class="label value">{{item['carriers']}}</text>
					</view>
					<view class="list-container-item uni-row">
						<text class="label">数量</text>
						<text class="label value">{{item['qualifiedNum']}}</text>
					</view>
					<view class="list-container-item uni-row">
						<text class="label">箱号</text>
						<text class="label value">{{item['carrierName']}}</text>
					</view>
					<view class="list-container-item uni-row">
						<text class="label">申请时间</text>
						<text class="label value">{{item['startTime']}}</text>
					</view>
					<view class="list-container-item uni-row">
						<text class="label">申请人</text>
						<text class="label value">{{item['nickName']}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="add-btn-container uni-row">
			<button type="primary" class="btn" @click="handleConfirmDelivery">确认周转</button>
		</view>

	</dialog-base>
</template>

<script setup>
	import {
		ref,
		getCurrentInstance
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import { updateDayWorkItemBatch } from '@/api/business/dayWorkItem.js'

	const baseDialog = ref(null)
	const confirmTurnoverList = ref([])

	function open(data) {
		confirmTurnoverList.value = data
		baseDialog.value.open()
	}
	
	function close(data) {
		baseDialog.value.close()
	}

	defineExpose({
		open
	})

	function handleConfirmDelivery() {
		// 设置周转状态
		for (let i = 0; i < confirmTurnoverList.value.length; i++) {
			confirmTurnoverList.value[i].status = confirmTurnoverList.value[i].status ='5';
		}
		console.log(confirmTurnoverList.value)
		updateDayWorkItemBatch(confirmTurnoverList.value).then(res => {
			if (res.code === 200) {
				uni.showToast({
					icon: 'success',
					title: '操作成功',
					duration: 2000
				});
				uni.$emit('confirmDelivery');
				uni.$emit('dayworkItemUpdate');
			} else {
				uni.showToast({
					icon: 'error',
					title: '操作失败',
					duration: 2000
				});
			}
		})
		close();
	}
</script>

<style lang="scss">
	.dialog-body {
		.list-title {
			margin: 40rpx 0 20rpx 0;

			.label {
				padding-right: 40rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}

		.list-item {
			overflow: auto;
			height: 700rpx;
		}

		.list-container {
			width: 100%;
			display: flex;
			align-items: flex-start;
			padding: 0 4rpx;

			.list-container-item {
				width: 100%;
				padding: 12rpx 8rpx;
				align-items: center;

				.label {
					font-size: 28rpx;
					color: gray;
					width: 144rpx;

					&.value {

						flex: 1;
						color: #000000;
					}
				}
			}

		}

		.add-btn-container {
			margin-top: 32rpx;

			.btn {
				flex: 1;
			}
		}
	}
</style>