<template>
	<view class="container">
		<!-- 输入框区域 -->
		<view class="search">
			<img src="../../static/images/repairsImg/search.png" />

			<input type="text" placeholder="请输入搜索内容" v-model="searchValue" />
		</view>

		<!-- 耗材区域 -->
		<view class="body">
			<view class="body_left">
				<view class="left_item" :class="{ active: activeIndex === index }" v-for="(item, index) in list" :key="index" @click="handleChange(index)">{{ item }}</view>
			</view>
			<view class="body_right">
				<view class="right_item" :class="{ active: activeIndex2 === index2 }" v-for="(ele, index2) in List2" :key="index2" @click="handleChange2(index2)">{{ ele }}</view>
			</view>
		</view>

		<!-- 备注区域 -->
		<view class="notes" v-if="list[activeIndex] === '其他'">
			<view class="notes_title">备注</view>
			<view class="notes_textarea">
				<textarea placeholder-style="color:#CCCCCC" placeholder="请输入您的备注" maxlength="150" v-model="textareaValue" @input="handleInput"></textarea>

				<view class="notes_num">{{ textLength }}/150</view>
			</view>
		</view>

		<view class="btn" v-if="list[activeIndex] === '其他'" @click="handleAffirm">确认</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 搜索框绑定数据
			searchValue: '',
			// 备注输入框绑定数据
			textareaValue: '',
			// 输入框当前输入数据的长度
			textLength: 0,
			// 左边数组的索引
			activeIndex: 0,
			// 左边数组
			list: ['水电', '木工类', '行政楼', '泥工类', '其他'],
			// 右边数组的索引
			activeIndex2: 0,
			// 右边数组
			List2: ['下水道', '安全指示牌', '消费应急灯', '排水管道', '吊顶', '风扇', '没电']
		}
	},
	methods: {
		// 确认按钮回调
		handleAffirm() {
			if (this.textareaValue) {
				this.List2.push(this.textareaValue)
				this.textareaValue = ''
			} else {
				uni.showToast({
					title: '请输入备注',
					icon: 'none'
				})
			}
		},
		// 左边数组切换回调
		handleChange(index) {
			this.activeIndex = index
		},
		// 右边数组切换回调
		handleChange2(index) {
			this.activeIndex2 = index
			uni.$emit('addConsumable', {
				data: this.List2[this.activeIndex2]
			})
			uni.navigateBack(1)
		},
		// 输入框输入值变化回调
		handleInput(e) {
			// console.log(e.detail.value.length)
			this.textLength = e.detail.value.length
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	width: 100vw;
	height: 100vh;
	overflow-y: auto;

	.search {
		display: flex;
		align-items: center;
		margin: 30rpx auto 30rpx;
		width: 690rpx;
		height: 80rpx;
		border-radius: 4rpx;
		background-color: #f2f2f2;

		img {
			margin: 0 20rpx;
			width: 40rpx;
			height: 40rpx;
		}

		input {
			flex: 1;
			padding: 10rpx;
		}
	}

	.body {
		display: flex;
		height: 686rpx;
		border-top: 1rpx solid #e5e5e5;

		.body_left {
			box-sizing: border-box;
			padding: 30rpx;
			width: 199rpx;
			border-right: 1rpx solid #cccccc;
			overflow-y: auto;

			.left_item {
				height: 80rpx;
				font-size: 28rpx;
				font-weight: bold;
			}

			.active {
				color: #6fb6b8;
			}
		}

		.body_right {
			flex: 1;
			box-sizing: border-box;
			padding: 35rpx 30rpx;
			overflow-y: auto;

			.right_item {
				float: left;
				box-sizing: border-box;
				padding: 10rpx 30rpx;
				margin: 0 20rpx 37rpx 0;
				height: 50rpx;
				line-height: 30rpx;
				text-align: center;
				color: #808080;
				font-size: 28rpx;
				border-radius: 53rpx;
				background-color: #e6e6e6;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			.active {
				color: #fff;
				background-color: #6fb6b8;
			}
		}
	}

	.notes {
		box-sizing: border-box;
		padding: 0 30rpx;
		border-top: 1rpx solid #e5e5e5;

		.notes_title {
			display: flex;
			align-items: center;
			height: 88rpx;
			font-size: 32rpx;
			font-weight: bold;
		}

		.notes_textarea {
			position: relative;
			height: 284rpx;
			border: 1rpx solid #e5e5e5;

			textarea {
				box-sizing: border-box;
				padding: 16rpx 20rpx 75rpx;
				width: 100%;
				font-size: 32rpx;
			}

			.notes_num {
				position: absolute;
				right: 20rpx;
				bottom: 14rpx;
				color: #a6a6a6;
				font-size: 32rpx;
			}
		}
	}

	.btn {
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 55rpx auto 65rpx;
		width: 690rpx;
		height: 100rpx;
		color: #fff;
		font-size: 32rpx;
		border-radius: 12rpx;
		background-color: #6fb6b8;
	}
}
</style>
