chengxiangling
2025-05-16 af1c9e588f1de0240390648f9bb56aa486870aff
src/views/mainPlan/gasProduceStatics/index.vue
@@ -6,49 +6,84 @@
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
      label-position="left"
    >
      <el-row type="flex" justify="left">
        <el-form-item label="统计方式">
          <el-select
            v-model="queryParams.searchType"
            style="width: 200px"
            placeholder="Select"
            @change="handleChangeSelectType"
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item :label="$t('plan.query.statistical')" :style="{ width: '100%' }">
            <el-select
              v-model="queryParams.searchType"
              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-col>
        <el-col :span="6">
          <el-form-item
            :style="{ width: '250px' }"
            :label="
              !dayCom
                ? $t('plan.query.selectDateRange')
                : $t('plan.query.selectDateMonth')
            "
          >
            <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="选择区间">
          <div v-if="!dayCom">
            <el-date-picker
              v-model="queryParams.monthRange"
              type="monthrange"
              range-separator="至"
              start-placeholder="选择开始月份"
              end-placeholder="选择结束月份"
            />
          </div>
          <div v-else>
            <el-date-picker
              v-model="queryParams.monthDays"
              type="month"
              placeholder="选择月份"
            />
          </div>
        </el-form-item>
        <el-form-item class="column-with-margin">
          <el-button type="primary" icon="Search" @click="handleQuery"
            >查询</el-button
            <div v-if="!dayCom">
              <el-date-picker
               :style="{ width: '100%' }"
                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
                 :style="{ width: '100%' }"
                v-model="queryParams.monthDays"
                type="month"
                :placeholder="$t('plan.placeholder.selectMonth')"
              />
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="dayCom">
          <el-form-item
            :label="$t('basic.table.applicableFactories')"
            prop="plant"
            :style="{ width: '100%' }"
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
            <el-select
              clearable
              v-model="queryParams.applicableFactory"
              :placeholder="$t('basic.table.applicableFactories')"
            >
              <el-option
                v-for="item in aps_factory"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="6" style="text-align:right;">
          <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-col> -->
      </el-row>
    </el-form>
    <el-row :gutter="10" class="mb8">
@@ -60,60 +95,57 @@
          @click="handleExport"
          v-hasPermi="['aps:apsGasPipingRouteStat:exportExcel']"
          :disabled="loading"
          >导出</el-button
          >{{ $t("common.common.export") }}</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          type="success"
          plain
          icon="Refresh"
          @click="handleRefresh"
          v-hasPermi="['aps:apsGasPipingRouteStat:computeCapacity']"
          :disabled="loading"
          >更新</el-button
          >{{ $t("common.common.update") }}</el-button
        >
      </el-col>
      <right-toolbar @queryTable="handleQuery" :search="false"></right-toolbar>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="handleQuery"
        @resetTable="resetQuery"
      ></right-toolbar>
    </el-row>
    <vxe-grid ref="gridRef" v-bind="gridOptions" :loading="loading"></vxe-grid>
  </div>
