<template>
	<view>
		<uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar left-icon="left" left-text="返回"
			title="临界流流量计算" @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="2" 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 :meter-type="2" :formData="meterResult"></yjly-ngtools-meterResult>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['仪表参数', '组分参数', '计算结果'],
				current: 0,
				strNG: "",
				meterPar: [],
				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": "",
					"updateTime": null,
					"createTime": null
				},
				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.dCstar = "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 = 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.dPulseNum; //输入脉冲数
				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; //能量流量单位
				NG_par = NG_par + "," + this.meterPar.dCd; //仪表系数

				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 + '/PZFlowcal',
					type: 'GET',
					datatype: 'json',
					sslVerify: false,
					data: {
						"par": NG_par
					},
					timeout: 10000, //10秒超时
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: function(res) {
						console.log(res)
						var data = JSON.stringify(res.data.message).toString().replace('[', '').replace(']',
							'').split(
							',');

						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.dZb = data[64].substring(0, data[64].indexOf(".") + 6);
						that.meterResult.dZf = data[65].substring(0, data[65].indexOf(".") + 6);
						that.meterResult.dKappa = data[80].substring(0, data[80].indexOf(".") + 6);
						that.meterResult.dCstar = data[82].substring(0, data[82].indexOf(".") + 6);

						that.current = 2;
						console.log(that.meterResult)
					},
					fail: function(err) {
						console.log(err)
					}
				})



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