<template> 
 | 
  <div class="app-container"> 
 | 
    <el-form 
 | 
      class="responsive-form" 
 | 
      :model="queryParams" 
 | 
      ref="queryRef" 
 | 
      :inline="true" 
 | 
      v-show="showSearch" 
 | 
      :label-width="locale === 'zh' ? '68px' : '134px'" 
 | 
    > 
 | 
      <el-row type="flex" justify="left"> 
 | 
        <el-form-item :label="$t('plan.query.statistical')"> 
 | 
          <el-select 
 | 
            v-model="queryParams.searchType" 
 | 
            style="width: 200px" 
 | 
            placeholder="Select" 
 | 
            @change="handleChangeSelectType" 
 | 
          > 
 | 
            <el-option 
 | 
              v-for="item in options" 
 | 
              :key="item.value" 
 | 
              :label="item.label" 
 | 
              :value="item.value" 
 | 
            /> 
 | 
          </el-select> 
 | 
        </el-form-item> 
 | 
        <el-form-item :label="$t('plan.query.selectDateRange')"> 
 | 
          <div v-if="!dayCom"> 
 | 
            <el-date-picker 
 | 
              v-model="queryParams.monthRange" 
 | 
              type="monthrange" 
 | 
              :range-separator="$t('plan.placeholder.to')" 
 | 
              :start-placeholder="$t('plan.placeholder.startMonth')" 
 | 
              :end-placeholder="$t('plan.placeholder.endMonth')" 
 | 
            /> 
 | 
          </div> 
 | 
          <div v-else> 
 | 
            <el-date-picker 
 | 
              v-model="queryParams.monthDays" 
 | 
              type="month" 
 | 
              :placeholder="$t('plan.placeholder.selectMonth')" 
 | 
            /> 
 | 
          </div> 
 | 
        </el-form-item> 
 | 
  
 | 
        <el-form-item class="column-with-margin"> 
 | 
          <el-button type="primary" icon="Search" @click="handleQuery">{{ 
 | 
            $t("common.common.query") 
 | 
          }}</el-button> 
 | 
          <el-button icon="Refresh" @click="resetQuery">{{ 
 | 
            $t("common.common.reset") 
 | 
          }}</el-button> 
 | 
        </el-form-item> 
 | 
      </el-row> 
 | 
    </el-form> 
 | 
    <el-row :gutter="10" class="mb8"> 
 | 
      <el-col :span="1.5"> 
 | 
        <el-button 
 | 
          type="warning" 
 | 
          plain 
 | 
          icon="Download" 
 | 
          @click="handleExport" 
 | 
          v-hasPermi="['aps:apsGasPipingRouteStat:exportExcel']" 
 | 
          :disabled="loading" 
 | 
          >{{ $t("common.common.export") }}</el-button 
 | 
        > 
 | 
      </el-col> 
 | 
      <el-col :span="1.5"> 
 | 
        <el-button 
 | 
          type="success" 
 | 
          plain 
 | 
          icon="Refresh" 
 | 
          @click="handleRefresh" 
 | 
          v-hasPermi="['aps:apsGasPipingRouteStat:computeCapacity']" 
 | 
          :disabled="loading" 
 | 
          >{{ $t("common.common.update") }}</el-button 
 | 
        > 
 | 
      </el-col> 
 | 
      <right-toolbar @queryTable="handleQuery" :search="false"></right-toolbar> 
 | 
    </el-row> 
 | 
    <vxe-grid ref="gridRef" v-bind="gridOptions" :loading="loading"></vxe-grid> 
 | 
  </div> 
 | 
</template> 
 | 
  
 | 
<script setup name="gasProduceStatics"> 
 | 
import { 
 | 
  listUpdateGasProduceStatics, 
 | 
  listGasProduceStatics, 
 | 
} from "@/api/mainPlan/gasProduceStatics.js"; 
 | 
import { ref } from "vue"; 
 | 
import * as XLSX from "xlsx"; 
 | 
import { ElMessage } from "element-plus"; 
 | 
import { useI18n } from "vue-i18n"; //要在js中使用国际化 
 | 
const { t, locale } = useI18n(); 
 | 
const { proxy } = getCurrentInstance(); 
 | 
  
 | 
const loading = ref(false); 
 | 
const gridRef = ref(); 
 | 
const height = ref(document.documentElement.clientHeight - 180 + "px;"); 
 | 
const headers = ref([]); 
 | 
const exportData = ref([]); 
 | 
const showSearch = ref(true); 
 | 
const data = reactive({ 
 | 
  queryParams: { 
 | 
    monthRange: "", 
 | 
    monthDays: "", 
 | 
    searchType: t("plan.options.monthlyStatic"), 
 | 
  }, 
 | 
}); 
 | 
