<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工况压力" prop="dPf">
        <el-input
          v-model="queryParams.dPf"
          placeholder="请输入工况压力"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工况温度" prop="dTf">
        <el-input
          v-model="queryParams.dTf"
          placeholder="请输入工况温度"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工况差压" prop="dDp">
        <el-input
          v-model="queryParams.dDp"
          placeholder="请输入工况差压"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工况脉冲数" prop="dPulseNum">
        <el-input
          v-model="queryParams.dPulseNum"
          placeholder="请输入工况脉冲数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工况流量" prop="dVFlowfInput">
        <el-input
          v-model="queryParams.dVFlowfInput"
          placeholder="请输入工况流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="今日计量秒数" prop="dJrsjSeconds">
        <el-input
          v-model="queryParams.dJrsjSeconds"
          placeholder="请输入今日计量秒数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昨日计量秒数" prop="dZrsjSeconds">
        <el-input
          v-model="queryParams.dZrsjSeconds"
          placeholder="请输入昨日计量秒数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工况体积流量" prop="dVFlowfSs">
        <el-input
          v-model="queryParams.dVFlowfSs"
          placeholder="请输入工况体积流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准状态体积流量" prop="dVFlowbSs">
        <el-input
          v-model="queryParams.dVFlowbSs"
          placeholder="请输入标准状态体积流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="今日体积流量" prop="dVFlowbJrl">
        <el-input
          v-model="queryParams.dVFlowbJrl"
          placeholder="请输入今日体积流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昨日体积流量" prop="dVFlowbZrl">
        <el-input
          v-model="queryParams.dVFlowbZrl"
          placeholder="请输入昨日体积流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准状态质量流量" prop="dMFlowbSs">
        <el-input
          v-model="queryParams.dMFlowbSs"
          placeholder="请输入标准状态质量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="今日质量流量" prop="dMFlowbJrl">
        <el-input
          v-model="queryParams.dMFlowbJrl"
          placeholder="请输入今日质量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昨日质量流量" prop="dMFlowbZrl">
        <el-input
          v-model="queryParams.dMFlowbZrl"
          placeholder="请输入昨日质量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准状态能量流量" prop="dEFlowbSs">
        <el-input
          v-model="queryParams.dEFlowbSs"
          placeholder="请输入标准状态能量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="今日能量流量" prop="dEFlowbJrl">
        <el-input
          v-model="queryParams.dEFlowbJrl"
          placeholder="请输入今日能量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昨日能量流量" prop="dEFlowbZrl">
        <el-input
          v-model="queryParams.dEFlowbZrl"
          placeholder="请输入昨日能量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总体积流量" prop="dVFlowbZll">
        <el-input
          v-model="queryParams.dVFlowbZll"
          placeholder="请输入总体积流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总质量流量" prop="dMFlowbZll">
        <el-input
          v-model="queryParams.dMFlowbZll"
          placeholder="请输入总质量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总能量流量" prop="dEFlowbZll">
        <el-input
          v-model="queryParams.dEFlowbZll"
          placeholder="请输入总能量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段1" prop="dRyl1">
        <el-input
          v-model="queryParams.dRyl1"
          placeholder="请输入预留字段1"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段2" prop="dRyl2">
        <el-input
          v-model="queryParams.dRyl2"
          placeholder="请输入预留字段2"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段3" prop="dRyl3">
        <el-input
          v-model="queryParams.dRyl3"
          placeholder="请输入预留字段3"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段4" prop="dRyl4">
        <el-input
          v-model="queryParams.dRyl4"
          placeholder="请输入预留字段4"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['plc:flowresult:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['plc:flowresult:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['plc:flowresult:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['plc:flowresult:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="flowresultList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="工况压力" align="center" prop="dPf" />
      <el-table-column label="工况温度" align="center" prop="dTf" />
      <el-table-column label="工况差压" align="center" prop="dDp" />
      <el-table-column label="工况脉冲数" align="center" prop="dPulseNum" />
      <el-table-column label="工况流量" align="center" prop="dVFlowfInput" />
      <el-table-column label="今日计量秒数" align="center" prop="dJrsjSeconds" />
      <el-table-column label="昨日计量秒数" align="center" prop="dZrsjSeconds" />
      <el-table-column label="工况体积流量" align="center" prop="dVFlowfSs" />
      <el-table-column label="标准状态体积流量" align="center" prop="dVFlowbSs" />
      <el-table-column label="今日体积流量" align="center" prop="dVFlowbJrl" />
      <el-table-column label="昨日体积流量" align="center" prop="dVFlowbZrl" />
      <el-table-column label="标准状态质量流量" align="center" prop="dMFlowbSs" />
      <el-table-column label="今日质量流量" align="center" prop="dMFlowbJrl" />
      <el-table-column label="昨日质量流量" align="center" prop="dMFlowbZrl" />
      <el-table-column label="标准状态能量流量" align="center" prop="dEFlowbSs" />
      <el-table-column label="今日能量流量" align="center" prop="dEFlowbJrl" />
      <el-table-column label="昨日能量流量" align="center" prop="dEFlowbZrl" />
      <el-table-column label="总体积流量" align="center" prop="dVFlowbZll" />
      <el-table-column label="总质量流量" align="center" prop="dMFlowbZll" />
      <el-table-column label="总能量流量" align="center" prop="dEFlowbZll" />
      <el-table-column label="预留字段1" align="center" prop="dRyl1" />
      <el-table-column label="预留字段2" align="center" prop="dRyl2" />
      <el-table-column label="预留字段3" align="center" prop="dRyl3" />
      <el-table-column label="预留字段4" align="center" prop="dRyl4" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['plc:flowresult:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['plc:flowresult:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改流量处理结果对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="flowresultRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="工况压力" prop="dPf">
          <el-input v-model="form.dPf" placeholder="请输入工况压力" />
        </el-form-item>
        <el-form-item label="工况温度" prop="dTf">
          <el-input v-model="form.dTf" placeholder="请输入工况温度" />
        </el-form-item>
        <el-form-item label="工况差压" prop="dDp">
          <el-input v-model="form.dDp" placeholder="请输入工况差压" />
        </el-form-item>
        <el-form-item label="工况脉冲数" prop="dPulseNum">
          <el-input v-model="form.dPulseNum" placeholder="请输入工况脉冲数" />
        </el-form-item>
        <el-form-item label="工况流量" prop="dVFlowfInput">
          <el-input v-model="form.dVFlowfInput" placeholder="请输入工况流量" />
        </el-form-item>
        <el-form-item label="今日计量秒数" prop="dJrsjSeconds">
          <el-input v-model="form.dJrsjSeconds" placeholder="请输入今日计量秒数" />
        </el-form-item>
        <el-form-item label="昨日计量秒数" prop="dZrsjSeconds">
          <el-input v-model="form.dZrsjSeconds" placeholder="请输入昨日计量秒数" />
        </el-form-item>
        <el-form-item label="工况体积流量" prop="dVFlowfSs">
          <el-input v-model="form.dVFlowfSs" placeholder="请输入工况体积流量" />
        </el-form-item>
        <el-form-item label="标准状态体积流量" prop="dVFlowbSs">
          <el-input v-model="form.dVFlowbSs" placeholder="请输入标准状态体积流量" />
        </el-form-item>
        <el-form-item label="今日体积流量" prop="dVFlowbJrl">
          <el-input v-model="form.dVFlowbJrl" placeholder="请输入今日体积流量" />
        </el-form-item>
        <el-form-item label="昨日体积流量" prop="dVFlowbZrl">
          <el-input v-model="form.dVFlowbZrl" placeholder="请输入昨日体积流量" />
        </el-form-item>
        <el-form-item label="标准状态质量流量" prop="dMFlowbSs">
          <el-input v-model="form.dMFlowbSs" placeholder="请输入标准状态质量流量" />
        </el-form-item>
        <el-form-item label="今日质量流量" prop="dMFlowbJrl">
          <el-input v-model="form.dMFlowbJrl" placeholder="请输入今日质量流量" />
        </el-form-item>
        <el-form-item label="昨日质量流量" prop="dMFlowbZrl">
          <el-input v-model="form.dMFlowbZrl" placeholder="请输入昨日质量流量" />
        </el-form-item>
        <el-form-item label="标准状态能量流量" prop="dEFlowbSs">
          <el-input v-model="form.dEFlowbSs" placeholder="请输入标准状态能量流量" />
        </el-form-item>
        <el-form-item label="今日能量流量" prop="dEFlowbJrl">
          <el-input v-model="form.dEFlowbJrl" placeholder="请输入今日能量流量" />
        </el-form-item>
        <el-form-item label="昨日能量流量" prop="dEFlowbZrl">
          <el-input v-model="form.dEFlowbZrl" placeholder="请输入昨日能量流量" />
        </el-form-item>
        <el-form-item label="总体积流量" prop="dVFlowbZll">
          <el-input v-model="form.dVFlowbZll" placeholder="请输入总体积流量" />
        </el-form-item>
        <el-form-item label="总质量流量" prop="dMFlowbZll">
          <el-input v-model="form.dMFlowbZll" placeholder="请输入总质量流量" />
        </el-form-item>
        <el-form-item label="总能量流量" prop="dEFlowbZll">
          <el-input v-model="form.dEFlowbZll" placeholder="请输入总能量流量" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="dRyl1">
          <el-input v-model="form.dRyl1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="dRyl2">
          <el-input v-model="form.dRyl2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="dRyl3">
          <el-input v-model="form.dRyl3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="dRyl4">
          <el-input v-model="form.dRyl4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="主表id" prop="主表id">
          <el-input v-model="form.主表id" placeholder="请输入主表id" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
	<meterPar v-model="parentMeterPar" :el-form-width="elFormItemWidth" />
  </div>
</template>

<script setup name="Flowresult">
import { listFlowresult, getFlowresult, delFlowresult, addFlowresult, updateFlowresult } from "@/api/production/plc/flowresult/flowresult"


import meterPar from '@/components/NGTools/meterPar';


const { proxy } = getCurrentInstance()

const flowresultList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const elFormItemWidth = ref(160);
	const parentMeterPar = ref({
		dFlowCalbz: '0',
		dZcalbz: '0',
		dCbtj: '0',
		dpbM: 0,
		dtbM: 0,
		dpbE: 0,
		dtbE: 0,
		dPatm: 0.0981,
		dPatmUnit: 2,
		dngComponents: '',
		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: 0,
		dOrificeDtempUnit: 0,
		dOrificeMaterial: '16.6',
		dOrificeSharpness: 0,
		dOrificeRk: 0,
		dOrificeRkLenU: 0,
		dPf: 1.48,
		dPfUnit: 2,
		dPfType: '0',
		dTf: 15,
		dTfUnit: 0,
		dDp: 12.5,
		dDpUnit: 1,
		dVFlowUnit: 0,
		dVFlowWorkUnit: 0,
		dMFlowUnit: 0,
		dEFlowUnit: 6,
		dCd: 0.9957,
		dCdCalMethod: 0,
		dMeterFactor: 2354,
		dPulseNum: 12000,
		dVFlowMax: 30,
		dVFlowMin: 12,
		dVFlowCon: 0.03,
		dPfRangeMin: 0,
		dPfRangeMax: 0,
		dDpRangeMin: 0,
		dDpRangeMax: 0,
		dTfRangeMin: 0,
		dTfRangeMax: 0,
		dVGsc: 300,
		dVGscUnit: 0,
		dCalcType: 0, //0 流量 1  天然气  3 管束车
		dBqdd: 0 //0 不计算，1 计算  计算不确定度
	});
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    dPf: null,
    dTf: null,
    dDp: null,
    dPulseNum: null,
    dVFlowfInput: null,
    dJrsjSeconds: null,
    dZrsjSeconds: null,
    dVFlowfSs: null,
    dVFlowbSs: null,
    dVFlowbJrl: null,
    dVFlowbZrl: null,
    dMFlowbSs: null,
    dMFlowbJrl: null,
    dMFlowbZrl: null,
    dEFlowbSs: null,
    dEFlowbJrl: null,
    dEFlowbZrl: null,
    dVFlowbZll: null,
    dMFlowbZll: null,
    dEFlowbZll: null,
    dRyl1: null,
    dRyl2: null,
    dRyl3: null,
    dRyl4: null,
  },
  rules: {
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询流量处理结果列表 */
function getList() {
  loading.value = true
  listFlowresult(queryParams.value).then(response => {
    flowresultList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null,
    dPf: null,
    dTf: null,
    dDp: null,
    dPulseNum: null,
    dVFlowfInput: null,
    dJrsjSeconds: null,
    dZrsjSeconds: null,
    dVFlowfSs: null,
    dVFlowbSs: null,
    dVFlowbJrl: null,
    dVFlowbZrl: null,
    dMFlowbSs: null,
    dMFlowbJrl: null,
    dMFlowbZrl: null,
    dEFlowbSs: null,
    dEFlowbJrl: null,
    dEFlowbZrl: null,
    dVFlowbZll: null,
    dMFlowbZll: null,
    dEFlowbZll: null,
    dRyl1: null,
    dRyl2: null,
    dRyl3: null,
    dRyl4: null,
    主表id: null
  }
  proxy.resetForm("flowresultRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加流量处理结果"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getFlowresult(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改流量处理结果"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["flowresultRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateFlowresult(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addFlowresult(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除流量处理结果编号为"' + _ids + '"的数据项？').then(function() {
    return delFlowresult(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('plc/flowresult/export', {
    ...queryParams.value
  }, `flowresult_${new Date().getTime()}.xlsx`)
}

getList()
</script>
