<template>
	<view>
		<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="dCbtj" label-width='150' label="计量参比条件">
								<yjly-dictItemSelect sql-condition="cbtj" v-model="formData.dCbtj"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>
						<view class="formItem">
							<uni-forms-item :required="true" name="dPatm" label-width='150' label="当地大气压MPa">
								<uni-easyinput placeholder="当地大气压" v-model="formData.dPatm" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if="meterType==0">
							<uni-forms-item name="dPipeType" label-width='150' label="管道类型">
								<yjly-dictItemSelect sql-condition="gdlx" v-model="formData.dPipeType"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==0">
							<uni-forms-item name="dCoreType" label-width='150' label="节流装置类型">
								<yjly-dictItemSelect sql-condition="jlzzlx"
									v-model="formData.dCoreType"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if="meterType==0 || meterType==2">
							<uni-forms-item name="dPipeMaterial" label-width='150' label="管道材料">
								<yjly-dictItemSelect sql-condition="jsclpzxs"
									v-model="formData.dPipeMaterial"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==0">
							<uni-forms-item name="dOrificeMaterial" label-width='150' label="孔板材料">
								<yjly-dictItemSelect sql-condition="jsclpzxs"
									v-model="formData.dOrificeMaterial"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==2">
							<uni-forms-item name="dOrificeMaterial" label-width='150' label="喷嘴材料">
								<yjly-dictItemSelect sql-condition="jsclpzxs"
									v-model="formData.dOrificeMaterial"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if="meterType==0 || meterType==2">
							<uni-forms-item :required="true" name="dPipeD" label-width='150' label="管道内径mm">
								<uni-easyinput placeholder="管道内径" v-model="formData.dPipeD" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==2">
							<uni-forms-item :required="true" name="dOrificeD" label-width='150' label="喷嘴喉径(mm)">
								<uni-easyinput placeholder="喷嘴喉径" v-model="formData.dOrificeD"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==0">
							<uni-forms-item :required="true" name="dOrificeD" label-width='150' label="孔板孔径mm">
								<uni-easyinput placeholder="孔板孔径" v-model="formData.dOrificeD"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>


						<view class="formItem">
							<uni-forms-item name="dPfType" label-width='150' label="压力类型">
								<yjly-dictItemSelect sql-condition="yllx" v-model="formData.dPfType"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==0">
							<uni-forms-item name="dPtmode" label-width='150' label="取压方式">
								<yjly-dictItemSelect sql-condition="qyfs" v-model="formData.dPtmode"></yjly-dictItemSelect>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==2">
							<uni-forms-item :required="true" name="dCd" label-width='150' label="流出系数">
								<uni-easyinput placeholder="流出系数" v-model="formData.dCd" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==6 || meterType==7 || meterType==9">
							<uni-forms-item :required="true" name="dVGsc" label-width='150' label="管束车水容积m³">
								<uni-easyinput placeholder="管束车水容积" v-model="formData.dVGsc"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==8">
							<uni-forms-item :required="true" name="dMLNG" label-width='150' label="LNG质量kg">
								<uni-easyinput placeholder="LNG质量kg" v-model="formData.dMLNG"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if="meterType!=7 && meterType !=9  && meterType !=10 ">
							<uni-forms-item :required="true" name="dPf" label-width='150' label="压力MPa">
								<uni-easyinput placeholder="输入压力" v-model="formData.dPf" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType!=7 && meterType !=9 &&   meterType !=10 ">
							<uni-forms-item :required="true" name="dTf" label-width='150' label="温度℃">
								<uni-easyinput placeholder="输入温度" v-model="formData.dTf" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>

						<view class="formItem" v-if="meterType==10 ">

						</view>

						<view class="formItem" v-if=" meterType ==9 || meterType ==10 ">
							<uni-forms-item :required="true" name="dPf" label-width='150' label="起始压力MPa">
								<uni-easyinput placeholder="输入压力" v-model="formData.dPf" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if=" meterType ==9 || meterType ==10 ">
							<uni-forms-item :required="true" name="dTf" label-width='150' label="起始温度℃">
								<uni-easyinput placeholder="输入温度" v-model="formData.dTf" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if=" meterType ==9 || meterType ==10 ">
							<uni-forms-item :required="true" name="dPf" label-width='150' label="压力步长MPa">
								<uni-easyinput placeholder="输入压力步长" v-model="formData.dPStep"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if=" meterType ==9 || meterType ==10">
							<uni-forms-item :required="true" name="dTf" label-width='150' label="温度步长℃">
								<uni-easyinput placeholder="输入温度步长" v-model="formData.dTStep"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if=" meterType ==9 || meterType ==10">
							<uni-forms-item :required="true" name="dPf" label-width='150' label="终止压力MPa">
								<uni-easyinput placeholder="输入终止压力" v-model="formData.dPEnd"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if=" meterType ==9 ||  meterType ==10">
							<uni-forms-item :required="true" name="dTf" label-width='150' label="终止温度℃">
								<uni-easyinput placeholder="输入终止温度" v-model="formData.dTEnd"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>

						<view class="formItem" v-if="meterType==0">
							<uni-forms-item :required="true" name="dDp" label-width='150' label="差压kPa">
								<uni-easyinput placeholder="输入差压" v-model="formData.dDp" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==1">
							<uni-forms-item name="dMeterFactor" label-width='150' label="仪表系数">
								<uni-easyinput placeholder="仪表系数" v-model="formData.dMeterFactor"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==1">
							<uni-forms-item name="dPulseNum" label-width='150' label="脉冲数">
								<uni-easyinput placeholder="脉冲数" v-model="formData.dPulseNum"
									trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if="meterType==7">
							<uni-forms-item :required="true" name="dPf" label-width='150' label="起始压力MPa">
								<uni-easyinput placeholder="输入压力" v-model="formData.dPf" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==7">
							<uni-forms-item :required="true" name="dTf" label-width='150' label="起始温度℃">
								<uni-easyinput placeholder="输入温度" v-model="formData.dTf" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>


						<view class="formItem" v-if="meterType==7">
							<uni-forms-item :required="true" name="dPfEnd" label-width='150' label="最终压力MPa">
								<uni-easyinput placeholder="输入压力" v-model="formData.dPfEnd" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
						<view class="formItem" v-if="meterType==7">
							<uni-forms-item :required="true" name="dTfEnd" label-width='150' label="最终温度℃">
								<uni-easyinput placeholder="输入温度" v-model="formData.dTfEnd" trim="both"></uni-easyinput>
							</uni-forms-item>
						</view>
					</view>
				</scroll-view>
			</uni-forms>
		</uni-card>
	</view>
