<template>
	<view class="result-container">
		<scroll-view scroll-y :style="{ height: scrollViewHeight + 'px' }" class="scroll-area">
			<!-- GB/T 17747 计算结果 -->
			<view v-if="dMeterType === '4'" class="result-section">
				<view class="section-title">GB/T 17747</view>
				<u-divider></u-divider>
				<view class="form-grid">
					<view class="form-item">
						<view class="form-label">分子量/摩尔质量kg/mol</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dMrx" placeholder="分子量" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">标况压缩因子</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dZb" placeholder="标况压缩因子" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">工况压缩因子</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dZf" placeholder="工况压缩因子" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">超压缩系数</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dFpv" placeholder="超压缩系数" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">标况摩尔密度mol/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dDb" placeholder="标况摩尔密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">工况摩尔密度mol/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dDf" placeholder="工况摩尔密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">标况质量密度kg/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRhob" placeholder="标况质量密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">工况质量密度kg/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRhof" placeholder="工况质量密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">理想气体的相对密度</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRD_Ideal" placeholder="理想气体的相对密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">真实气体的相对密度</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRD_Real" placeholder="真实气体的相对密度" />
						</view>
					</view>
				</view>
			</view>

			<!-- AGA No10 计算结果 -->
			<view v-if="dMeterType === '5'" class="result-section">
				<view class="section-title">AGA No10</view>
				<u-divider></u-divider>
				<view class="form-grid">
					<view class="form-item">
						<view class="form-label">理想气体的比焓</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dHo" placeholder="理想气体的比焓" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">真实气体的焓kJ/kg</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dH" placeholder="真实气体的焓" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">真实气体的熵kJ/kg.K</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dS" placeholder="真实气体的熵" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">理想气体定压热容 J/(kg·K)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dCpi" placeholder="理想气体定压热容" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">定压热容J/(kg·K)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dCp" placeholder="定压热容" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">定容积热容 J/(kg·K)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dCv" placeholder="定容积热容" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">比热比</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dk" placeholder="比热比" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">等熵指数</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dKappa" placeholder="等熵指数" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">声速m/s</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dSOS" placeholder="声速" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">临界流函数</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dCstar" placeholder="临界流函数" />
						</view>
					</view>
				</view>
			</view>

			<!-- GB/T 11062 计算结果 -->
			<view v-if="dMeterType === '6'" class="result-section">
				<view class="section-title">GB/T 11062</view>
				<u-divider></u-divider>
				<view class="form-grid">
					<view class="form-item">
						<view class="form-label">摩尔高位发热量MJ/mol</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dHhvMol" placeholder="摩尔高位发热量" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">摩尔低位发热量MJ/mol</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dLhvMol" placeholder="摩尔低位发热量" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">体积高位发热量MJ/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dHhvv" placeholder="体积高位发热量" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">体积低位发热量MJ/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dLhvv" placeholder="体积低位发热量" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">质量高位发热量MJ/t</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dHhvm" placeholder="质量高位发热量" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">质量地位发热量MJ/t</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dLhvm" placeholder="质量地位发热量" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">标况压缩因子</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dZb11062" placeholder="标况压缩因子" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">标况质量密度kg/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRhob11062" placeholder="标况质量密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">工况质量密度kg/m³</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRhof11062" placeholder="工况质量密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">理想气体的相对密度</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRD_Ideal11062" placeholder="理想气体的相对密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">真实气体的相对密度</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dRD_Real11062" placeholder="真实气体的相对密度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">真实气体的沃泊指数</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dWobbeIndex" placeholder="真实气体的沃泊指数" />
						</view>
					</view>
				</view>
			</view>

			<!-- 其他计算结果 -->
			<view v-if="dMeterType === '7'" class="result-section">
				<view class="section-title">其他</view>
				<view class="form-grid">
					<view class="form-item">
						<view class="form-label">临界压力</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dPc" placeholder="临界压力" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">临界温度</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dTC" placeholder="临界温度" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">爆炸上限</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dBzsx" placeholder="爆炸上限" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">爆炸下限</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dBzxx" placeholder="爆炸下限" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">总炭含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dTotalC" placeholder="总炭含量(kg/m3)" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">C2组分含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dC2" placeholder="C2组分含量(kg/m3)" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">C2以上组分含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dC2j" placeholder="C2以上组分含量(kg/m3)" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">C3以上组分含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dC3j" placeholder="C3以上组分含量(kg/m3)" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">C4以上组分含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dC4j" placeholder="C4以上组分含量(kg/m3)" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">C5以上组分含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dC5j" placeholder="C5以上组分含量(kg/m3)" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">C6以上组分含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dC6j" placeholder="C6以上组分含量(kg/m3)" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">C3C4组分含量(kg/m3)</view>
						<view class="form-control">
							<uni-easyinput class="input-result-class" disabled :clearable="false" :value="NGResult.dC3C4" placeholder="C3C4组分含量(kg/m3)" />
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<style scoped>
.result-container {
	padding-left: 20rpx;
	padding-right: 20rpx;
	box-sizing: border-box;
	width: 100%;
}

