<template>
	<view class="zhiwei-list u-flex-col">
		<view class="zhiwei-search">
			<view class="search-box u-flex">
				<u-icon name="search" size="30"></u-icon>
				<input type="text" class="input" placeholder="选择职位名称查找职位类别" v-model="keyword1" confirm-type="search" @confirm="tosearch">
			</view>
		</view>
		<view class="u-flex-1 scroll-box u-flex">
			<scroll-view scroll-y="true" class="scroll-left">
				<view class="left-item u-flex u-row-between" :class="{leftactive:leftindex == index}" @click="changeleft(index)" v-for="(item,index) in leftlist" :key="index">
					<text></text>
					<text>{{item.name}}</text>
					<text></text>
				</view>
			</scroll-view>
			<scroll-view scroll-y="true" class="scroll-right">
				<view class="right-item" v-for="(item,index) in rightlist" :key="index">
					<view class="item-title">
						{{item.name}}
					</view>
					<view class="u-flex u-row-between u-flex-wrap right-list">
						<text class="right-text" @click="changeright(item,a)" v-for="(a,b) in item.childlist" :key="b">{{a.name}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {get_category_job} from "@/units/inquire.js"
	export default {
		data() {
			return {
				leftindex: 0,
				leftlist: [],
				rightlist: [],
				keyword1: '',
				keyword: ''
			}
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			changeright(item, a) {
				var arr = []
				arr.push({
					id: this.leftlist[this.leftindex].id,
					name: this.leftlist[this.leftindex].name
				})
				arr.push({
					id: item.id,
					name: item.name
				})
				arr.push({
					id: a.id,
					name: a.name
				})
				const eventChannel = this.getOpenerEventChannel();
				eventChannel.emit('changefenlei', arr);
				uni.navigateBack()
			},
			tosearch() {
				this.keyword = this.keyword1
				this.shaixuan()
			},
			shaixuan() {
				if (this.keyword) {
					var rightlist = JSON.parse(JSON.stringify(this.leftlist[this.leftindex].childlist))
					this.rightlist = []
					rightlist.forEach(item => {
						var arr = []
						item.childlist.forEach(val => {
							if (val.name.indexOf(this.keyword) > -1) {
								arr.push(val)
							}
						})
						item.childlist = arr
						if (arr.length > 0) {
							this.rightlist.push(item)
						}
					})
				} else {
					this.rightlist = this.leftlist[this.leftindex].childlist
				}
			},
			changeleft(index) {
				this.leftindex = index
				this.shaixuan()
			},
			getlist() {
				get_category_job().then(res => {
					this.leftlist = res.data
					this.rightlist = res.data[this.leftindex].childlist
				})
			}
		}
	}
</script>

<style lang="scss">
	.zhiwei-list {
		height: 100vh;

		.scroll-box {
			min-height: 1rpx;

			.scroll-right {
				flex: 1;
				min-width: 1rpx;
				height: 100%;
				padding: 0 32rpx 0 26rpx;

				.right-item {
					.right-list {
						.right-text {
							width: 212rpx;
							line-height: 72rpx;
							background: #F3F3F3;
							border-radius: 4rpx;
							text-align: center;
							font-size: 24rpx;
							font-family: SFPro-Regular, SFPro;
							font-weight: 400;
							color: #222222;
							margin-bottom: 20rpx;
						}

						.rightactive {
							background-color: rgba(12, 102, 194, 0.1);
							color: #0C66C2;
						}
					}

					.item-title {
						padding: 30rpx 0 24rpx;
						font-size: 36rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
			}

			.scroll-left {
				width: 240rpx;
				border-right: 2rpx solid #F0F0F0;
				height: 100%;

				.left-item {
					padding: 26rpx 0;

					text:first-child {
						width: 4rpx;
						height: 32rpx;
					}

					text:nth-child(2) {
						flex: 1;
						padding: 0 28rpx;
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}

					text:last-child {
						width: 4rpx;
						height: 32rpx;
					}
				}

				.leftactive {
					text:first-child {
						background-color: #0C66C2;
					}

					text:nth-child(2) {
						color: #0C66C2;
						font-weight: bold;
					}
				}
			}
		}

		.zhiwei-search {
			border-bottom: 2rpx solid #F0F0F0;
			padding: 20rpx 32rpx;

			.search-box {
				height: 76rpx;
				background: #F3F3F3;
				border-radius: 16rpx;
				padding: 0 24rpx;

				.input {
					flex: 1;
					font-size: 30rpx;
					margin-left: 10rpx;
				}
			}
		}
	}
</style>