<template>
	<view>
		<uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar left-icon="left" left-text="返回"
			title="差压式流量计算" @clickLeft="back" />
		<uni-card>
		
			<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="0" 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-meterResult :formData="meterResult"></yjly-ngtools-meterResult>
			</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['仪表参数', '组分参数', '计算结果'],
				current: 0,
				strNG: "",
				meterPar: [],
				
		</view>meterResult: {
					"dCd": "",
					"dCdCalMethod": "",
					"dMeterFactor": "",
					"dPulseNum": "",
					"dVFlowMax": "",
					"dVFlowMin": "",
					"dVFlowCon": "",
					"dPfRangeMin": "",
					"dPfRangeMax": "",
					"dDpRangeMin": "",
					"dDpRangeMax": "",
					"dTfRangeMin": "",
					"dTfRangeMax": "",
					"dE": "",
					"dFG": "",
					"dFT": "",
					"dDViscosity": "",
					"dDExpCoefficient": "",
					"dRnPipe": "",
					"dBk": "",
					"dRoughNessPipe": "",
					"dCdCorrect": "",
					"dCdNozell": "",
					"dVFlowb": "",
					"dVFlowf": "",
					"dMFlowb": "",
					"dEFlowb": "",
					"dVelocityFlow": "",
					"dPressLost": "",
					"dBeta": "",
					"dKappa": "",

				},
				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.dCd = "0";
				this.meterResult.dCdCalMethod = "0";
				this.meterResult.dMeterFactor = "0";
				this.meterResult.dPulseNum = "0";
				this.meterResult.dVFlowMax = "0";
				this.meterResult.dVFlowMin = "0";
				this.meterResult.dVFlowCon = "0";
				this.meterResult.dPfRangeMin = "0";
				this.meterResult.dPfRangeMax = "0";
				this.meterResult.dDpRangeMin = "0";
				this.meterResult.dDpRangeMax = "0";
				this.meterResult.dTfRangeMin = "0";
				this.meterResult.dTfRangeMax = "0";
				this.meterResult.dE = "0";
				this.meterResult.dFG = "0";
				this.meterResult.dFT = "0";
				this.meterResult.dDViscosity = "0";
				this.meterResult.dDExpCoefficient = "0";
				this.meterResult.dRnPipe = "0";
				this.meterResult.dBk = "0";
				this.meterResult.dRoughNessPipe = "0";
				this.meterResult.dCdCorrect = "0";
				this.meterResult.dCdNozell = "0";
				this.meterResult.dVFlowb = "0";
				this.meterResult.dVFlowf = "0";
				this.meterResult.dMFlowb = "0";
				this.meterResult.dEFlowb = "0";
				this.meterResult.dVelocityFlow = "0";
				this.meterResult.dPressLost = "0";
				this.meterResult.dBeta = "0";
				this.meterResult.dKappa = "0";
				this.meterResult.dZb = "0";
				this.meterResult.dZf = "0";
				this.meterResult.dFpv = "0";
			},


			onClickItem(e) {
				this.ssss="";
				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 = this.meterPar.dMeterType; //流量计类别
				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 MP-WEIXIN
				 url="https://ngtools.cn:8443"; 
				 // #endif				
				// #ifdef H5
				url = "/api"
				// #endif
				console.log(url)
			 
				uni.request({
					url: url + "/KBFlowcal",
					type: 'GET',
					datatype: 'json',
					data: {
						"par": NG_par
					},
					sslVerify: false,
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					timeout: 1000, //10秒超时
					success: function(res) {						 
						console.log(res)	 			
						var data = JSON.stringify(res.data.message).toString().replace('[', '').replace(']','').split(',');
						that.meterResult.dCd = data[45].substring(0, data[45].indexOf(".") + 6);
						that.meterResult.dE = data[46].substring(0, data[46].indexOf(".") + 6);
						that.meterResult.dFG = data[47].substring(0, data[47].indexOf(".") + 6);
						that.meterResult.dFT = data[48].substring(0, data[48].indexOf(".") + 6);
						that.meterResult.dDViscosity = data[49].substring(0, data[49].indexOf(".") + 6);
						that.meterResult.dDExpCoefficient = data[50].substring(0, data[50].indexOf(".") + 6);
						that.meterResult.dRnPipe = data[51].substring(0, data[51].indexOf(".") + 2);
						that.meterResult.dBk = data[52].substring(0, data[52].indexOf(".") + 5);
						that.meterResult.dRoughNessPipe = data[53].substring(0, data[53].indexOf(".") + 5);
						that.meterResult.dVFlowb = data[56].substring(0, data[56].indexOf(".") + 5);
						that.meterResult.dVFlowf = data[57].substring(0, data[57].indexOf(".") + 5);
						that.meterResult.dMFlowb = data[58].substring(0, data[58].indexOf(".") + 5);
						that.meterResult.dEFlowb = data[59].substring(0, data[59].indexOf(".") + 5);
						that.meterResult.dVelocityFlow = data[60].substring(0, data[60].indexOf(".") + 5);
						that.meterResult.dPressLost = data[61].substring(0, data[61].indexOf(".") + 5);
						that.meterResult.dBeta = data[62].substring(0, data[62].indexOf(".") + 5);
						that.meterResult.dZb = data[64].substring(0, data[64].indexOf(".") + 6);
						that.meterResult.dZf = data[65].substring(0, data[65].indexOf(".") + 6);
						that.meterResult.dFpv = data[66].substring(0, data[66].indexOf(".") + 6);
						that.meterResult.dKappa = data[80].substring(0, data[80].indexOf(".") + 6);
						that.current = 2;
						console.log(that.meterResult)
					},
					fail: function(res) {						 
						console.log(res)
					}
				})




			},
			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>