.scroll-area {
	width: 100%;
}

.result-section {
	margin-bottom: 30rpx;
}

.section-title {
	font-size: 18px;
	font-weight: bold;
	color: #333;
	margin-top: 10rpx;
	padding: 0 5rpx;
}
.input-result-class
{
	 color: #000000 !important;
	  background-color: #ffffff !important;
}
/* 确保输入框内部的文字也是黑色 */
.input-result-class ::v-deep .uni-easyinput__content {
  color: #000000 !important;
  background-color: #ffffff !important;
}

.input-result-class ::v-deep .uni-input-input {
  color: #000000 !important;
  background-color: #ffffff !important;
  -webkit-text-fill-color: #000000 !important;
  opacity: 1 !important;
}

.form-grid {
	display: grid;
	gap: 20rpx;
	padding: 20rpx;
	box-sizing: border-box;
}

.form-item {
	width: 100%;
	display: flex;
	flex-direction: column;
}

.form-label {
	font-size: 12px;
	color: #606266;
	margin-bottom: 8rpx;
	font-weight: 300;
	line-height: 1.4;
}

.form-control {
	width: 100%;
}



/* 移动端：2列 */
@media screen and (max-width: 768px) {
	.form-grid {
		grid-template-columns: repeat(2, 1fr);
	}
}

/* 桌面：3列 */
@media screen and (min-width: 1200px) {
	.form-grid {
		grid-template-columns: repeat(3, 1fr);
	}
}
</style>

