<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" style="width: 308px">
        <el-date-picker
          v-model="daterangeTestDate"
          value-format="YYYY/MM/DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="calculateList" @selection-change="handleSelectionChange">
      <el-table-column label="化验时间" align="center" prop="testTime" />
      <el-table-column label="进水碳氮比" align="center" prop="jsTdb" />
      <el-table-column label="进水碳磷比" align="center" prop="jsTlb" />
      <el-table-column label="进水BOD与COD比值(生化性)" align="center" prop="jsBodBCod" />
      <el-table-column label="厌氧区停留时间" align="center" prop="yyqHrt" />
      <el-table-column label="缺氧区停留时间" align="center" prop="qyqHrt" />
      <el-table-column label="好氧区停留时间" align="center" prop="hyqHrt" />
      <el-table-column label="挥发性污泥浓度占比" align="center" prop="HFXWNNDZB" />
      <el-table-column label="F/M" align="center" prop="fM" />
      <el-table-column label="过栅流速" align="center" prop="GSLS" />
      <el-table-column label="第1道粗格栅过栅流速" align="center" prop="gslsOne" />
      <el-table-column label="第2道粗格栅过栅流速" align="center" prop="gslsTwo" />
      <el-table-column label="细格栅过栅流速" align="center" prop="xgsGsls" />
      <el-table-column label="旋流沉砂池表面负荷" align="center" prop="xlcscBmfh" />
      <el-table-column label="旋流沉砂池停留时间" align="center" prop="xlcscHrt" />
      <el-table-column label="初次沉淀池表面负荷" align="center" prop="cccdcBmfh" />
      <el-table-column label="初次沉淀池停留时间" align="center" prop="cccdcHrt" />
      <el-table-column label="二沉池表面负荷" align="center" prop="eccBmfh" />
      <el-table-column label="二沉池停留时间" align="center" prop="eccHrt" />
      <el-table-column label="二沉池固体负荷" align="center" prop="eccGtfh" />
      <el-table-column label="次氯酸钠接触时间" align="center" prop="clsnJcsj" />
      <el-table-column label="斜管沉淀池清水区上升流速" align="center" prop="xgcdcQsqSsls" />
      <el-table-column label="外回流比" align="center" prop="WHLB" />
      <el-table-column label="外回流比，新的计算方式" align="center" prop="whlRN" />
      <el-table-column label="内回流比" align="center" prop="NHLB" />
      <el-table-column label="万吨水产泥率" align="center" prop="WDSCNL" />
      <el-table-column label="生化池气水比" align="center" prop="QSB" />
      <el-table-column label="反冲洗水量" align="center" prop="FCXSL" />
      <el-table-column label="反冲洗水量比例" align="center" prop="FCXSLBL" />
      <el-table-column label="备注" align="center" prop="remark" />
    </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="calculateRef" :model="form" :rules="rules" label-width="80px">
      </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="Calculate">
import { listCalculate, getCalculate, delCalculate, addCalculate, updateCalculate } from "@/api/business/calculate";

const { proxy } = getCurrentInstance();

const calculateList = 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 daterangeTestDate = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    testDate: null,
  },
  rules: {
  }
});

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

/** 查询信义计算数据列表 */
function getList() {
  loading.value = true;
  queryParams.value.params = {};
  if (null != daterangeTestDate && '' != daterangeTestDate) {
    queryParams.value["timeBegin"] = daterangeTestDate.value[0];
    queryParams.value["timeEnd"] = daterangeTestDate.value[1];
  }
  listCalculate(queryParams.value).then(response => {
    calculateList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

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

// 表单重置
function reset() {
  form.value = {
    id: null,
    testDate: null,
    testHour: null,
    testTime: null,
    jsTdb: null,
    jsTlb: null,
    jsBodBCod: null,
    yyqHrt: null,
    qyqHrt: null,
    hyqHrt: null,
    HFXWNNDZB: null,
    fM: null,
    GSLS: null,
    gslsOne: null,
    gslsTwo: null,
    xgsGsls: null,
    xlcscBmfh: null,
    xlcscHrt: null,
    cccdcBmfh: null,
    cccdcHrt: null,
    eccBmfh: null,
    eccHrt: null,
    eccGtfh: null,
    clsnJcsj: null,
    xgcdcQsqSsls: null,
    WHLB: null,
    whlRN: null,
    NHLB: null,
    WDSCNL: null,
    QSB: null,
    FCXSL: null,
    FCXSLBL: null,
    delFlag: null,
    revision: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null
  };
  proxy.resetForm("calculateRef");
}

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

/** 重置按钮操作 */
function resetQuery() {
  daterangeTestDate.value = [];
  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
  getCalculate(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改信义计算数据";
  });
}

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

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

getList();
</script>
