<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">
				<uni-card>
					<uni-forms ref="form" label-position="top" :model="formData" validate-trigger="submit"
						err-show-type="toast">
						<scroll-view scroll-y="true" :style="{height:scrollerHeight+'px'}">
							<view class="uni-container">
								<view class="formItem">
									<uni-forms-item name="jsCs" label-width='150' label="输气工艺参数">
										<yjly-dictItemSelect sql-condition="sqgyjscs"
											v-model="formData.djsCs"></yjly-dictItemSelect>
									</uni-forms-item>
								</view>

								<view class="formItem">
									<uni-forms-item :required="true" name="jsgs" label-width='150' label="水力计算公式">
										<yjly-dictItemSelect sql-condition="sqgysljsgs"
											v-model="formData.djsGs"></yjly-dictItemSelect>
									</uni-forms-item>
								</view>


								<!-- 	<view class="formItem">
									<uni-forms-item name="dSqgLx" label-width='150' label="输气管道类型">
										<yjly-dictItemSelect sql-condition="sqgygdlx"
											v-model="formData.dSqgLx"></yjly-dictItemSelect>
									</uni-forms-item>
								</view> -->

								<view class="formItem" v-if="formData.djsCs !='0'">
									<uni-forms-item name="dflowSq" label-width='150' label="输气流量(m³/d)">
										<uni-easyinput placeholder="输气流量" v-model="formData.dflowSq"
											trim="both"></uni-easyinput>
									</uni-forms-item>
								</view>
								<view class="formItem" v-if="formData.djsCs !='1'">
									<uni-forms-item name="dPipleDw" label-width='150' label="管道外径(mm)">
										<uni-easyinput placeholder="管道外径" v-model="formData.dPipleDw"
											trim="both"></uni-easyinput>
									</uni-forms-item>
								</view>
								<view class="formItem">
									<uni-forms-item name="dPipleBh" label-width='150' label="管道壁厚(mm)">
										<uni-easyinput placeholder="管道壁厚" v-model="formData.dPipleBh"
											trim="both"></uni-easyinput>
									</uni-forms-item>
								</view>

								<view class="formItem" v-if="formData.djsCs !='2'">
									<uni-forms-item name="dPipleL" label-width='150' label="管道长度(km)">
										<uni-easyinput placeholder="管道壁厚" v-model="formData.dPipleL"
											trim="both"></uni-easyinput>
									</uni-forms-item>
								</view>

								<view class="formItem" v-if="formData.djsCs !='3'">
									<uni-forms-item name="dStartP" label-width='150' label="起点压力(MPa)">
										<uni-easyinput placeholder="起点压力" v-model="formData.dStartP"
											trim="both"></uni-easyinput>
									</uni-forms-item>
								</view>
								<view class="formItem" v-if="formData.djsCs !='4'">
									<uni-forms-item name="dEndP" label-width='150' label="终点压力(MPa)">
										<uni-easyinput placeholder="终点压力" v-model="formData.dEndP"
											trim="both"></uni-easyinput>
									</uni-forms-item>
								</view>

								<view class="formItem">
									<uni-forms-item name="strResult" label-width='150' label="计算结果">
										<uni-easyinput placeholder="计算结果" v-model="strResult"
											trim="both"></uni-easyinput>
									</uni-forms-item>
								</view>


							</view>
						</scroll-view>
					</uni-forms>
				</uni-card>
			</view>
			<view v-show="current === 1">
				<yjly-ngtools-NGComponents @calEnable="NGEnable" v-model="strNG"></yjly-ngtools-NGComponents>
			</view>

		</view>

	</view>
</template>

