Newer
Older
Nanping_sponge_SJJC / src / views / dataAnalysis / dataService / waterAnalysis / analysisReport.vue
@liyingjing liyingjing on 25 Oct 2023 4 KB 数据检测
<template>
  <!-- 分析报表 -->
  <div class="">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="stCode">
        <el-select v-model="queryParams.stCode" filterable placeholder="请选择站点" style="width: 300px">
          <el-option
            v-for="dict in searchSiteList"
            :key="dict.stCode"
            :label="`${dict.stName}-${dict.stCode}`"
            :value="dict.stCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="dateRange">
        <dateSelect valueFormat="YYYY-MM-DD" :dateTime="queryParams.dateRange" @update="changeTime"></dateSelect>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="getTableHead">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableData" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column label="序号" type="index" width="55" />
      <template v-for="item in tableHeads" :key="item.key">
        <el-table-column v-if="item.isChild === 1" :label="item.title" :prop="item.key" show-overflow-tooltip />
        <el-table-column v-else :label="item.title">
          <el-table-column
            v-for="child in item.childList"
            :key="child.key"
            :label="child.title"
            :prop="child.key"
            width="120"
            show-overflow-tooltip
          ></el-table-column>
        </el-table-column>
      </template>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getTableData"
    />
  </div>
</template>

<script setup>
import { listRepairAllSite } from '@/api/dataAnalysis/repairdata';
import { analysisReportHeads, analysisReport } from '@/api/dataAnalysis/dataCapability';
import dateSelect from '@/views/dataAnalysis/components/dateSelect'; //日期组件
import { findDictObj } from '@/utils/ruoyi.js';
const { proxy } = getCurrentInstance();
const activeName = ref('first');
const loading = ref(false);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const searchSiteList = ref([]); //站点搜索列表
const total = ref(0);
const tableData = ref([]);
const tableHeads = ref([]); //动态表头数据
const data = reactive({
  queryParams: {
    stCode: null,
    pageNum: 1,
    pageSize: 10,
    dateRange: [proxy.moment(new Date()).format('YYYY-MM-DD'), proxy.moment(new Date()).add(1, 'days').format('YYYY-MM-DD')],
  },
});

const { queryParams } = toRefs(data);

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

//修改时间
function changeTime(val) {
  queryParams.value.dateRange = val;
}
//获取站点列表
function getSearchSiteList() {
  loading.value = true;
  listRepairAllSite({ platformCode: 111211 }).then(res => {
    searchSiteList.value = res.data;
    queryParams.value.stCode = searchSiteList.value.length ? searchSiteList.value[0].stCode : '';
    getTableHead();
  });
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm('queryRef');
  queryParams.value.stCode = searchSiteList.value.length ? searchSiteList.value[0].stCode : '';
  getTableHead();
}

//获取动态表头
function getTableHead() {
  loading.value = true;
  analysisReportHeads({ stCode: queryParams.value.stCode }).then(res => {
    tableHeads.value = res.data;
    getTableData();
  });
}
//获取表格数据
function getTableData() {
  loading.value = true;
  let params = proxy.formatAddDateRange(queryParams.value, queryParams.value.dateRange, 'startTime', 'endTime');
  analysisReport(params).then(res => {
    loading.value = false;
    tableData.value = res.data;
    total.value = res.total;
  });
}
getSearchSiteList();
</script>
<style lang="scss" scoped></style>