Browse Source

修复同比增速排序问题

littleblue55 1 month ago
parent
commit
4d31dadd7e
3 changed files with 268 additions and 41 deletions
  1. 8 4
      src/views/enterprise/enterprise/index.vue
  2. 34 10
      src/views/growthRate/index.vue
  3. 226 27
      src/views/match/index.vue

+ 8 - 4
src/views/enterprise/enterprise/index.vue

@@ -314,9 +314,16 @@ export default {
     };
   },
   created() {
+    this.init()
     this.getList();
   },
   methods: {
+    init() {
+      listEtypeAll().then((res) => {
+        this.enterTypeList = res;
+        console.log(this.enterTypeList)
+      });
+    },
     /** 查询enterprise列表 */
     getList() {
       this.loading = true;
@@ -325,10 +332,7 @@ export default {
         this.total = response.total;
         this.loading = false;
       });
-      listEtypeAll().then((res) => {
-        this.enterTypeList = res;
-        console.log(this.enterTypeList)
-      });
+      
     },
     // 取消按钮
     cancel() {

+ 34 - 10
src/views/growthRate/index.vue

@@ -426,9 +426,9 @@ export default {
           return;
         }
       } else if (["energyConsume", "funding"].includes(selectedDataKey)) {
-        this.rateForm.selectedSeason = null; 
-        this.rateForm.selectedStartMonth = null; 
-        this.rateForm.selectedEndMonth = null; 
+        this.rateForm.selectedSeason = null;
+        this.rateForm.selectedStartMonth = null;
+        this.rateForm.selectedEndMonth = null;
       }
       // -----数据校验 end-----
       const propertyMapping = {
@@ -472,18 +472,42 @@ export default {
           ? null
           : (parseFloat(item.rate) * 100).toFixed(2),
       }));
-      // 处理数据
+      console.log(rawData, sortedData, "sortedData");
       if (this.sortActive === "asc") {
-        sortedData.sort((a, b) => parseFloat(a.rate) - parseFloat(b.rate));
+        sortedData.sort((a, b) => {
+          if (a.rate === null && b.rate === null) return 0;
+          if (a.rate === null) return -1;
+          if (b.rate === null) return 1;
+          if (a.rate === "Infinity" && b.rate === "Infinity") return 0;
+          if (a.rate === "Infinity") return 1;
+          if (b.rate === "Infinity") return -1;
+          return parseFloat(a.rate) - parseFloat(b.rate);
+        });
       } else if (this.sortActive === "desc") {
-        sortedData.sort((a, b) => parseFloat(b.rate) - parseFloat(a.rate));
-      } else if (this.sortActive === "location") {
+        sortedData.sort((a, b) => {
+          if (a.rate === null && b.rate === null) return 0;
+            if (a.rate === null) return 1;   // 将null排在最后
+            if (b.rate === null) return -1; 
+            if (a.rate === "Infinity" && b.rate === "Infinity") return 0;
+            if (a.rate === "Infinity") return -1; // 将Infinity排在最前
+            if (b.rate === "Infinity") return 1;
+            // 转换为数字进行比较并进行降序排列
+            return parseFloat(b.rate) - parseFloat(a.rate);
+        });
+      }else if(this.sortActive === "location") {
         sortedData.sort((a, b) => a.location.localeCompare(b.location));
       }
