<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="创建人名称" prop="createName">
        <el-input
          v-model="queryParams.createName"
          placeholder="请输入创建人名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新人名称" prop="updateName">
        <el-input
          v-model="queryParams.updateName"
          placeholder="请输入更新人名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流量计编号" prop="ybbh">
        <el-input
          v-model="queryParams.ybbh"
          placeholder="请输入流量计编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求渐近速度系数 E" prop="dE">
        <el-input
          v-model="queryParams.dE"
          placeholder="请输入求渐近速度系数 E"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求相对密度系数 FG" prop="dFG">
        <el-input
          v-model="queryParams.dFG"
          placeholder="请输入求相对密度系数 FG"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求流动温度系数 FT" prop="dFT">
        <el-input
          v-model="queryParams.dFT"
          placeholder="请输入求流动温度系数 FT"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求动力粘度dlnd" prop="dDViscosity">
        <el-input
          v-model="queryParams.dDViscosity"
          placeholder="请输入求动力粘度dlnd"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求可膨胀系数" prop="dDExpCoefficient">
        <el-input
          v-model="queryParams.dDExpCoefficient"
          placeholder="请输入求可膨胀系数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管道雷诺数" prop="dRnPipe">
        <el-input
          v-model="queryParams.dRnPipe"
          placeholder="请输入管道雷诺数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="孔板锐利度系数Bk" prop="dBk">
        <el-input
          v-model="queryParams.dBk"
          placeholder="请输入孔板锐利度系数Bk"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管道粗糙度系数 Gme" prop="dRoughNessPipe">
        <el-input
          v-model="queryParams.dRoughNessPipe"
          placeholder="请输入管道粗糙度系数 Gme"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修正后的流出系数" prop="dCdCorrect">
        <el-input
          v-model="queryParams.dCdCorrect"
          placeholder="请输入修正后的流出系数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="喷嘴的流出系数" prop="dCdNozell">
        <el-input
          v-model="queryParams.dCdNozell"
          placeholder="请输入喷嘴的流出系数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标况体积流量m³/s" prop="dVFlowb">
        <el-input
          v-model="queryParams.dVFlowb"
          placeholder="请输入标况体积流量m³/s"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工况体积流量" prop="dVFlowf">
        <el-input
          v-model="queryParams.dVFlowf"
          placeholder="请输入工况体积流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标况质量流量" prop="dMFlowb">
        <el-input
          v-model="queryParams.dMFlowb"
          placeholder="请输入标况质量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标况能量流量" prop="dEFlowb">
        <el-input
          v-model="queryParams.dEFlowb"
          placeholder="请输入标况能量流量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管道内天然气流速" prop="dVelocityFlow">
        <el-input
          v-model="queryParams.dVelocityFlow"
          placeholder="请输入管道内天然气流速"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="压力损失" prop="dPressLost">
        <el-input
          v-model="queryParams.dPressLost"
          placeholder="请输入压力损失"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="直径比" prop="dBeta">
        <el-input
          v-model="queryParams.dBeta"
          placeholder="请输入直径比"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="等熵指数" prop="dKappa">
        <el-input
          v-model="queryParams.dKappa"
          placeholder="请输入等熵指数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="取样编号" prop="sampleno">
        <el-input
          v-model="queryParams.sampleno"
          placeholder="请输入取样编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仪表编号" prop="meterno">
        <el-input
          v-model="queryParams.meterno"
          placeholder="请输入仪表编号"
          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="['ngtools:meterresult:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ngtools:meterresult:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ngtools:meterresult:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['ngtools:meterresult:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="meterresultList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="创建人名称" align="center" prop="createName" />
      <el-table-column label="更新人名称" align="center" prop="updateName" />
      <el-table-column label="流量计编号" align="center" prop="ybbh" />
      <el-table-column label="求渐近速度系数 E" align="center" prop="dE" />
      <el-table-column label="求相对密度系数 FG" align="center" prop="dFG" />
      <el-table-column label="求流动温度系数 FT" align="center" prop="dFT" />
      <el-table-column label="求动力粘度dlnd" align="center" prop="dDViscosity" />
      <el-table-column label="求可膨胀系数" align="center" prop="dDExpCoefficient" />
      <el-table-column label="管道雷诺数" align="center" prop="dRnPipe" />
      <el-table-column label="孔板锐利度系数Bk" align="center" prop="dBk" />
      <el-table-column label="管道粗糙度系数 Gme" align="center" prop="dRoughNessPipe" />
      <el-table-column label="修正后的流出系数" align="center" prop="dCdCorrect" />
      <el-table-column label="喷嘴的流出系数" align="center" prop="dCdNozell" />
      <el-table-column label="标况体积流量m³/s" align="center" prop="dVFlowb" />
      <el-table-column label="工况体积流量" align="center" prop="dVFlowf" />
      <el-table-column label="标况质量流量" align="center" prop="dMFlowb" />
      <el-table-column label="标况能量流量" align="center" prop="dEFlowb" />
      <el-table-column label="管道内天然气流速" align="center" prop="dVelocityFlow" />
      <el-table-column label="压力损失" align="center" prop="dPressLost" />
      <el-table-column label="直径比" align="center" prop="dBeta" />
      <el-table-column label="等熵指数" align="center" prop="dKappa" />
      <el-table-column label="取样编号" align="center" prop="sampleno" />
      <el-table-column label="仪表编号" align="center" prop="meterno" />
      <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="['ngtools:meterresult:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['ngtools:meterresult: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="meterresultRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="创建人名称" prop="createName">
          <el-input v-model="form.createName" placeholder="请输入创建人名称" />
        </el-form-item>
        <el-form-item label="更新人名称" prop="updateName">
          <el-input v-model="form.updateName" placeholder="请输入更新人名称" />
        </el-form-item>
        <el-form-item label="流量计编号" prop="ybbh">
          <el-input v-model="form.ybbh" placeholder="请输入流量计编号" />
        </el-form-item>
        <el-form-item label="求渐近速度系数 E" prop="dE">
          <el-input v-model="form.dE" placeholder="请输入求渐近速度系数 E" />
        </el-form-item>
        <el-form-item label="求相对密度系数 FG" prop="dFG">
          <el-input v-model="form.dFG" placeholder="请输入求相对密度系数 FG" />
        </el-form-item>
        <el-form-item label="求流动温度系数 FT" prop="dFT">
          <el-input v-model="form.dFT" placeholder="请输入求流动温度系数 FT" />
        </el-form-item>
        <el-form-item label="求动力粘度dlnd" prop="dDViscosity">
          <el-input v-model="form.dDViscosity" placeholder="请输入求动力粘度dlnd" />
        </el-form-item>
        <el-form-item label="求可膨胀系数" prop="dDExpCoefficient">
          <el-input v-model="form.dDExpCoefficient" placeholder="请输入求可膨胀系数" />
        </el-form-item>
        <el-form-item label="管道雷诺数" prop="dRnPipe">
          <el-input v-model="form.dRnPipe" placeholder="请输入管道雷诺数" />
        </el-form-item>
        <el-form-item label="孔板锐利度系数Bk" prop="dBk">
          <el-input v-model="form.dBk" placeholder="请输入孔板锐利度系数Bk" />
        </el-form-item>
        <el-form-item label="管道粗糙度系数 Gme" prop="dRoughNessPipe">
          <el-input v-model="form.dRoughNessPipe" placeholder="请输入管道粗糙度系数 Gme" />
        </el-form-item>
        <el-form-item label="修正后的流出系数" prop="dCdCorrect">
          <el-input v-model="form.dCdCorrect" placeholder="请输入修正后的流出系数" />
        </el-form-item>
        <el-form-item label="喷嘴的流出系数" prop="dCdNozell">
          <el-input v-model="form.dCdNozell" placeholder="请输入喷嘴的流出系数" />
        </el-form-item>
        <el-form-item label="标况体积流量m³/s" prop="dVFlowb">
          <el-input v-model="form.dVFlowb" placeholder="请输入标况体积流量m³/s" />
        </el-form-item>
        <el-form-item label="工况体积流量" prop="dVFlowf">
          <el-input v-model="form.dVFlowf" placeholder="请输入工况体积流量" />
        </el-form-item>
        <el-form-item label="标况质量流量" prop="dMFlowb">
          <el-input v-model="form.dMFlowb" placeholder="请输入标况质量流量" />
        </el-form-item>
        <el-form-item label="标况能量流量" prop="dEFlowb">
          <el-input v-model="form.dEFlowb" placeholder="请输入标况能量流量" />
        </el-form-item>
        <el-form-item label="管道内天然气流速" prop="dVelocityFlow">
          <el-input v-model="form.dVelocityFlow" placeholder="请输入管道内天然气流速" />
        </el-form-item>
        <el-form-item label="压力损失" prop="dPressLost">
          <el-input v-model="form.dPressLost" placeholder="请输入压力损失" />
        </el-form-item>
        <el-form-item label="直径比" prop="dBeta">
          <el-input v-model="form.dBeta" placeholder="请输入直径比" />
        </el-form-item>
        <el-form-item label="等熵指数" prop="dKappa">
          <el-input v-model="form.dKappa" placeholder="请输入等熵指数" />
        </el-form-item>
        <el-form-item label="取样编号" prop="sampleno">
          <el-input v-model="form.sampleno" placeholder="请输入取样编号" />
        </el-form-item>
        <el-form-item label="仪表编号" prop="meterno">
          <el-input v-model="form.meterno" placeholder="请输入仪表编号" />
        </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>
  </div>
