<template>
	<view>
		<uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar left-icon="left" left-text="返回"
			title="密度热值计算 (GB/T11062)" @clickLeft="back" />
		<uni-card>

			<!-- <view class="uni-button-group">
				<uni-row width="100%">
					<uni-col :span="12"><button class="mini-btn" type="primary" size="mini" @click="cal">计算</button>
					</uni-col>
					<uni-col :span="12"><button class="mini-btn" type="primary" size="mini" @click="save">打印结果</button>
					</uni-col>
				</uni-row>
			</view> -->
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="button"
				activeColor="#4cd964"></uni-segmented-control>
		</uni-card>
		<view class="content">
			<view v-show="current === 0">
				<yjly-ngtools-meterPar :meter-type="4" v-model="meterPar" @calEnable="meterEnable">
				</yjly-ngtools-meterPar>
			</view>
			<view v-show="current === 1">
				<yjly-ngtools-NGComponents @calEnable="NGEnable" v-model="strNG">
				</yjly-ngtools-NGComponents>
			</view>
			<view v-show="current === 2">
				<yjly-ngtools-ParResult :formData="meterResult" :meter-type="4">
				</yjly-ngtools-ParResult>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['工艺参数', '组分参数', '计算结果'],
				current: 0,
				strNG: "",
				meterPar: [],
				meterResult: {
					"adMixture": "",
					"adMixtureV": "",
					"adMixtureD": "",
					"dCbtj": "",
					"dPb": "",
					"dTb": "",
					"dPf": "",
					"dTf": "",
					"dMrx": "",
					"dZb": "",
					"dZf": "",
					"dFpv": "",
					"dDb": "",
					"dDf": "",
					"dRhob": "",
					"dRhof": "",
					"dRD_Ideal": "",
					"dRD_Real": "",
					"dHo": "",
					"dH": "",
					"dS": "",
					"dCpi": "",
					"dCp": "",
					"dCv": "",
					"dk": "",
					"dKappa": "",
					"dSOS": "",
					"dCstar": "",
					"dHhvMol": "",
					"dLhvMol": "",
					"dHhvv": "",
					"dLhvv": "",
					"dHhvm": "",
					"dLhvm": "",
					"dZb11062": "",
					"dRhob11062": "",
					"dRhof11062": "",
					"dRD_Ideal11062": "",
					"dRD_Real11062": "",
					"dWobbeIndex": "",
					"Pc": "",
					"TC": "",
					"Bzsx": "",
					"Bzxx": "",
					"TotalC": "",
					"C2": "",
					"C2j": "",
					"C3j": "",
					"C4j": "",
					"C5j": "",
					"C6j": "",
					"C3C4": ""
				},
				NGFlag: false,
				meterFlag: false
			};
		},
		watch: {
			strNG: {
				immediate: true,
				deep: true,
				handler(val) {
					this.zeroPar();
				}
			},
			meterPar: {
				immediate: true,
				deep: true,
				handler(val) {
					this.zeroPar();
				}
			},
		},

		methods: {
			NGEnable(e) {
				console.log(e)
				this.NGFlag = e
			},
			meterEnable(e) {
				console.log(e)
				this.meterFlag = e
			},
			zeroPar() {
				this.meterResult.adMixture = "0";
				this.meterResult.adMixtureV = "0";
				this.meterResult.adMixtureD = "0";
				this.meterResult.dCbtj = "0";
				this.meterResult.dPb = "0";
				this.meterResult.dTb = "0";
				this.meterResult.dPf = "0";
				this.meterResult.dTf = "0";
				this.meterResult.dMrx = "0";
				this.meterResult.dZb = "0";
				this.meterResult.dZf = "0";
				this.meterResult.dFpv = "0";
				this.meterResult.dDb = "0";
				this.meterResult.dDf = "0";
				this.meterResult.dRhob = "0";
				this.meterResult.dRhof = "0";
				this.meterResult.dRD_Ideal = "0";
				this.meterResult.dRD_Real = "0";
				this.meterResult.dHo = "0";
				this.meterResult.dH = "0";
				this.meterResult.dS = "0";
				this.meterResult.dCpi = "0";
				this.meterResult.dCp = "0";
				this.meterResult.dCv = "0";
				this.meterResult.dk = "0";
				this.meterResult.dKappa = "0";
				this.meterResult.dSOS = "0";
				this.meterResult.dCstar = "0";
				this.meterResult.dHhvMol = "0";
				this.meterResult.dLhvMol = "0";
				this.meterResult.dHhvv = "0";
				this.meterResult.dLhvv = "0";
				this.meterResult.dHhvm = "0";
				this.meterResult.dLhvm = "0";
				this.meterResult.dZb11062 = "0";
				this.meterResult.dRhob11062 = "0";
				this.meterResult.dRhof11062 = "0";
				this.meterResult.dRD_Ideal11062 = "0";
				this.meterResult.dRD_Real11062 = "0";
				this.meterResult.dWobbeIndex = "0";
				this.meterResult.Pc = "0";
				this.meterResult.TC = "0";
				this.meterResult.Bzsx = "0";
				this.meterResult.Bzxx = "0";
				this.meterResult.TotalC = "0";
				this.meterResult.C2 = "0";
				this.meterResult.C2j = "0";
				this.meterResult.C3j = "0";
				this.meterResult.C4j = "0";
				this.meterResult.C5j = "0";
				this.meterResult.C6j = "0";
				this.meterResult.C3C4 = "0"
			},

			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
					this.$nextTick(() => {
						if (this.current == 2) {
							this.cal();
						}
					}, 500)
				}
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			cal() {

				if (!this.NGFlag) {
					// uni.navigateTo({
					// 	url: '/pages/grid/popup?title="提示"&text="组分参数输入不完整，请检查并重新输入"'
					// })

					uni.showModal({
						title: '提示',
						content: '组分摩尔百分数合计不为100%，请检查并重新输入',
						icon: 'none',
						showCancel: false
					})
					this.current = 1;
					return
				}
				if (!this.meterFlag) {
					uni.showModal({
						title: '提示',
						content: '工艺参数输入不完整，请检查并重新输入',
						icon: 'none',
						showCancel: false
					})

					this.current = 0;
					return
				}

				var NG_par = ""
				NG_par = "0"; //流量计类别
				NG_par = NG_par + "," + this.meterPar.dCoreType; //节流装置类型
				NG_par = NG_par + "," + this.meterPar.dFlowCalbz; //流量计算标准
				NG_par = NG_par + "," + this.meterPar.dZcalbz; //压缩因子计算标准
				NG_par = NG_par + "," + this.meterPar.dCbtj; //'计量参比条件
				NG_par = NG_par + "," + this.meterPar.dPb_M; //计量参比条件压力
				NG_par = NG_par + "," + this.meterPar.dTb_M; //计量参比条件温度
				NG_par = NG_par + "," + this.meterPar.dPb_E; //燃烧参比条件压力
				NG_par = NG_par + "," + this.meterPar.dTb_E; //燃烧参比条件温度
				NG_par = NG_par + "," + this.meterPar.dPatm; //当地大气压
				NG_par = NG_par + "," + this.meterPar.dPatmUnit; //当地大气压单位
				NG_par = NG_par + "," + this.strNG; //天然气组分
				NG_par = NG_par + "," + this.meterPar.dPtmode; //取压方式
				NG_par = NG_par + "," + this.meterPar.dPipeType; //管道类型
				NG_par = NG_par + "," + this.meterPar.dPipeD; //管道内径
				NG_par = NG_par + "," + this.meterPar.dLenUnit; //长度单位
				NG_par = NG_par + "," + this.meterPar.dPipeDtemp; //管道内径参考温度
				NG_par = NG_par + "," + this.meterPar.dPileDtempU; //温度单位
				NG_par = NG_par + "," + this.meterPar.dPipeMaterial; //管道材料
				NG_par = NG_par + "," + this.meterPar.dOrificeD; //孔板孔径
				NG_par = NG_par + "," + this.meterPar.dOrificeUnit; //长度单位
				NG_par = NG_par + "," + this.meterPar.dOrificeDtemp; //孔板内径参考温度
				NG_par = NG_par + "," + this.meterPar.dOrificeDtempUnit; //温度单位
				NG_par = NG_par + "," + this.meterPar.dOrificeMaterial; //孔板材料
				NG_par = NG_par + "," + this.meterPar.dOrificeSharpness; //锐利度系数计算方法
				NG_par = NG_par + "," + this.meterPar.dOrificeRk; //孔板入口圆弧半径
				NG_par = NG_par + "," + this.meterPar.dOrificeRkLenU; //长度单位
				NG_par = NG_par + "," + this.meterPar.dPf; //输入压力
				NG_par = NG_par + "," + this.meterPar.dPfUnit; //压力单位
				NG_par = NG_par + "," + this.meterPar.dPfType; //压力类型
				NG_par = NG_par + "," + this.meterPar.dTf; //输入温度
				NG_par = NG_par + "," + this.meterPar.dTfUnit; //温度单位
				NG_par = NG_par + "," + this.meterPar.dDp; //输入差压
				NG_par = NG_par + "," + this.meterPar.dDpUnit; //压力单位
				NG_par = NG_par + "," + this.meterPar.dVFlowUnit; //体积流量单位
				NG_par = NG_par + "," + this.meterPar.dMFlowUnit; //质量流量单位
				NG_par = NG_par + "," + this.meterPar.dEFlowUnit; //能量流量单位

				console.log(NG_par);
				var that = this;
				var url = "";
				// #ifdef APP-PLUS
				url = "https://ngtools.cn:8443";
				// #endif	
				
				// #ifdef MP-WEIXIN
				 url="https://ngtools.cn:8443";
				 // #endif				
				// #ifdef H5
				url = "/api"
				// #endif
				console.log(url)
				uni.request({
					url: url + '/ParCal',
					type: 'GET',

					sslVerify: false,
					datatype: 'json',
					data: {
						"par": NG_par
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					timeout: 1000, //10秒超时
					success: function(res) {
						console.log(res.data)
						var data = JSON.stringify(res.data.message).toString().replace('[', '').replace(']',
							'').split(
							',');
						console.log(data)
						that.meterResult.dMrx = data[63].substring(0, data[63].indexOf(".") + 6);
						that.meterResult.dDb = data[67].substring(0, data[67].indexOf(".") + 6);
						that.meterResult.dDf = data[68].substring(0, data[68].indexOf(".") + 6);
						that.meterResult.dRhob = data[69].substring(0, data[69].indexOf(".") + 6);
						that.meterResult.dRhof = data[70].substring(0, data[70].indexOf(".") + 6);
						that.meterResult.dRD_Ideal = data[71].substring(0, data[71].indexOf(".") + 6);
						that.meterResult.dRD_Real = data[72].substring(0, data[72].indexOf(".") + 6);

						that.meterResult.dHhvMol = data[83].substring(0, data[83].indexOf(".") + 6);
						that.meterResult.dLhvMol = data[84].substring(0, data[84].indexOf(".") + 6);
						that.meterResult.dHhvv = data[85].substring(0, data[85].indexOf(".") + 6);
						that.meterResult.dLhvv = data[86].substring(0, data[86].indexOf(".") + 6);
						that.meterResult.dHhvm = data[87].substring(0, data[87].indexOf(".") + 6);
						that.meterResult.dLhvm = data[88].substring(0, data[88].indexOf(".") + 6);

						that.meterResult.dRhob11062 = data[90].substring(0, data[90].indexOf(".") + 6);
						that.meterResult.dRhof11062 = data[91].substring(0, data[91].indexOf(".") + 6);
						that.meterResult.dRD_Ideal11062 = data[92].substring(0, data[92].indexOf(".") + 6);
						that.meterResult.dRD_Real11062 = data[93].substring(0, data[93].indexOf(".") + 6);
						that.meterResult.dWobbeIndex = data[94].substring(0, data[94].indexOf(".") + 6);
						that.current = 2;
					},
				})



			},
			save() {

			}
		},
	}
</script>

<style>
	.uni-button-group {
		margin-top: 0px;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
	}

	.mini-btn {
		width: 100px;
		margin-right: 10px;
		margin-bottom: 10px;
	}
</style>