cfofpp 4 месяцев назад
Родитель
Сommit
f441fac32f
1 измененных файлов с 108 добавлено и 11 удалено
  1. 108 11
      src/views/distributionnetwork/team-manage/index.vue

+ 108 - 11
src/views/distributionnetwork/team-manage/index.vue

@@ -41,6 +41,20 @@
           >新增</el-button
         >
       </el-col>
+      <el-col :span="1.5">
+        <el-upload
+          :action="uploadUrl"
+          :headers="headers"
+          :show-file-list="false"
+          :before-upload="beforeUpload"
+          :on-success="handleSuccess"
+          :on-error="handleError"
+        >
+          <el-button type="primary" icon="el-icon-upload" size="mini"
+            >全量导入</el-button
+          >
+        </el-upload>
+      </el-col>
     </el-row>
     <div class="table" v-loading="loading">
       <el-table
@@ -192,18 +206,27 @@
 </template>
 
 <script>
+import { getToken } from "@/utils/auth";
 import {
   constructTeam,
   deleteConstructTeam,
 } from "@/api/powerdistribution/team-manage";
 import AddEdit from "./add-edit/index";
 import { personTypeOptions } from "./team.data";
+
 export default {
   components: {
     AddEdit,
   },
   data() {
     return {
+      // 上传相关配置
+      uploadUrl:
+        process.env.VUE_APP_BASE_API +
+        "/powerdistribution/constructTeam/import", // 上传地址
+      headers: {
+        Authorization: "Bearer " + getToken(),
+      },
       personTypeOptions,
       dataList: [],
       wrapperDataList: [],
@@ -266,7 +289,8 @@ export default {
         .sort((a, b) => a.teamSerialNo - b.teamSerialNo);
     },
     objectSpanMethod({ row, column, rowIndex }) {
-      const propertiesToMerge = [
+      // 需要合并的列
+      const mergeColumns = [
         "countyOrgNm",
         "teamNm",
         "legalPerson",
@@ -276,19 +300,20 @@ export default {
         "teamLeaderPhone",
         "construcCarNumber",
         "arrestPoint",
-        "操作",
       ];
 
-      if (propertiesToMerge.includes(column.property)) {
-        const currentValue = row[column.property];
+      // 操作列单独处理
+      if (column.property === "操作") {
+        const currentValue = row.teamNm;
+        const currentCounty = row.countyOrgNm;
         let rowspan = 1;
 
         // 向下检查相同的值
         for (let i = rowIndex + 1; i < this.wrapperDataList.length; i++) {
           if (
-            this.wrapperDataList[i][column.property] === currentValue &&
-            this.wrapperDataList[i].teamNm === row.teamNm && // 确保在同一队伍内
-            this.wrapperDataList[i].teamSerialNo === row.teamSerialNo // 确保在同一序号内
+            this.wrapperDataList[i].teamNm === currentValue &&
+            this.wrapperDataList[i].countyOrgNm === currentCounty &&
+            this.wrapperDataList[i].teamSerialNo === row.teamSerialNo
           ) {
             rowspan++;
           } else {
@@ -299,16 +324,57 @@ export default {
         // 如果不是第一个出现的值,返回 { rowspan: 0, colspan: 0 }
         if (
           rowIndex > 0 &&
-          this.wrapperDataList[rowIndex - 1][column.property] ===
-            currentValue &&
-          this.wrapperDataList[rowIndex - 1].teamNm === row.teamNm && // 确保在同一队伍内
-          this.wrapperDataList[rowIndex - 1].teamSerialNo === row.teamSerialNo // 确保在同一序号内
+          this.wrapperDataList[rowIndex - 1].teamNm === currentValue &&
+          this.wrapperDataList[rowIndex - 1].countyOrgNm === currentCounty &&
+          this.wrapperDataList[rowIndex - 1].teamSerialNo === row.teamSerialNo
         ) {
           return { rowspan: 0, colspan: 0 };
         }
 
         return { rowspan, colspan: 1 };
       }
+
+      // 其他需要合并的列
+      if (mergeColumns.includes(column.property)) {
+        const currentValue = row[column.property];
+        const currentCounty = row.countyOrgNm;
+        const currentTeam = row.teamNm;
+        let rowspan = 1;
+
+        // 向下检查相同的值
+        for (let i = rowIndex + 1; i < this.wrapperDataList.length; i++) {
+          const nextRow = this.wrapperDataList[i];
+
+          // 所有列都需要考虑队伍名称
+          if (
+            nextRow[column.property] === currentValue &&
+            nextRow.countyOrgNm === currentCounty &&
+            nextRow.teamNm === currentTeam
+          ) {
+            rowspan++;
+          } else {
+            break;
+          }
+        }
+
+        // 如果不是第一个出现的值,返回 { rowspan: 0, colspan: 0 }
+        if (rowIndex > 0) {
+          const prevRow = this.wrapperDataList[rowIndex - 1];
+
+          // 所有列都需要考虑队伍名称
+          if (
+            prevRow[column.property] === currentValue &&
+            prevRow.countyOrgNm === currentCounty &&
+            prevRow.teamNm === currentTeam
+          ) {
+            return { rowspan: 0, colspan: 0 };
+          }
+        }
+
+        return { rowspan, colspan: 1 };
+      }
+
+      // 其他列不合并
       return { rowspan: 1, colspan: 1 };
     },
     handleUpdate(row) {
@@ -358,6 +424,37 @@ export default {
       this.resetForm("queryForm");
       this.handleQuery();
     },
+    /** 文件上传前的处理 */
+    beforeUpload(file) {
+      const isExcel =
+        file.type ===
+          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
+        file.type === "application/vnd.ms-excel";
+      if (!isExcel) {
+        this.$message.error("只能上传Excel文件!");
+        return false;
+      }
+      const isLt5M = file.size / 1024 / 1024 < 5;
+      if (!isLt5M) {
+        this.$message.error("文件大小不能超过 5MB!");
+        return false;
+      }
+      return true;
+    },
+    /** 文件上传成功的处理 */
+    handleSuccess(response, file) {
+      if (response.code === 200) {
+        this.$modal.msgSuccess("导入成功");
+        this.getList();
+      } else {
+        this.$modal.msgError(response.msg || "导入失败");
+      }
+    },
+    /** 文件上传失败的处理 */
+    handleError(error) {
+      this.$modal.msgError("导入失败,请重试");
+      console.error("上传失败:", error);
+    },
   },
 };
 </script>