<template>
	<view class="page-container uni-column" style="position: absolute;left: 0;right: 0;top: 0;bottom: 0">
		<view class="option-container uni-column" style="display: flex;">
			<!-- tab-bar -->
			<view class="tab-bars uni-row">
				<view >
					<text style="font-weight: bold;">技术负责人</text>
					<view class="line"></view>
				</view>
			</view>
			<!-- 搜索框 -->
			<view class="search-container uni-row">
				<input type="text" v-model="keywords" placeholder="请输入关键字" />
				<view class="btn" @click="handleSearch()">搜索</view>
			</view>

		</view>
		<view  class="uni-row" style="background-color:#ffffff;height: 85%;padding-bottom: 12px;">
			<view style="width: 100%;height: 100%;overflow: auto;">
				<view v-if="optionList&& optionList.length == 0" style="align-items: center;margin-top: 30px">暂无技术员</view>
			<!-- 选项 -->
			<view class="option-item" v-for="(item, index) in optionList" :key="index"
				@click="handleOptionChecked(item)">
				<view class="uni-row">
					<view class="value">{{ item.nickName }}</view>
				</view>
				<uni-icons class="arrow-right" type="right" size="24" />
			</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onMounted,
		getCurrentInstance
	} from 'vue';
	import {
		onLoad,
		onReady,
		onUnload,
		onShow
	} from '@dcloudio/uni-app'
	import {
		getTechnicianList
	} from '@/api/dept/dept.js'

	const currentTabName = ref(1)
	const keywords = ref('')
	const optionList = ref([])
	onMounted(() => {
		loadTechnicianList()
	})

	function handleSearch() {
		uni.showLoading({
			title: '加载中'
		});
		getTechnicianList({nickName:keywords.value}).then(res => {
			console.log(res)
			if (res.code === 200) {
				optionList.value = res.data
				uni.hideLoading();
			} else {
				uni.showToast({
					icon: 'none',
					title: '技术部无人员'
				})
				uni.hideLoading();
			}
		})

	}

	const loadTechnicianList = () => {
		uni.showLoading({
			title: '加载中'
		});
		getTechnicianList().then(res => {
			console.log(res)
			if (res.code === 200) {
				optionList.value = res.data
				uni.hideLoading();
			} else {
				uni.showToast({
					icon: 'none',
					title: '技术部无人员'
				})
				uni.hideLoading();
			}
		})
	}

	const handleOptionChecked = (data) => {
		uni.$emit('addTechnicianEvent', {
			technicianId:data.userId,
			technicianName:data.nickName
		})
		uni.navigateBack()
	}
</script>

<style lang="scss">
	.page-container {
		height: 100%;
		background-color: #ececec;
		font-size: 28rpx;
		padding: 24rpx;
		box-sizing: border-box;
	}

	.option-container {
		height: 10%;
		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;
		margin-left: 24rpx;
		
		.uni-row {
			padding-bottom: 16rpx;
			
			.label {
				width: 144rpx;
			}
			.value {
				flex: 1;
			}
		}
		.uni-row:first-child {
			font-size: 32rpx;
	
		}
		.arrow-right {
			position: absolute;
			right: 24rpx;
		}
	}
</style>