</template>

<script>
	 
	import {
		validator
	} from '@/js_sdk/validator/ngTools_MeterPar.js';

	function getValidator(fields) {
		// console.log(validator)
		let result = {}
		for (let key in validator) {
			if (fields.indexOf(key) > -1) {
				result[key] = validator[key]
			}
		}
		return result
	}
	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": "",







			}
			return {
				formData,
				formOptions: {},
				scrollerHeight: 0,
				rules: {
					...getValidator(Object.keys(formData))
				},
			}
		},
		props: {
			meterType: {
				type: Number,
				default: 0
			},
			// formData: {
			// 	type: Number,
			// 	default: 0
			// }
		},
		watch: {
			formData: {
				// immediate: true,
				deep: true,
				handler(val) {
					// console.log(val)
					this.submit(val);
				}
			},
		},

		mounted() {
			this.$refs.form.setRules(this.rules)
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					if (that.meterType == 3) {
						that.scrollerHeight = (res.windowHeight - 560)
					} else {
						that.scrollerHeight = (res.windowHeight - 200)
					}

				}
			});
			//初始化参数
			this.formData.dMeterType = this.meterType.toString();
			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"
		},
		methods: {

			/**
			 * 验证表单并提交
			 */
			submit(val) {
				this.$refs.form.validate().then((res) => {
					// console.log(res)
					this.$emit("calEnable", true);
					this.$emit("input", val);
				}).catch(() => {
					this.$emit("calEnable", false);
				}).finally(() => {

				})
			},


		}
	}
</script>

<style>
	.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;
		}
	}


	/* .formItem {
		width: 30%;
		padding-right: 10px;
	} */

	.uni-input-border,
	.uni-textarea-border {
		width: 100%;
		font-size: 14px;
		color: #666;
		border: 1px #e5e5e5 solid;
		border-radius: 5px;
		box-sizing: border-box;
	}

	.uni-input-border {
		padding: 0 10px;
		height: 35px;

	}

	.uni-textarea-border {
		padding: 10px;
		height: 80px;
	}

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

	.uni-button {
		width: 184px;
	}
</style>