<script setup>
	import {
		ref,
		watch,
		onMounted,
		nextTick
	} from 'vue';
	//  

	// 定义 props
	const props = defineProps({
		elFormWidth: {
			type: Number,
			default: 180
		},
		otherComHeight: {
			type: Number,
			default: 120
		},
		dMeterType: {
			type: String,
			default: '0'
		},
		modelValue: {
			type: Object,
			default: () => ({
				dMrx: 0,
				dZb: 0,
				dZf: 0,
				dFpv: 0,
				dDb: 0,
				dDf: 0,
				dRhob: 0,
				dRhof: 0,
				dRD_Ideal: 0,
				dRD_Real: 0,
				dHo: 0,
				dH: 0,
				dS: 0,
				dCpi: 0,
				dCp: 0,
				dCv: 0,
				dk: 0,
				dKappa: 0,
				dSOS: 0,
				dCstar: 0,
				dHhvMol: 0,
				dLhvMol: 0,
				dHhvv: 0,
				dLhvv: 0,
				dHhvm: 0,
				dLhvm: 0,
				dZb11062: 0,
				dRhob11062: 0,
				dRhof11062: 0,
				dRD_Ideal11062: 0,
				dRD_Real11062: 0,
				dWobbeIndex: 0,
				dPc: 0,
				dTC: 0,
				dBzsx: 0,
				dBzxx: 0,
				dTotalC: 0,
				dC2: 0,
				dC2j: 0,
				dC3j: 0,
				dC4j: 0,
				dC5j: 0,
				dC6j: 0,
				dC3C4: 0
			})
		}
	});

	// 定义响应式数据
	const NGResult = ref({
		dMrx: 0,
		dZb: 0,
		dZf: 0,
		dFpv: 0,
		dDb: 0,
		dDf: 0,
		dRhob: 0,
		dRhof: 0,
		dRD_Ideal: 0,
		dRD_Real: 0,
		dHo: 0,
		dH: 0,
		dS: 0,
		dCpi: 0,
		dCp: 0,
		dCv: 0,
		dk: 0,
		dKappa: 0,
		dSOS: 0,
		dSOSUnit: 0,
		dCstar: 0,
		dHhvMol: 0,
		dLhvMol: 0,
		dHhvv: 0,
		dLhvv: 0,
		dHhvm: 0,
		dLhvm: 0,
		dZb11062: 0,
		dRhob11062: 0,
		dRhof11062: 0,
		dRD_Ideal11062: 0,
		dRD_Real11062: 0,
		dWobbeIndex: 0,
		dPc: 0,
		dTC: 0,
		dBzsx: 0,
		dBzxx: 0,
		dTotalC: 0,
		dC2: 0,
		dC2j: 0,
		dC3j: 0,
		dC4j: 0,
		dC5j: 0,
		dC6j: 0,
		dC3C4: 0
	});
	const selectWidth = ref(180);
	const queryRef = ref(null);

	watch(
		() => props.otherComHeight,
		(newVal) => {
			calculateScrollViewHeight(newVal)
		})
	// 定义响应式数据
	const scrollViewHeight = ref(0);

	// 获取屏幕高度并计算scroll-view高度
	const calculateScrollViewHeight = (h) => {
		try {
			let systemInfo = {};
			
			// #ifdef MP-WEIXIN
			// 微信小程序平台
			try {
			  // 获取窗口信息
			  const windowInfo = wx.getWindowInfo();
			  // 获取设备信息
			  const deviceInfo = wx.getDeviceInfo();
			  
			  // 将两个新API获取到的信息合并成一个对象，方便使用
			  systemInfo = {
			    ...windowInfo,
			    ...deviceInfo
			  };
			  
			  // 注意：如果你还需要获取系统设置或授权信息，可以按需添加
			  // const systemSetting = wx.getSystemSetting();
			  // const appAuthorizeSetting = wx.getAppAuthorizeSetting();
			  // systemInfo = { ...systemInfo, ...systemSetting, ...appAuthorizeSetting };
			  
			} catch (e) {
			  console.error("获取微信小程序系统信息失败:", e);
			}
			// #endif
			
			// #ifdef H5 || APP-PLUS
			// H5 或 App 平台
			try {
			  systemInfo = uni.getSystemInfoSync();
			} catch (e) {
			  console.error("获取系统信息失败:", e);
			}
			// #endif
			const screenHeight = systemInfo.windowHeight;
			// 计算scroll-view高度
			scrollViewHeight.value = screenHeight - h - 20;
		} catch (error) {
			console.error('获取系统信息失败:', error);
			// 设置默认高度
			scrollViewHeight.value = 400;
		}
	};


	// 监听 elFormWidth 的变化
	watch(
		() => props.elFormWidth,
		(newVal) => {
			selectWidth.value = newVal;
		}, {
			deep: true
		}
	);

	// 监听 value 的变化
	watch(
		() => props.modelValue,
		(newVal) => {
			console.log('NGResult数据更新:', newVal);
			const processedValue = {
				...newVal
			};
			for (const key in processedValue) {
				if (processedValue.hasOwnProperty(key)) {
					const value = processedValue[key];
					// 判断是否为有效的数值
					if (typeof value === 'number' && !isNaN(value) && isFinite(value)) {
						// 使用 toFixed 方法设置小数点位数
						processedValue[key] = parseFloat(value.toFixed(6));
					}
				}
			}
			NGResult.value = JSON.parse(JSON.stringify(processedValue));
		}, {
			deep: true,
			immediate: true
		}
	);

	// 挂载后设置 selectWidth
	onMounted(() => {
		selectWidth.value = props.elFormWidth;
		nextTick(() => {
			calculateScrollViewHeight()
		})
	});
</script>

 