+      // 处理数据
+      // if (this.sortActive === "asc") {
+      //   sortedData.sort((a, b) => parseFloat(a.rate) - parseFloat(b.rate));
+      // } else if (this.sortActive === "desc") {
+      //   sortedData.sort((a, b) => parseFloat(b.rate) - parseFloat(a.rate));
+      // } else if (this.sortActive === "location") {
+      //   sortedData.sort((a, b) => a.location.localeCompare(b.location));
+      // }
 
       sortedData.forEach((item) => {
         categories.push(item.enterpriseName);
-
         if (!item.rate || item.rate === "Infinity") {
           seriesData.push({
             value: null,
@@ -501,7 +525,7 @@ export default {
         }
       });
       that.tableData = sortedData;
-      console.log(sortedData);
+      // console.log(sortedData);
       const values = seriesData.map((s) => s.value || 0);
       const minValue = Math.min(...values); // 获取最小值
       const maxValue = Math.max(...values); // 获取最大值
@@ -515,7 +539,7 @@ export default {
       const minVal = -maxBound; // 设置最小值为负
       const maxVal = maxBound; // 设置最大值为正
 
-      console.log(minVal, maxVal);
+      // console.log(minVal, maxVal);
       // 配置图表
       const option = {
         title: {

+ 226 - 27
src/views/match/index.vue

@@ -1,13 +1,11 @@
 <template>
-  <div :class="className" :style="{ height: '100%', width: width }">
+  <div
+    :class="className"
+    :style="{ height: '100%', width: width, padding: '15px' }"
+  >
     <div class="select-container">
       <el-form
-        style="
-          display: grid;
-          grid-template-columns: 1fr 1fr 1fr;
-          align-items: center;
-          grid-gap: 5px;
-        "
+        style="display: grid; grid-template-columns: 1fr 1fr 1fr; grid-gap: 5px"
         label-width="100px"
       >
         <el-form-item label="评估指标">
@@ -23,7 +21,7 @@
           </el-select>
         </el-form-item>
         <el-form-item label="行业">
-            <el-select
+          <el-select
             v-model="matchForm.industry"
             style="width: 100%"
             filterable
@@ -38,7 +36,7 @@
           </el-select>
         </el-form-item>
         <el-form-item label="企业分类">
-            <el-select
+          <el-select
             v-model="matchForm.companyType"
             style="width: 100%"
             clearable
@@ -52,14 +50,16 @@
             </el-option>
           </el-select>
         </el-form-item>
-        <el-form-item label="相差值阈值"></el-form-item>
+        <el-form-item label="相差值阈值">
+          <el-input
+            v-model="matchForm.threshold"
+            placeholder="请输入内容"
+            style="width: 100%"
+          ></el-input>
+        </el-form-item>
         <!-- 用电:月度;用气:年度;用人:季度 -->
         <el-form-item label="年度">
-            <el-select
-            v-model="matchForm.year"
-            style="width: 100%"
-            filterable
-          >
+          <el-select v-model="matchForm.year" style="width: 100%" filterable>
             <el-option
               v-for="key in yearsOptions"
               :key="key"
@@ -69,10 +69,103 @@
             </el-option>
           </el-select>
         </el-form-item>
-        <el-form-item label="月度"></el-form-item>
-        <el-form-item label="季度"></el-form-item>
+        <el-form-item label="月度" v-if="matchForm.dataKey === 'powerConsume'">
+          <div style="display: flex; gap: 5px">
+            <el-select v-model="matchForm.elecStartMonth" filterable>
+              <el-option
+                v-for="key in monthOptions"
+                :key="key"
+                :label="key"
+                :value="key"
+              >
+              </el-option>
+            </el-select>
+            <span>-</span>
+            <el-select v-model="matchForm.elecEndMonth" filterable>
+              <el-option
+                v-for="key in monthOptions"
+                :key="key"
+                :label="key"
+                :value="key"
+              >
+              </el-option>
+            </el-select>
+          </div>
+        </el-form-item>
+        <el-form-item
+          label="季度"
+          v-if="matchForm.dataKey === 'employeeNumber'"
+        >
+          <div style="display: flex; gap: 5px">
+            <el-select v-model="matchForm.manStartSeason" filterable>
+              <el-option
+                v-for="key in seasonOptions"
+                :key="key"
+                :label="key"
+                :value="key"
+              >
+              </el-option>
+            </el-select>
+            <span>-</span>
+            <el-select v-model="matchForm.manEndSeason" filterable>
+              <el-option
+                v-for="key in seasonOptions"
+                :key="key"
+                :label="key"
+                :value="key"
+              >
+              </el-option>
+            </el-select>
+          </div>
+        </el-form-item>
+        <el-form-item>
+          <el-button
+            type="primary"
+            icon="el-icon-search"
+            @click="submit"
+            size="mini"
+            >搜索</el-button
+          >
+        </el-form-item>
       </el-form>
     </div>
+    <el-table :data="tableData" border>\
+      code: "2422"
+      enterpriseName: "企业1"
+      location: "A"
+      trueThreshold: -0.24883973894126177
+      typeName: "A"
+      typeNum: "1"
+      <el-table-column prop="enterpriseName" label="企业名称" sortable></el-table-column>
+      <el-table-column
+        prop="location"
+        label="坐落地"
+        width="200" sortable
+      ></el-table-column>
+      <el-table-column
+        prop="code"
+        label="行业代码"
+        width="200"
+      ></el-table-column>
+      <el-table-column
+        prop="typeName"
+        label="企业分类"
+        width="200"
+      ></el-table-column>
+      <el-table-column
+        prop="trueThreshold"
+        label="相差值"
+        width="200" sortable
+      ></el-table-column>
+    </el-table>
+    <el-pagination
+      v-show="total > 0"
+      :total="total"
+      :page.sync="matchForm.pageNum"
+      :limit.sync="matchForm.pageSize"
+      @pagination="submit"
+       >
+    </el-pagination>
   </div>
 </template>
 <script>
@@ -97,10 +190,14 @@ export default {
   },
   data() {
     return {
+      total: 0,
       matchForm: {
-        dataKey: "funding", //评估指标
+        pageNum: 1,
+        pageSize: 10,
+        dataKey: "powerConsume", //评估指标
         industry: "", //行业
         companyType: "", //企业分类
+        threshold: null, //相差值阈值
         // 用电
         year: "", //年度 (用电和用人都用这个年度)
         elecStartMonth: "", //起始月
@@ -109,14 +206,7 @@ export default {
         manStartSeason: "", //起始季度
         manEndSeason: "", //结束季度
       },
-      dataKeys: [
-        "funding",
-        "energyConsume",
-        "paidTax",
-        "taxableIncome",
-        "totalIndustrialValue",
-        "powerConsume",
-      ], // 可选项
+      dataKeys: ["powerConsume", "energyConsume", "employeeNumber"], // 可选项
       keyToChinese: {
         landArea: "用地面积",
         totalIndustrialValue: "工业总产值",
@@ -135,9 +225,10 @@ export default {
       monthMap: new Map(),
       yearsOptions: [],
       enterTypeList: [],
-      enterTypeList:[],
+      enterTypeList: [],
       industryData: [],
       industryMap: new Map(),
+      tableData: [],
     };
   },
   mounted() {
@@ -231,6 +322,114 @@ export default {
       const item = this.enterTypeList.find((element) => element.number === num);
       return item ? item.name : null;
     },
+    submit() {
+      // 清除无关字段
+      this.clearUnrelatedFields();
+      // 必填项校验
+      if (this.validateForm()) {
+        // this.$message.success("提交成功");
+        // console.log(this.matchForm);
+        analysisMatch(this.matchForm).then(res=>{
+          // console.log(res,"test")
+          if(res && res?.rows){
+            this.total = res.total;
+            this.tableData = res.rows.map(item => {
+              return {
+                ...item,
+                trueThreshold: parseFloat(item.trueThreshold).toFixed(4) // 转换并保留4位小数
+              };
+            });
+          }
+        })
+      }
+    },
+    clearUnrelatedFields() {
+      const { dataKey } = this.matchForm;
+      if (dataKey === "powerConsume") {
+        this.matchForm.manStartSeason = "";
+        this.matchForm.manEndSeason = "";
+      } else if (dataKey === "employeeNumber") {
+        this.matchForm.elecStartMonth = "";
+        this.matchForm.elecEndMonth = "";
+      } else if (dataKey === "energyConsume") {
+        this.matchForm.manStartSeason = "";
+        this.matchForm.manEndSeason = "";
+        this.matchForm.elecStartMonth = "";
+        this.matchForm.elecEndMonth = "";
+      }
+    },
+
+    validateForm() {
+      const { matchForm } = this;
+
+      // 行业校验
+      if (!matchForm.industry) {
+        this.$message.error("请选择行业");
+        return false;
+      }
+
+      // 阈值校验
+      const threshold = parseFloat(matchForm.threshold);
+      if (isNaN(threshold)) {
+        this.$message.error("请填写有效的相差值阈值");
+        return false;
+      }
+      matchForm.threshold = threshold; // 转换为数字
+
+      // 年度必填校验
+      if (!matchForm.year) {
+        this.$message.error("请选择年度");
+        return false;
+      }
+
+      // 针对 powerConsume 的校验
+      if (matchForm.dataKey === "powerConsume") {
+        if (!matchForm.elecStartMonth) {
+          this.$message.error("请选择起始月度");
+          return false;
+        }
+        if (!matchForm.elecEndMonth) {
+          this.$message.error("请选择结束月度");
+          return false;
+        }
+        if (matchForm.elecStartMonth > matchForm.elecEndMonth) {
+          this.$message.error("起始月度必须小于等于结束月度");
+          return false;
+        }
+      }
+
+      // 针对 employeeNumber 的校验
+      if (matchForm.dataKey === "employeeNumber") {
+        if (!matchForm.manStartSeason) {
+          this.$message.error("请选择起始季度");
+          return false;
+        }
+        if (!matchForm.manEndSeason) {
+          this.$message.error("请选择结束季度");
+          return false;
+        }
+        if (matchForm.manStartSeason > matchForm.manEndSeason) {
+          this.$message.error("起始季度必须小于等于结束季度");
+          return false;
+        }
+      }
+
+      return true; // 所有校验通过
+    },
+  },
+  computed: {
+    seasonOptions() {
+      const options = this.matchForm.year
+        ? this.seasonMap.get(this.matchForm.year)
+        : [];
+      return options || []; // 以防得到 undefined
+    },
+    monthOptions() {
+      const options = this.matchForm.year
+        ? this.monthMap.get(this.matchForm.year)
+        : [];
+      return options || []; // 以防得到 undefined
+    },
   },
 };
 </script>