</template>

<script setup name="Meterresult">
import { listMeterresult, getMeterresult, delMeterresult, addMeterresult, updateMeterresult } from "@/api/ngtools/meterresult";

const { proxy } = getCurrentInstance();

const meterresultList = 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 data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    createName: null,
    updateName: null,
    ybbh: null,
    dE: null,
    dFG: null,
    dFT: null,
    dDViscosity: null,
    dDExpCoefficient: null,
    dRnPipe: null,
    dBk: null,
    dRoughNessPipe: null,
    dCdCorrect: null,
    dCdNozell: null,
    dVFlowb: null,
    dVFlowf: null,
    dMFlowb: null,
    dEFlowb: null,
    dVelocityFlow: null,
    dPressLost: null,
    dBeta: null,
    dKappa: null,
    sampleno: null,
    meterno: null
  },
  rules: {
  }
});

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

/** 查询流量计算结果列表 */
function getList() {
  loading.value = true;
  listMeterresult(queryParams.value).then(response => {
    meterresultList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

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

// 表单重置
function reset() {
  form.value = {
    id: null,
    createName: null,
    createBy: null,
    createTime: null,
    updateName: null,
    updateBy: null,
    updateTime: null,
    ybbh: null,
    dE: null,
    dFG: null,
    dFT: null,
    dDViscosity: null,
    dDExpCoefficient: null,
    dRnPipe: null,
    dBk: null,
    dRoughNessPipe: null,
    dCdCorrect: null,
    dCdNozell: null,
    dVFlowb: null,
    dVFlowf: null,
    dMFlowb: null,
    dEFlowb: null,
    dVelocityFlow: null,
    dPressLost: null,
    dBeta: null,
    dKappa: null,
    sampleno: null,
    meterno: null
  };
  proxy.resetForm("meterresultRef");
}

/** 搜索按钮操作 */
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
  getMeterresult(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改流量计算结果";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["meterresultRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateMeterresult(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addMeterresult(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 delMeterresult(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

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

getList();
</script>