let searchTypeValue = ref("month"); 
 | 
let options = ref([]); 
 | 
const { queryParams } = toRefs(data); 
 | 
const gridOptions = reactive({ 
 | 
  border: true, 
 | 
  stripe: true, 
 | 
  loading: false, 
 | 
  showOverflow: true, 
 | 
  eaderOverflow: true, 
 | 
  showFooterOverflow: true, 
 | 
  height: height, 
 | 
  columnConfig: { 
 | 
    resizable: true, 
 | 
  }, 
 | 
  scrollX: { 
 | 
    enabled: true, 
 | 
    gt: 0, 
 | 
    threshold: 50, 
 | 
  }, 
 | 
  scrollY: { 
 | 
    enabled: true, 
 | 
    gt: 0, 
 | 
    threshold: 50, 
 | 
  }, 
 | 
}); 
 | 
const dayCom = ref(false); 
 | 
let tableColumn = []; 
 | 
let tableData = []; 
 | 
let merges = []; 
 | 
watch(locale, (newLocale) => { 
 | 
  options.value = [ 
 | 
    { 
 | 
      value: "month", 
 | 
      label: t("plan.options.monthlyStatic"), 
 | 
    }, 
 | 
    { 
 | 
      value: "day", 
 | 
      label: t("plan.options.dailyStatic"), 
 | 
    }, 
 | 
  ]; 
 | 
  queryParams.value.searchType = t("plan.options.monthlyStatic"); 
 | 
  handleQuery() 
 | 
},{ immediate: true, deep: true }); 
 | 
function handleChangeSelectType(e) { 
 | 
  searchTypeValue.value = e; 
 | 
  if (e === "day") { 
 | 
    dayCom.value = true; 
 | 
  } else { 
 | 
    dayCom.value = false; 
 | 
  } 
 | 
} 
 | 
function dateStr(dateTimeString) { 
 | 
  const dateTime = new Date(dateTimeString); 
 | 
  // 提取年份和月份 
 | 
  const year = dateTime.getFullYear(); 
 | 
  const month = String(dateTime.getMonth() + 1).padStart(2, "0"); // 月份从0开始,所以需要加1,并用padStart补零 
 | 
  // 格式化年份和月份为 "yyyy-mm" 格式的字符串 
 | 
  return `${year}-${month}`; 
 | 
} 
 | 
function dateRangeStr(monthRange) { 
 | 
  // 创建一个Date对象 
 | 
  let sDate = new Date(monthRange[0]); 
 | 
  let eDate = new Date(monthRange[1]); 
 | 
  // 获取年份和月份 
 | 
  let sYear = sDate.getFullYear(); 
 | 
  let sMonth = sDate.getMonth() + 1; // 月份是从0开始的,所以要加1 
 | 
  let eYear = eDate.getFullYear(); 
 | 
  let eMonth = eDate.getMonth() + 1; // 月份是从0开始的,所以要加1 
 | 
  // 格式化为"YYYY-MM"的形式 
 | 
  return { 
 | 
    sYearMonth: `${sYear}-${sMonth.toString().padStart(2, "0")}`, 
 | 
    eYearMonth: `${eYear}-${eMonth.toString().padStart(2, "0")}`, 
 | 
  }; 
 | 
} 
 | 
