<template>
	<view class="page-container uni-column">
		<view class="consultation-container uni-column">
			<view class="title uni-row">咨询</view>
			<view class="info-row uni-row">
				<view class="label">批次号</view>
				<view class="value">{{ dayworkItem.lotCode }}</view>
			</view>
			<view class="info-row uni-row">
				<view class="label">产品描述</view>
				<view class="value">{{ dayworkItem.productDescription }}</view>
			</view>
			<view class="info-row uni-row">
				<view class="label">技术负责人</view>
				<view class="value">{{ dayworkItem.technicianName }}</view>
			</view>
			<view class="info-row uni-column">
				<view class="label" style="margin-bottom: 16rpx;">问题描述</view>
				<view class="value uni-row">
					<textarea v-model="data.content"></textarea>
				</view>
			</view>
			<view class="btn uni-row" @click.stop="handleSubmit">提交</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad,
		onReady,
		onUnload,
		onShow
	} from '@dcloudio/uni-app'

	import {
		onMounted,
		getCurrentInstance
	} from 'vue';
	const dayworkItem = ref({})
	const data = ref({
		content: ''
	})

	// 创建一个引用来存储最后一次请求的时间戳
	const lastRequestTimestamp = ref(0);

	onMounted(() => {
		const instance = getCurrentInstance().proxy
		const eventChannel = instance.getOpenerEventChannel();

		eventChannel.on('acceptDataFromOpenerPage', function(data) {
			console.log('acceptDataFromOpenerPage', data)
			// 传入当前报工信息 通过当前报工的产品和工序获取检查指导书和分选标准
			if (data && data.data) {
				dayworkItem.value = data.data
			}
		})
	})


	// 页面生命周期函数
	onLoad(() => {

	})

	const handleSubmit = () => {
		if (data.value.content == null || data.value.content == '') {
			uni.showToast({
				icon: 'none',
				title: '请输入问题描述'
			})
			return
		}
		const currentTime = Date.now();
		console.log("检查", lastRequestTimestamp);
		// 检查是否已经过去了 2 秒
		if (currentTime - lastRequestTimestamp.value < 2000) {
			// 如果在 2 秒 内已经点击，那么不执行
			uni.showToast({
				icon: 'none',
				title: `请勿重复点击`,
				duration: 2000
			})
			return;
		}
		uni.$emit('addConsulttationEvent', {
			content: data.value.content
		})
		uni.navigateBack()
	}
</script>

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

	.consultation-container {
		background-color: #ffffff;
		padding: 24rpx;
		border-radius: 12rpx;

		.title {
			justify-content: center;
			font-size: 32rpx;
			font-weight: 700;
		}

		.info-row {
			margin-top: 24rpx;

			.label {
				width: 160rpx;
			}

			.value {
				flex: 1;

				textarea {
					flex: 1;
					border: 1px solid #888888;
					box-sizing: border-box;
					padding: 16rpx;
				}
			}
		}

		.btn {
			background-color: #00D068;
			color: #ffffff;
			border-radius: 8rpx;
			margin: 24rpx;
			height: 64rpx;
			justify-content: center;
			align-items: center;
		}
	}
</style>