<template>
	<view class="page-container uni-column" >
		<!-- 零存库部分 -->
		<view class="title unfit-title uni-row">
			<view class="title">零取</view>
		</view>
		<view class="consultation-container uni-column" style="margin-bottom: 200rpx;padding-bottom: 140rpx">
			
			<view style="width: 100%;">
				<zb-table 
				    :columns="column1"
				    :stripe="true"
					:fit="true"
					@toggleRowSelection="selectionChange"
					 @toggleAllSelection="toggleAllSelection"
				    :data="listData"></zb-table>
<!-- 				<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
					@selection-change="selectionChange">
					<uni-tr>
						<uni-th style="font-size: 25rpx;" width="100" align="center">批次号</uni-th>
						<uni-th style="font-size: 25rpx;" width="100" align="center">操作者</uni-th>
						<uni-th style="font-size: 25rpx;" width="80" align="center">数量</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in listData" :key="index">
						<uni-th style="font-size: 24rpx;" width="100" align="center">{{ item.lotCode }}</uni-th>
						<uni-th style="font-size: 24rpx;" width="100" align="center">{{ item.storagerName }}</uni-th>
						<uni-th style="font-size: 24rpx;" width="80" align="center">{{ item.storageNum }}</uni-th>

					</uni-tr>
				</uni-table> -->
				</view>
				</view>
				<view class="bottom uni-row">
					<button class="start-batch-btn" style="margin-right: 10rpx;" type="primary"
					  :disabled="selections.length == 0"	@click="handleAdd">确认取出</button>
				</view>
			</view>
			
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onMounted,
		getCurrentInstance
	} from 'vue';

	import {
		getStorageRetrievalList
	} from '@/api/business/storageRetrieval.js'
	import {
		onLoad,
		onReady,
		onUnload,
		onShow
	} from '@dcloudio/uni-app'
	import {
		store
	} from '@/store/index.js'

	const selections = ref([])
	const listData = ref([])
	const column1 = [
		{ type:'selection', width:50 },
	    { name: 'lotCode', label: '批次号',align:'center'},
	    { name: 'storagerName', label: '操作者',align:'center' },
{ name: 'storageNum', label: '数量',align:'center' },
	]

	/***************************** 页面生命周期函数 *****************************/

	onLoad((options) => {
		 const data = decodeURIComponent(options.data);
		
		  // 将解码后的字符串转换回对象
		  const lotInfo = JSON.parse(data);
		console.log(lotInfo)
		init(lotInfo)
		})

	/***************************** 定义了一些方法 *****************************/
	const init = (data) => {
		console.log(data)
		getStorageRetrievalList(data).then(res =>{
			listData.value = res.rows
		})
	}
	function selectionChange(checked,arr) {
		console.log(checked,arr)
		 getSelectionList(arr)
	}
	function getSelectionList(data) {
		selections.value = data
		console.log(selections.value)
	}
	function toggleAllSelection(checked,arr) {
		getSelectionList(arr)
	}
	//选择带回
	function handleAdd() {
		uni.$emit('addInfoEvent', {
			data:selections.value
		})
		uni.navigateBack()
	}
</script>

<style lang="scss">
	.unfit-title{
		height: 30rpx;
		position: fixed;
		top: 30rpx;
	}
	.page-container {
		height: 90%;
		background-color: #ffffff;
		font-size: 28rpx;

		>.title {
			position: relative;
			top: 0;
			font-weight: 700;
			margin: 24rpx 16rpx;
		}
	}

	.unfit-title {
		margin-bottom: 24rpx;
		justify-content: space-between;
		align-items: center;

		text {
			font-size: 28rpx;
			font-weight: 700;
		}

	}

	.bottom {
		height: 10%;
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		height: 100rpx;
		border-top: 1px solid #999999;
		padding: 16rpx 32rpx;
		align-items: center;
		background-color: #fff;
		justify-content: space-evenly;
		z-index: 99;

		.start-batch-btn {
			flex: 1;
			height: 80rpx;
			line-height: 80rpx;
			border-radius: 8rpx;
			color: #FFFFFF;
			font-size: 28rpx;
		}
	}
	.consultation-container {
		margin: 0 16rpx;
		padding: 24rpx;
		background-color: #ffffff;
		border-radius: 8rpx;
	
	}
	.zb-table .item-tr {
		flex-direction: row;
	}
</style>