function getGasList() { 
 | 
  let rowKey = 0; 
 | 
  let colKey = 0; 
 | 
  headers.value = []; 
 | 
  exportData.value = []; 
 | 
  tableColumn = []; 
 | 
  tableData = []; 
 | 
  loading.value = true; 
 | 
  listGasProduceStatics({ 
 | 
    searchStartDate: !dayCom.value 
 | 
      ? dateRangeStr(queryParams.value.monthRange).sYearMonth 
 | 
      : dateStr(queryParams.value.monthDays), 
 | 
    searchEndDate: !dayCom.value 
 | 
      ? dateRangeStr(queryParams.value.monthRange).eYearMonth 
 | 
      : dateStr(queryParams.value.monthDays), 
 | 
    searchType: searchTypeValue.value, 
 | 
    major: "gas", 
 | 
  }).then((response) => { 
 | 
    const colList = []; 
 | 
    let headersOne = []; 
 | 
    let headersTwo = []; 
 | 
    if (response.code == "200") { 
 | 
      if (!response.data.planTitle) { 
 | 
        loading.value = false; 
 | 
        return; 
 | 
      } 
 | 
      headersOne.push(t("plan.table.dateYearMonth")); 
 | 
      headersTwo.push(t("plan.table.processName")); 
 | 
      colList.push({ 
 | 
        field: "dateCol", 
 | 
        title: t("plan.table.dateYearMonth"), 
 | 
        fixed: "left", 
 | 
        children: [ 
 | 
          { 
 | 
            field: `resourceName`, 
 | 
            title: t("plan.table.processName"), 
 | 
            width: 250, 
 | 
            type: "html", 
 | 
          }, 
 | 
        ], 
 | 
        width: 160, 
 | 
      }); 
 | 
      response.data.planTitle.forEach((item) => { 
 | 
        headersOne.push(item); 
 | 
        headersOne.push(""); 
 | 
        headersOne.push(""); 
 | 
        headersTwo.push(t("plan.table.designWorkingHours")); 
 | 
        headersTwo.push(t("plan.table.requiredWorkingHours")); 
 | 
        headersTwo.push(t("plan.table.capacityLoad")); 
 | 
        colKey++; 
 | 
        colList.push({ 
 | 
          field: `dateColTime${colKey}`, 
 | 
          title: item, 
 | 
          children: [ 
 | 
            { 
 | 
              field: `designTimes${colKey}`, 
 | 
              title: t("plan.table.designWorkingHours"), 
 | 
              width: 80, 
 | 
            }, 
 | 
            { 
 | 
              field: `requireTimes${colKey}`, 
 | 
              title: t("plan.table.requiredWorkingHours"), 
 | 
              width: 80, 
 | 
            }, 
 | 
            { 
 | 
              field: `capacityLoad${colKey}`, 
 | 
              title: t("plan.table.capacityLoad"), 
 | 
              width: 80, 
 | 
              type: "html", 
 | 
            }, 
 | 
          ], 
 | 
          width: 160, 
 | 
        }); 
 | 
      }); 
 | 
  
 | 
      headers.value.push(headersOne); 
 | 
      headers.value.push(headersTwo); 
 | 
  
 | 
      const columnList = [...tableColumn, ...colList]; 
 | 
      const dataList = []; 
 | 
      let startCol = 1; 
 | 
  
 | 
      //获取map 
 | 
      response.data.planTable.map((mapItem) => { 
 | 
        rowKey++; 
 | 
        let lastCol = startCol + 2; 
 | 
        merges.push({ s: { r: 0, c: startCol }, e: { r: 0, c: lastCol } }); 
 | 
        startCol = lastCol + 1; 
 | 
        let data = []; 
 | 
        const item = { 
 | 
          id: `${rowKey}`, 
 | 
        }; 
 | 
        for (const [key, listValue] of Object.entries(mapItem)) { 
 | 
          data.push(key); 
 | 
  
 | 
          let tableKey = 0; 
 | 
          let flag = false; 
 | 
          listValue.forEach((listItem) => { 
 | 
            tableKey++; 
 | 
            item[`designTimes${tableKey}`] = listItem.designTimes; 
 | 
            item[`requireTimes${tableKey}`] = listItem.requireTimes; 
 | 
            item[`capacityLoad${tableKey}`] = formatCapacityLoad( 
 | 
              listItem.designTimes, 
 | 
              listItem.requireTimes, 
 | 
              listItem.capacityLoad 
 | 
            ); 
 | 
            data.push(listItem.designTimes); 
 | 
            data.push(listItem.requireTimes); 
 | 
            data.push(listItem.capacityLoad + "%"); 
 | 
            // if (listItem.capacityLoad > 100) { 
 | 
            //   flag = true; 
 | 
            // } 
 | 
          }); 
 | 
  
 | 
          // item[`resourceName`] = flag 
 | 
          //   ? `<div class='el-badge'><sup class="el-badge__content is-fixed is-dot"></sup>${key}</div>` 
 | 
          //   : key; 
 | 
          item[`resourceName`] = key; 
 | 
        } 
 | 
        exportData.value.push(data); 
 | 
        dataList.push(item); 
 | 
      }); 
 | 
  
 | 
      const $grid = gridRef.value; 
 | 
      if ($grid) { 
 | 
        tableColumn = columnList; 
 | 
        tableData = [...tableData, ...dataList]; 
 | 
        $grid.loadColumn(tableColumn); 
 | 
        $grid.loadData(tableData); 
 | 
        gridOptions.loading = false; 
 | 
      } 
 | 
  
 | 
      loading.value = false; 
 | 
    } 
 | 
  }); 
 | 
} 
 | 
