Ver Fonte

添加授课关系的批量导入

lm há 1 mês atrás
pai
commit
17c79710ce

+ 47 - 22
src/views/reviewManagement/stepComponent/teachingRelationshipComponent/TeachingRelationshipComponent.vue

@@ -30,7 +30,12 @@
             <div class="content_right">
               <el-button class="delete_button_border_no_bg" @click="ClearTeachingRelationship">清空授课</el-button>
               <el-button class="button_refresh" @click="HandleExportExcel">批量导出</el-button>
-              <el-button class="button_refresh">批量导入</el-button>
+              <el-upload action="#"
+                :auto-upload="false"
+                :show-file-list="false"
+                @change="(file)=>HandleImportExcel(file)">
+                  <el-button type="primary" class="button_refresh"> 批量导入</el-button>
+              </el-upload>
               <el-button class="button_background" @click="FinishTeachingRelationship">完成</el-button>
             </div>
           </div>
@@ -144,7 +149,6 @@
 import { ref, reactive, onMounted } from 'vue';
 import { ErrorTypes, useRoute } from 'vue-router';
 import { useStore } from 'vuex';
-
 import ExcelJS from 'exceljs';
 
 
@@ -155,7 +159,8 @@ import TabSearch from '@/baseComponents/TabSearch.vue';
 import {
   getTeachingRelationshipTableDataApi,  getTeacherListDataApi,  
   saveTeachingRelationshipApi,  deleteTeachingRelationshipApi,  
-  finishTeachingRelationshipApi,clearTeachingRelationshipApi
+  finishTeachingRelationshipApi,clearTeachingRelationshipApi, 
+  importTeachingRelationshipApi
 } from '@/api/teachingRelationshipComponent'
 
 import {getEvaluationDataDetailApi} from '@/api/evaluationDataComponent'
@@ -566,7 +571,7 @@ const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
     // 添加第一层表头
     headerRow = worksheet.addRow(topHeaders)
     // 添加第二层表头
-    subHeaderRow = worksheet.addRow(bottomHeaders)
+    // subHeaderRow = worksheet.addRow(bottomHeaders)
     
     // 定义第一层表头样式
     headerRow.eachCell((cell) => {
@@ -584,19 +589,19 @@ const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
     })
     
     // 定义第二层表头样式
-    subHeaderRow.eachCell((cell) => {
-      cell.style = {
-        font: { name: 'Microsoft YaHei', size: 11, bold: true, color: { argb: 'FF333333' } },
-        fill: { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF9FAFB' } },
-        border: {
-          top: { style: 'thin', color: { argb: 'FFD9D9D9' } },
-          left: { style: 'thin', color: { argb: 'FFD9D9D9' } },
-          bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
-          right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
-        },
-        alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
-      }
-    })
+    // subHeaderRow.eachCell((cell) => {
+    //   cell.style = {
+    //     font: { name: 'Microsoft YaHei', size: 11, bold: true, color: { argb: 'FF333333' } },
+    //     fill: { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF9FAFB' } },
+    //     border: {
+    //       top: { style: 'thin', color: { argb: 'FFD9D9D9' } },
+    //       left: { style: 'thin', color: { argb: 'FFD9D9D9' } },
+    //       bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
+    //       right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
+    //     },
+    //     alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
+    //   }
+    // })
   }
 
   // 4. 添加数据行
@@ -608,11 +613,11 @@ const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
       }
       const cellValue = row[column.name];
       if(sheetName == '行政班'){
-        return cellValue?.map((item: any) => item.teacherName || '').join(',') || '-';
+        return cellValue?.map((item: any) => item.teacherName || '').join(',');
       }else if(sheetName == '教学班'){
-        let className = cellValue.className.className
-        let teacherList = cellValue.teacherList
-        let teacherName = teacherList.map((item: any) => item.teacherName || '').join(',') || '-';
+        let className = cellValue?.className?.className
+        let teacherList = cellValue?.teacherList || []
+        let teacherName = teacherList?.map((item: any) => item.teacherName || '').join(',');
         return [className,teacherName]
       }
     }).flat();
@@ -647,7 +652,6 @@ const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
     })
   }
 }
-
 const HandleExportExcel = async () => {
   // 1. 初始化sheet列表
   let sheetList = [
@@ -687,6 +691,27 @@ const HandleExportExcel = async () => {
   URL.revokeObjectURL(url);
 };
 
+// 导入Excel
+const HandleImportExcel = async(file)=>{
+  console.log('file----------',file)
+  if(file.name.split('.').pop() !== 'xlsx' && file.name.split('.').pop() !== 'xls' ){
+    ElMessage.warning('请上传以.xlsx、.xls结尾的文件')
+    return
+  }
+  const fomData = new FormData()
+  fomData.append('file',file.raw)
+  let params = {
+    evaluationId:route.query.id,
+    evaluationGradeId:searchParmams.value.gradeId,
+    classType:searchParmams.value.classType=== 'teach' ? 1 : 0 ,  // 0-行政班,1-教学班
+  }
+  let res =   await importTeachingRelationshipApi(fomData,params)
+  if(res.code == 200){
+    // 查询查询数据
+    ElMessage.success(res.msg)
+     await reloadData()
+  }
+}
 
 // 重新加载页面数据
 const reloadData =async ()=>{