<template>
	<dialog-base ref="baseDialog" title="仪器室选择">
		<view class="list-container">
	<view class="" style="margin: 0 20rpx 20rpx 0;width: 88%;">
		<uni-section title="请选择仪器室" title-font-size="32rpx" style="margin: 0 0 0 -16rpx;">
			<uni-data-select v-model="inspectionChamber" :localdata="inspectionChamberList"
				:clear="false"
				style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
		</uni-section>
	</view>
		</view>
		<view class="add-btn-container uni-row">
			<button type="default" class="btn" @click="handleConfirm">确认</button>
		</view>
	</dialog-base>
</template>

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

	const baseDialog = ref(null)
	const inspectionChamberList = ref([])
	const inspectionChamber = ref(null)
	const inspectionChamberId = ref(0)
	const emit = defineEmits(['handleSelectInspectionChamber'])

	onLoad(() => {

	})

	function open() {
		resetPage();
		baseDialog.value.open();
		init();
	}

	function resetPage() {
		inspectionChamberList.value = []
		inspectionChamber.value = null;
	}

	defineExpose({
		open
	})
	function close() {
		inspectionChamberList.value = []
		inspectionChamber.value = null;
		baseDialog.value.close()
	}

	function init() {
		if(store.processInspection != null && store.processInspection.inspectionChamberId != 0) {
			inspectionChamberId.value = store.processInspection.inspectionChamberId
		}
		
		handleGetInspectionChamberList();
	}

	function handleConfirm() {
		console.log(inspectionChamber.value)
		emit('handleSelectInspectionChamber', inspectionChamber.value);
		close()
	
		
	}

	// function handleChange() {
	// 	handleGetTurnoverListByDId(curDept.value);
	// }

	function handleGetInspectionChamberList() {
		getInspectionChamber({id:inspectionChamberId.value}).then(res => {
			if(res.rows.length >0) {
				  inspectionChamberList.value = res.rows.map(info => {
		    return { value: info.id, text: info.chamberName };
		  });
		  inspectionChamber.value = inspectionChamberList.value[0].value
			}else {
				inspectionChamberList.value = []
				inspectionChamber.value = null;
			}
		
		});
	}
</script>

<style lang="scss">
	.dialog-body {
		.list-container {
			width: 100%;

			.list-title {
				margin-top: 24rpx;

				.label {
					font-size: 32rpx;
				}
			}

			.turnArea {
				flex-wrap: wrap;
				height: auto;
				max-height: 200rpx;
				overflow: auto;
			}

			.btn {
				margin-top: 24rpx;

				.middle-btn {
					margin-right: 32rpx;
					align-items: center;
					justify-content: center;
					padding-left: 0;
					height: 80rpx;
					width: 220rpx;
					border-radius: 8rpx;
					background-color: #FFFFFF;
					border: 1px solid #999999;
					background-color: #FFFFFF;

				}

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

				.active {
					border-color: #1684fc;
					background-color: rgb(236, 245, 255);

					.label {
						color: #1684fc;
					}
				}
			}
		}

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

			.btn {
				flex: 1;
				background-color: #1684fc;
				color: #FFFFFF;

			}
		}
	}
</style>