function formatCapacityLoad(designTimes, requireTimes, capacityLoad) { 
 | 
  /** 
 | 
   * // 0-100 绿色,101-120黄色,大于120红色 
 | 
    listItem.capacityLoad <= 100 
 | 
      ? `<font color="red">${listItem.capacityLoad}%</font>` 
 | 
      : listItem.capacityLoad + "%"; 
 | 
   */ 
 | 
  if (designTimes > 0 && capacityLoad > 0 && capacityLoad <= 100) { 
 | 
    return `<font color="#85cf60">${capacityLoad}%</font>`; 
 | 
  } else if (designTimes > 0 && capacityLoad > 101 && capacityLoad <= 120) { 
 | 
    return `<font color="#ecb869">${capacityLoad}%</font>`; 
 | 
  } else if (designTimes > 0 && capacityLoad > 120) { 
 | 
    return `<font color="#f89c9c">${capacityLoad}%</font>`; 
 | 
  } else if (designTimes == 0 && requireTimes > 0) { 
 | 
    return `<font color="#f56c6c">error</font>`; 
 | 
  } else { 
 | 
    return `${capacityLoad}%`; 
 | 
  } 
 | 
} 
 | 
/** 导出按钮操作 */ 
 | 
function handleExport() { 
 | 
  if ( 
 | 
    (!queryParams.value.monthRange && dayCom.value == false) || 
 | 
    (!queryParams.value.monthDays && dayCom.value == true) 
 | 
  ) { 
 | 
    ElMessage({ 
 | 
      message: t("plan.message.errorMonthEmpty"), 
 | 
      type: "error", 
 | 
    }); 
 | 
    return; 
 | 
  } 
 | 
  proxy.download( 
 | 
    "/aps/apsGasPipingRouteStat/exportExcel", 
 | 
    { 
 | 
      searchStartDate: !dayCom.value 
 | 
        ? dateRangeStr(queryParams.value.monthRange).sYearMonth 
 | 
        : dateStr(queryParams.value.monthDays), 
 | 
      searchEndDate: !dayCom.value 
 | 
        ? dateRangeStr(queryParams.value.monthRange).eYearMonth 
 | 
        : dateStr(queryParams.value.monthDays), 
 | 
      searchType: searchTypeValue.value, 
 | 
      major: "gas", 
 | 
    }, 
 | 
    `aps_gas_produce_statics_${new Date().getTime()}.xlsx` 
 | 
  ); 
 | 
} 
 | 
/** 搜索按钮操作 */ 
 | 
function handleQuery() { 
 | 
  if ( 
 | 
    (!queryParams.value.monthRange && dayCom.value == false) || 
 | 
    (!queryParams.value.monthDays && dayCom.value == true) 
 | 
  ) { 
 | 
    ElMessage({ 
 | 
      message: t("plan.message.errorMonthEmpty"), 
 | 
      type: "error", 
 | 
    }); 
 | 
    return; 
 | 
  } 
 | 
  // queryParams.value.pageNum = 1; 
 | 
  getGasList(); 
 | 
} 
 | 
  
 | 
/** 重置按钮操作 */ 
 | 
function resetQuery() { 
 | 
  queryParams.value.monthRange = ""; 
 | 
  queryParams.value.monthDays = ""; 
 | 
  dayCom.value = false; 
 | 
  (queryParams.value.searchType = t("plan.options.monthlyStatic")), 
 | 
    (searchTypeValue.value = "month"); 
 | 
  tableData = []; 
 | 
  const $grid = gridRef.value; 
 | 
  if ($grid) { 
 | 
    $grid.loadColumn([]); 
 | 
    $grid.loadData([]); 
 | 
    gridOptions.loading = false; 
 | 
  } 
 | 
} 
 | 
/** 刷新按钮操作 */ 
 | 
function handleRefresh() { 
 | 
  if ( 
 | 
    (!queryParams.value.monthRange && dayCom.value == false) || 
 | 
    (!queryParams.value.monthDays && dayCom.value == true) 
 | 
  ) { 
 | 
    ElMessage({ 
 | 
      message: t("plan.message.errorMonthEmpty"), 
 | 
      type: "error", 
 | 
    }); 
 | 
    return; 
 | 
  } 
 | 
  loading.value = true; 
 | 
  listUpdateGasProduceStatics({ 
 | 
    major: "gas", 
 | 
  }).then((response) => { 
 | 
    ElMessage({ 
 | 
      message: t("plan.message.update"), 
 | 
      type: "success", 
 | 
    }); 
 | 
    loading.value = false; 
 | 
    getGasList(); 
 | 
  }); 
 | 
} 
 | 
  
 | 
// getList(); 
 | 
</script> 
 | 
<style lang="scss" scoped> 
 | 
.box_container { 
 | 
  width: 100%; 
 | 
  margin: 20px auto; 
 | 
  background: #fff; 
 | 
  border-radius: 5px; 
 | 
  box-shadow: 1px 1px 1px 4px#f1f1f1; 
 | 
  .title_text { 
 | 
    padding-top: 20px; 
 | 
    margin-left: 20px; 
 | 
  } 
 | 
  .tabel_container { 
 | 
    width: 98%; 
 | 
    margin: 20px auto; 
 | 
  } 
 | 
} 
 | 
</style> 
 |