<script>
 

	export default {
		components: {
			 
		},
		data() {
			let formData = {
				"dFlowCalbz": "0",
				"dZcalbz": "0",
				"dCbtj": "0",
				"dPb_M": "101325",
				"dTb_M": "293.15",
				"dPb_E": "101325",
				"dTb_E": "293.15",
				"dPatm": "0.101325",
				"dPatmUnit": "2",
				"dMeterType": "0",
				"dCoreType": "0",
				"dPtmode": "0",
				"dPipeType": "0",
				"dPipeD": "0",
				"dLenUnit": "3",
				"dPipeDtemp": "20",
				"dPileDtempU": "0",
				"dPipeMaterial": "11.16",
				"dOrificeD": "0",
				"dOrificeUnit": "3",
				"dOrificeDtemp": "20",
				"dOrificeDtempUnit": "0",
				"dOrificeMaterial": "16.6",
				"dOrificeSharpness": "0",
				"dOrificeRk": "0",
				"dOrificeRkLenU": "3",
				"dPf": "0",
				"dPfUnit": "2",
				"dPfType": "0",
				"dTf": "0",
				"dTfUnit": "0",
				"dDp": "0",
				"dDpUnit": "1",
				"dVFlowUnit": "0",
				"dMFlowUnit": "2",
				"dEFlowUnit": "1",
				"dVGsc": "",
				"dPfEnd": "",
				"dTfEnd": "",
				"dMLNG": "",
				"dPStep": "",
				"dTStep": "",
				"dPEnd": "",
				"dTEnd": "",
				"djsCs": "",
				"djsGs": "",
				"dSqgLx": "0",
				"dPipleDw": "325",
				"dPipleBh": "8",
				"dPipleL": "20",
				"dStartP": "2.5",
				"dEndP": "1.8",
				"dflowSq": "30000",


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

				},
				NGFlag: false,
				meterFlag: false,
				formData,
				formOptions: {},
				scrollerHeight: 0,
				strResult: ""
			};
		},
		watch: {
			strNG: {
				immediate: true,
				deep: true,
				handler(val) {
					this.zeroPar();
				}
			},
			meterPar: {
				immediate: true,
				deep: true,
				handler(val) {
					this.zeroPar();
				}
			},
		},
		onReady() {
			this.formData.dMeterType = "0";
			this.formData.dPatm = "0.0981"
			this.formData.dPipeD = "259.38"
			this.formData.dOrificeD = "150.25"
			this.formData.dPf = "1.48"
			this.formData.dTf = "15"
			this.formData.dDp = " 12.5"
			this.formData.dMeterFactor = "20000"
			this.formData.dPulseNum = "300"
			this.formData.dCd = "0.95"
			this.formData.dVGsc = "25"
			this.formData.dPfEnd = "20"
			this.formData.dTfEnd = "35"
			this.formData.dMLNG = "10"
			this.formData.dPStep = "0.5"
			this.formData.dTStep = "1"
			this.formData.dPEnd = "5.48"
			this.formData.dTEnd = "30"

			this.formData.dPipleDw = "325"
			this.formData.dPipleBh = "8"
			this.formData.dPipleL = "20"
			this.formData.dStartP = "2.5"
			this.formData.dEndP = "1.8"
			this.formData.dflowSq = "30000"
		},
		mounted() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					if (that.meterType == 3) {
						that.scrollerHeight = (res.windowHeight - 560)
					} else {
						that.scrollerHeight = (res.windowHeight - 200)
					}

				}
			});




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

			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.formData.djsCs == "" || this.formData.djsGs == "" || this.formData
					.dPipleDw == "" || this.formData.dPipleBh == "" || this.formData.dPipleL == "" || this.formData
					.dStartP == "" || this.formData.dEndP == "" || this.formData.dflowSq == "") {
					uni.showModal({
						title: '提示',
						content: '工艺参数输入不全，请检查并重新输入',
						icon: 'none',
						showCancel: false
					})
					this.current = 0;
					return
				}
				if (!this.NGFlag) {
					uni.showModal({
						title: '提示',
						content: '组分摩尔百分数合计不为100%，请检查并重新输入',
						icon: 'none',
						showCancel: false
					})
					this.current = 1;
					return
				}

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

				NG_par = NG_par + "," + this.formData.djsCs;
				NG_par = NG_par + "," + this.formData.djsGs;
				NG_par = NG_par + "," + this.formData.dSqgLx;
				NG_par = NG_par + "," + this.formData.dPipleDw;
				NG_par = NG_par + "," + this.formData.dPipleBh;
				NG_par = NG_par + "," + this.formData.dPipleL;
				NG_par = NG_par + "," + this.formData.dStartP;
				NG_par = NG_par + "," + this.formData.dEndP;
				NG_par = NG_par + "," + this.formData.dflowSq;




				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 + "/SQGYjs",
					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.data)

						that.strResult = res.data.result;
						that.current = 0;

					},
					fail: function(res) {
						console.log(res)
					}
				})




			},
			save() {
				console.log(this.meterPar, this.meterResult)

			}
		},
	}
</script>

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

	.mini-btn {
		width: 100px;
		margin-right: 10px;
	}

	.uni-container {
		padding: 0px;
		display: flex;
		flex-wrap: wrap;
	}

	@media screen and (min-width: 1024px) {
		.formItem {
			width: 18%;
			padding-right: 10px;
		}
	}

	@media screen and (max-width: 1024px) {
		.formItem {
			width: 18%;
			padding-right: 10px;
		}
	}

	@media screen and (max-width: 768px) {
		.formItem {
			width: 22%;
			padding-right: 10px;
		}
	}

	@media screen and (max-width: 640px) {
		.formItem {
			width: 30%;
			padding-right: 10px;
		}
	}

	@media screen and (max-width: 480px) {
		.formItem {
			width: 45%;
			padding-right: 10px;
		}
	}

	@media screen and (max-width: 320px) {
		.formItem {
			width: 90%;
			padding-right: 10px;
		}
	}
</style>