<template>
  <div class="app-container">
    <el-form :model="meterPar" ref="queryForm" label-position="top" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="流量计算标准" prop="dFlowCalbz" ref="selectRef">
        <el-select v-model="meterPar.dFlowCalbz" placeholder="请选择流量计算标准 " clearable>
          <el-option v-for="dict in dict.type.ngtools_lljsbz" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="压缩因子计算标准" prop="dZcalbz">
        <el-select v-model="meterPar.dZcalbz" placeholder="请选择压缩因子计算标准 " clearable>
          <el-option v-for="dict in dict.type.ngtools_ysyzjsbz" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="计量参比条件压力" prop="dCbtj">
        <el-select v-model="meterPar.dCbtj" placeholder="请选择计量参比条件压力 " clearable>
          <el-option v-for="dict in dict.type.ngtools_cbtj" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="当地大气压" prop="dPatm">
        <unit-converter
          v-model="meterPar.dPatm"
          :unit-type="'pressure'"
          :unit-order.sync="meterPar.dPatmUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>

      <el-form-item label="流量计类别" prop="dMeterType">
        <el-select v-model="meterPar.dMeterType" placeholder="请选择流量计类别 " clearable>
          <el-option v-for="dict in dict.type.ngtools_lljlx" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="节流装置类型" prop="dCoreType">
        <el-select v-model="meterPar.dCoreType" placeholder="请选择节流装置类型 " clearable>
          <el-option v-for="dict in dict.type.ngtools_jlzzlx" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="取压方式" prop="dPtmode">
        <el-select v-model="meterPar.dPtmode" placeholder="请选择取压方式 " clearable>
          <el-option v-for="dict in dict.type.ngtools_qyfs" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="管道类型" prop="dPipeType">
        <el-select v-model="meterPar.dPipeType" placeholder="请选择管道类型 " clearable>
          <el-option v-for="dict in dict.type.ngtools_gdlx" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="管道内径" prop="dPipeD">
        <unit-converter
          v-model="meterPar.dPipeD"
          :unit-type="'length'"
          :unit-order.sync="meterPar.dLenUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="管道材料" prop="dPipeMaterial">
        <el-select v-model="meterPar.dPipeMaterial" placeholder="请选择管道材料 " clearable>
          <el-option v-for="dict in dict.type.ngtools_gdcz" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="孔板孔径" prop="dOrificeD">
        <unit-converter
          v-model="meterPar.dOrificeD"
          :unit-type="'length'"
          :unit-order.sync="meterPar.dOrificeUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>

      <el-form-item label="孔板材料" prop="dOrificeMaterial">
        <el-select v-model="meterPar.dOrificeMaterial" placeholder="请选择孔板材料 " clearable>
          <el-option v-for="dict in dict.type.ngtools_gdcz" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="输入压力" prop="dPf">
        <unit-converter
          v-model="meterPar.dPf"
          :unit-type="'pressure'"
          :unit-order.sync="meterPar.dPfUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>

      <el-form-item label="压力类型" prop="dPfType">
        <el-select v-model="meterPar.dPfType" placeholder="请选择压力类型 " clearable>
          <el-option v-for="dict in dict.type.ngtools_yllx" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="输入温度" prop="dTf">
        <unit-converter
          v-model="meterPar.dTf"
          :unit-type="'temperature'"
          :unit-order.sync="meterPar.dTfUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="输入差压" prop="dDp">
        <unit-converter
          v-model="meterPar.dDp"
          :unit-type="'pressure'"
          :unit-order.sync="meterPar.dDpUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>

      <!--  <el-form-item label="体积流量单位" prop="dVFlowUnit">
        <el-input v-model="meterPar.dVFlowUnit" placeholder="请输入体积流量单位 " clearable />
      </el-form-item>
      <el-form-item label="质量流量单位" prop="dMFlowUnit">
        <el-input v-model="meterPar.dMFlowUnit" placeholder="请输入质量流量单位 " clearable />
      </el-form-item>
      <el-form-item label="能量流量单位" prop="dEFlowUnit">
        <el-input v-model="meterPar.dEFlowUnit" placeholder="请输入能量流量单位 " clearable />
      </el-form-item> -->

      <el-form-item label="流出系数" prop="dCd">
        <el-input v-model="meterPar.dCd" placeholder="请输入流出系数 " clearable />
      </el-form-item>
      <!-- <el-form-item label="流出系数计算方法" prop="dCdCalMethod">
        <el-select v-model="meterPar.dCdCalMethod" placeholder="请选择流出系数计算方法 " clearable>
          <el-option v-for="dict in dict.type.ngtools_lcxsjsff" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="仪表系数" prop="dMeterFactor">
        <el-input v-model="meterPar.dMeterFactor" placeholder="请输入仪表系数 " clearable />
      </el-form-item>
      <el-form-item label="脉冲数" prop="dPulseNum">
        <unit-converter
          v-model="meterPar.dPulseNum"
          :unit-type="'user'"
          :unit-order.sync="meterPar.dVGscUnit"
          :show-english-only="false"
          :decimal-places="5"
          :user-defined="true"
          :user-definedunit-name="'个'"
          :enable-convert="false"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>

      <el-form-item label="管束车容积" prop="dVGsc">
        <unit-converter
          v-model="meterPar.dVGsc"
          :unit-type="'volume'"
          :unit-order.sync="meterPar.dVGscUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>

      <el-form-item label="最大体积流量" prop="dVFlowMax">
        <unit-converter
          v-model="meterPar.dVFlowMax"
          :unit-type="'volumeflow'"
          :unit-order.sync="meterPar.dVFlowUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="最小体积流量" prop="dVFlowMin">
        <unit-converter
          v-model="meterPar.dVFlowMin"
          :unit-type="'volumeflow'"
          :unit-order.sync="meterPar.dVFlowUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="常用流量" prop="dVFlowCon">
        <unit-converter
          v-model="meterPar.dVFlowCon"
          :unit-type="'volumeflow'"
          :unit-order.sync="meterPar.dVFlowUnit"
          :show-english-only="false"
          :decimal-places="5"
          :enable-convert="true"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>

      <el-form-item label="压力量程下限" prop="dPfRangeMin">
        <unit-converter
          v-model="meterPar.dPfRangeMin"
          :unit-type="'pressure'"
          :unit-order.sync="meterPar.dPfUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="压力量程上限" prop="dPfRangeMax">
        <unit-converter
          v-model="meterPar.dPfRangeMax"
          :unit-type="'pressure'"
          :unit-order.sync="meterPar.dPfUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="差压量程下限" prop="dDpRangeMin">
        <unit-converter
          v-model="meterPar.dDpRangeMin"
          :unit-type="'pressure'"
          :unit-order.sync="meterPar.dDpUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="差压量程上限" prop="dDpRangeMax">
        <unit-converter
          v-model="meterPar.dDpRangeMax"
          :unit-type="'pressure'"
          :unit-order.sync="meterPar.dDpUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="温度计量程下限" prop="dTfRangeMin">
        <unit-converter
          v-model="meterPar.dTfRangeMin"
          :unit-type="'temperature'"
          :unit-order.sync="meterPar.dTfUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
      <el-form-item label="温度计量程上限" prop="dTfRangeMax">
        <unit-converter
          v-model="meterPar.dTfRangeMax"
          :unit-type="'temperature'"
          :unit-order.sync="meterPar.dTfUnit"
          :show-english-only="false"
          :decimal-places="5"
          :width="selectWidth"
          :style="{ width: selectWidth + 'px' }"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { listMeterpar, getMeterpar, delMeterpar, addMeterpar, updateMeterpar } from '@/api/ngtools/meterpar';
