<template>
	<view class="page-container uni-column">
		<view class="option-container uni-column">
			<!-- 搜索框 -->
			<view class="search-container uni-row">
				<input type="text" v-model="standard" placeholder="请输入检查标准" />
				<view class="btn" @click="handleSelect">搜索</view>
			</view>
			<!-- 选项 -->
			<view class="option-item" v-for="(item, index) in optionList" :key="index" @click="handleOptionChecked(item)">
				<view class="uni-row">
					<view class="label">检查标准</view>
					<view class="value">{{ item.standard }}</view>
				</view>
				<uni-icons class="arrow-right" type="right" size="24" />
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { onLoad, onReady, onUnload, onShow } from '@dcloudio/uni-app'
	import {
		getInspectionStandardsList
	} from '@/api/business/inspectionStandards.js'
	const standard = ref('')
	const optionList = ref([])
	const productId = ref(null)
	const processId = ref(null)
	
	// 页面生命周期函数
	onLoad((options) => {
		productId.value = options.param1
		processId.value = options.param2
		init();
		
	})
	function init() {
		//查询该产品，当前工序，当前检查绑定的检查
			getInspectionStandardsList({
				productId:productId.value,
				processId:processId.value,
				inspectionCode:"firstArticleInspection"
				}).then(res =>{
					optionList.value = res.rows
		})
	}
	function handleSelect() {
		getInspectionStandardsList({
				productId:productId.value,
				processId:processId.value,
				inspectionCode:"firstArticleInspection",
				standard:standard.value
				}).then(res =>{
					if(res.rows &&res.rows.length>0){
					optionList.value = res.rows
					  }
					  else{
						  optionList.value = []
					  }
		})
	}
	
	
	const handleOptionChecked = (data) => {
		console.log(data)
		uni.$emit('addWasteInfoEvent', {
			id: data.id,
			standard: data.standard
		})
		uni.navigateBack()
	}
</script>

<style lang="scss">
	.page-container {
		height: 100%;
		background-color: #ececec;
		font-size: 28rpx;
		padding: 24rpx;
		box-sizing: border-box;
	}
	.option-container {
		background-color: #ffffff;
		padding: 24rpx;
		border-radius: 12rpx;
	}
	.tab-bars {
		height: 56rpx;
		
		> view {
			flex: 1;
			text-align: center;
			
			.line {
				width: 50%;
				height: 2px;
				margin:8rpx auto 0 auto;
				background-color: #FFFFFF;
			}
			&.active {
				.line {
					background-color: #1684FC;
				}
			}
		}
	}
	.search-container {
		margin-top: 16rpx;
		align-items: center;
		
		input {
			flex: 1;
			height: 72rpx;
			border: 1px solid #bbbbbb;
			padding: 0 8rpx;
			box-sizing: border-box;
		}
		.btn {
			display: flex;
			flex-direction: row;
			width: 112rpx;
			height: 72rpx;
			align-items: center;
			justify-content: center;
			background-color: #1684FC;
			color: #ffffff;
		}
	}
	.option-item {
		position: relative;
		margin-top: 24rpx;
		padding-bottom: 8rpx;
		border-bottom: 1px solid #BBBBBB;
		
		.uni-row {
			padding-bottom: 16rpx;
			
			.label {
				width: 144rpx;
			}
			.value {
				flex: 1;
			}
		}
		.uni-row:first-child {
			font-size: 32rpx;
			font-weight: 700;
		}
		
		.arrow-right {
			position: absolute;
			right: 24rpx;
		}
	}
</style>