</template>
<script setup name="gasProduceStatics">
<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 { ElMessage } from "element-plus";
import { useI18n } from "vue-i18n"; //要在js中使用国际化
const { t, locale } = useI18n();
const { proxy } = getCurrentInstance();
const { aps_factory } = proxy.useDict("aps_factory");
const loading = ref(false);
const gridRef = ref();
const height = ref(document.documentElement.clientHeight - 180 + "px;");
const headers = ref([]);
const exportData = ref([]);
// const exportData = ref([]);
const showSearch = ref(true);
const data = reactive({
  queryParams: {
    monthRange: "",
    monthDays: "",
    searchType: "按月统计",
    searchType: t("plan.options.monthlyStatic"),
  },
});
let searchTypeValue = ref("month");
const options = [
  {
    value: "month",
    label: "按月统计",
  },
  {
    value: "day",
    label: "按日统计",
  },
];
let options = ref([]);
const { queryParams } = toRefs(data);
const gridOptions = reactive({
  border: true,
@@ -140,7 +172,32 @@
const dayCom = ref(false);
let tableColumn = [];
let tableData = [];
let merges = [];
// 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");
    if (
      (!queryParams.value.monthRange && dayCom.value == false) ||
      (!queryParams.value.monthDays && dayCom.value == true)
    ) {
      return;
    }
    // queryParams.value.pageNum = 1;
    getGasList();
  },
  { immediate: true, deep: true }
);
function handleChangeSelectType(e) {
  searchTypeValue.value = e;
  if (e === "day") {
@@ -172,11 +229,22 @@
    eYearMonth: `${eYear}-${eMonth.toString().padStart(2, "0")}`,
  };
}
const formatTypeLabelPlant = (list) => {
  if (list) {
    return list
      .map((type) => {
        const item = aps_factory.value.find((item) => item.value === type);
        return item ? item.label : type;
      })
      .join("");
  }
  return "";
};
function getGasList() {
  let rowKey = 0;
  let colKey = 0;
  headers.value = [];
  exportData.value = [];
  // exportData.value = [];
  tableColumn = [];
  tableData = [];
  loading.value = true;
@@ -189,48 +257,76 @@
      : dateStr(queryParams.value.monthDays),
    searchType: searchTypeValue.value,
    major: "gas",
    plant: !dayCom.value?"": queryParams.value.applicableFactory
  }).then((response) => {
    const colList = [];
    let headersOne = [];
    let headersTwo = [];
    if (response.code == "200") {
      if (!response.data.planTitle) {
        loading.value = false;
        return;
      }
      headersOne.push("日期");
      headersTwo.push("工序名称");
      colList.push({
        field: "dateCol",
        title: "日期",
        fixed: "left",
        children: [
          {
            field: `resourceName`,
            title: "工序名称",
            width: 250,
            type: "html",
          },
        ],
        width: 160,
      });
      if (!dayCom.value) {
        colList.push({
          field: "dateCol",
          title: t("plan.table.dateYearMonth"),
          fixed: "left",
          children: [
            {
              field: `resourceName`,
              title: t("plan.table.processName"),
              width: 250,
              type: "html",
            },
            {
              field: `resourceGroupName`,
              title: t("plan.table.applicableFactories"),
              width: 250,
              type: "html",
            },
          ],
          width: 160,
        });
      }else{
        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("设计产能");
        headersTwo.push("需求产能");
        headersTwo.push("产能负载");
        // 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: "设计产能", width: 80 },
            { field: `requireTimes${colKey}`, title: "需求产能", width: 80 },
            {
              field: `designTimes${colKey}`,
              title: t("plan.table.designWorkingHours"),
              width: 80,
            },
            {
              field: `requireTimes${colKey}`,
              title: t("plan.table.requiredWorkingHours"),
              width: 80,
            },
            {
              field: `capacityLoad${colKey}`,
              title: "产能负载",
              title: t("plan.table.capacityLoad"),
              width: 80,
              type: "html",
            },
@@ -239,25 +335,24 @@
        });
      });
      headers.value.push(headersOne);
      headers.value.push(headersTwo);
      // headers.value.push(headersOne);
      // headers.value.push(headersTwo);
      const columnList = [...tableColumn, ...colList];
      const dataList = [];
      let startCol = 1;
      // 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 = [];
        // let lastCol = startCol + 2;
        // merges.push({ s: { r: 0, c: startCol }, e: { r: 0, c: lastCol } });
        // startCol = lastCol + 1;
        const item = {
          id: `${rowKey}`,
        };
        for (const [key, listValue] of Object.entries(mapItem)) {
          data.push(key);
          // data.push(key);
          let tableKey = 0;
          let flag = false;
@@ -265,10 +360,14 @@
            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 + "%");
            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;
            // }
@@ -277,9 +376,15 @@
          // item[`resourceName`] = flag
          //   ? `<div class='el-badge'><sup class="el-badge__content is-fixed is-dot"></sup>${key}</div>`
          //   : key;
          item[`resourceName`] = key;
          if (!dayCom.value) {
            const lastIndex = key.lastIndexOf('_');
            item[`resourceName`] = key.slice(0, lastIndex);
            item[`resourceGroupName`] = formatTypeLabelPlant([key.slice(lastIndex + 1)]);
          }else{
            item[`resourceName`] = key
          }
        }
        exportData.value.push(data);
        // exportData.value.push(data);
        dataList.push(item);
      });
@@ -296,21 +401,23 @@
    }
  });
}
function formatCapacityLoad(designTimes,requireTimes,capacityLoad){
function formatCapacityLoad(designTimes, requireTimes, capacityLoad) {
  /**
   * // 0-100 绿色,101-120黄色,大于120红色
    listItem.capacityLoad <= 100
      ? `<font color="red">${listItem.capacityLoad}%</font>`
      : listItem.capacityLoad + "%";
   */
  if(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>`
  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}%`;
  }
}
/** 导出按钮操作 */
@@ -320,7 +427,7 @@
    (!queryParams.value.monthDays && dayCom.value == true)
  ) {
    ElMessage({
      message: "请选择年月",
      message: t("plan.message.errorMonthEmpty"),
      type: "error",
    });
    return;
@@ -347,7 +454,7 @@
    (!queryParams.value.monthDays && dayCom.value == true)
  ) {
    ElMessage({
      message: "请选择年月",
      message: t("plan.message.errorMonthEmpty"),
      type: "error",
    });
    return;
@@ -361,7 +468,7 @@
  queryParams.value.monthRange = "";
  queryParams.value.monthDays = "";
  dayCom.value = false;
  (queryParams.value.searchType = "按月统计"),
  (queryParams.value.searchType = t("plan.options.monthlyStatic")),
    (searchTypeValue.value = "month");
  tableData = [];
  const $grid = gridRef.value;
@@ -378,7 +485,7 @@
    (!queryParams.value.monthDays && dayCom.value == true)
  ) {
    ElMessage({
      message: "请选择年月",
      message: t("plan.message.errorMonthEmpty"),
      type: "error",
    });
    return;
@@ -388,7 +495,7 @@
    major: "gas",
  }).then((response) => {
    ElMessage({
      message: "数据更新成功",
      message: t("plan.message.update"),
      type: "success",
    });
    loading.value = false;
@@ -399,6 +506,9 @@
// getList();
</script>
<style lang="scss" scoped>
.column-with-margin {
  margin-right: 0px;
}
.box_container {
  width: 100%;
  margin: 20px auto;