import unitConverter from '@/components/inputValueUnit/index';

export default {
  name: 'meterPar',
  components: {
    unitConverter
  },
  props: {
    // 使用 v-model:meterPar 实现双向绑定
    meterPar: {
      type: Object,
      default: () => ({
        pageNum: 1,
        pageSize: 10,
        createName: null,
        createBy: null,
        createTime: null,
        updateName: null,
        updateBy: null,
        updateTime: null,
        dFlowCalbz: '0',
        dZcalbz: '0',
        dCbtj: '0',
        dpbM: null,
        dtbM: null,
        dpbE: null,
        dtbE: null,
        dPatm: 0.101325,
        dPatmUnit: 2,
        dngCompents: null,
        dMeterType: '0',
        dCoreType: '0',
        dPtmode: '0',
        dPipeType: '0',
        dPipeD: 259.38,
        dLenUnit: 3,
        dPipeDtemp: 20,
        dPileDtempU: 0,
        dPipeMaterial: '11.16',
        dOrificeD: 150.25,
        dOrificeUnit: 3,
        dOrificeDtemp: null,
        dOrificeDtempUnit: null,
        dOrificeMaterial: '16.6',
        dOrificeSharpness: null,
        dOrificeRk: null,
        dOrificeRkLenU: null,
        dPf: 1.48,
        dPfUnit: 2,
        dPfType: '0',
        dTf: 15,
        dTfUnit: 0,
        dDp: 12.5,
        dDpUnit: 1,
        dVFlowUnit: 0,
        dMFlowUnit: 0,
        dEFlowUnit: 0,
        dCd: null,
        dCdCalMethod: null,
        dMeterFactor: 2354,
        dPulseNum: 12000,
        dVFlowMax: 6,
        dVFlowMin: 3,
        dVFlowCon: 5,
        dPfRangeMin: null,
        dPfRangeMax: null,
        dDpRangeMin: null,
        dDpRangeMax: null,
        dTfRangeMin: null,
        dTfRangeMax: null,
        dVGsc: 30,
        dVGscUnit: 0,
        sampleno: null,
        meterno: null
        // 其他属性省略，可根据实际情况添加完整
      })
    }
  },
  dicts: [
    'ngtools_cbtj',
    'ngtools_jlzzlx',
    'ngtools_lljlx',
    'ngtools_qyfs',
    'ngtools_gdcz',
    'ngtools_lcxsjsff',
    'ngtools_gdlx',
    'ngtools_yllx',
    'ngtools_lljsbz',
    'ngtools_ysyzjsbz'
  ],
  data() {
    return {
      selectWidth: 0, //下拉选择组件的宽度

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 流量计参数表格数据
      meterparList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {},
  watch: {
    meterPar: {
      deep: true,
      handler(newVal) {
        // 当 meterPar 变化时触发事件通知父组件
        this.$emit('update:meterPar', newVal);
      }
    }
  },
  mounted() {
    this.selectWidth = this.$refs.selectRef.$el.offsetWidth;
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        pageNum: 1,
        pageSize: 10,
        createName: null,
        createBy: null,
        createTime: null,
        updateName: null,
        updateBy: null,
        updateTime: null,
        dFlowCalbz: null,
        dZcalbz: null,
        dCbtj: null,
        dpbM: null,
        dtbM: null,
        dpbE: null,
        dtbE: null,
        dPatm: null,
        dPatmUnit: null,
        dngCompents: null,
        dMeterType: null,
        dCoreType: null,
        dPtmode: null,
        dPipeType: null,
        dPipeD: null,
        dLenUnit: null,
        dPipeDtemp: null,
        dPileDtempU: null,
        dPipeMaterial: null,
        dOrificeD: null,
        dOrificeUnit: null,
        dOrificeDtemp: null,
        dOrificeDtempUnit: null,
        dOrificeMaterial: null,
        dOrificeSharpness: null,
        dOrificeRk: null,
        dOrificeRkLenU: null,
        dPf: null,
        dPfUnit: null,
        dPfType: null,
        dTf: null,
        dTfUnit: null,
        dDp: null,
        dDpUnit: null,
        dVFlowUnit: null,
        dMFlowUnit: null,
        dEFlowUnit: null,
        dCd: null,
        dCdCalMethod: null,
        dMeterFactor: null,
        dPulseNum: 0,
        dVFlowMax: null,
        dVFlowMin: null,
        dVFlowCon: null,
        dPfRangeMin: null,
        dPfRangeMax: null,
        dDpRangeMin: null,
        dDpRangeMax: null,
        dTfRangeMin: null,
        dTfRangeMax: null,
        dVGsc: null,
        sampleno: null,
        meterno: null
        // 其他属性省略，可根据实际情况添加完整
      };
    }
  }
};
</script>

<style scoped>
/* 可根据需要添加样式 */
</style>
