deason 6 years ago
parent
commit
9d1016f0be
1 changed files with 429 additions and 251 deletions
  1. 429 251
      src/modules/print/view/CourseStatistic.vue

+ 429 - 251
src/modules/print/view/CourseStatistic.vue

@@ -124,6 +124,7 @@
               size="small"
               type="primary"
               icon="el-icon-download"
+              :disabled="selectElements.length == 0"
               @click="openExportDialog"
               >批量导出
             </el-button>
@@ -132,6 +133,7 @@
               size="small"
               type="primary"
               icon="el-icon-refresh"
+              :disabled="selectElements.length == 0"
               @click="refreshStatistic"
               >刷新
             </el-button>
@@ -145,6 +147,7 @@
           element-loading-text="数据加载中"
           style="width:100%;"
           border
+          @selection-change="handleSelection"
         >
           <el-table-column type="selection" width="55"> </el-table-column>
           <el-table-column label="课程名称" prop="courseName" />
@@ -177,7 +180,7 @@
                 size="mini"
                 icon="el-icon-download"
                 v-show="scope.row.paperStatus > 1"
-                @click="download(scope.row);"
+                @click="openExportDialog(scope.row);"
                 >下载
               </el-button>
             </template>
@@ -251,177 +254,172 @@
         </el-form>
       </el-dialog>
 
-      <el-dialog title="试卷整体分配" :visible.sync="allotAllDialog">
+      <el-dialog
+        title="试卷整体分配"
+        width="400px"
+        :visible.sync="allotAllDialog"
+        @close="closeAllotAllDialog"
+      >
         <el-form
           :model="allotAllForm"
+          ref="allotAllForm"
+          :rules="rules"
           label-position="right"
-          label-width="100px"
+          label-width="80px"
         >
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="学校名称">
-                <el-select
-                  v-model="allotAllForm.orgId"
-                  @change="searchExamList(allotAllForm.orgId, 2);"
-                >
-                  <el-option label="请选择" value></el-option>
-                  <el-option
-                    v-for="item in orgList"
-                    :label="item.orgName"
-                    :value="item.orgId"
-                    :key="item.orgId"
-                  ></el-option>
-                </el-select>
-              </el-form-item>
-            </el-col>
-          </el-row>
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="考试名称">
-                <el-select v-model="allotAllForm.examId">
-                  <el-option label="请选择" value></el-option>
-                  <el-option
-                    v-for="item in examList"
-                    :label="item.examName"
-                    :value="item.examId"
-                    :key="item.examId"
-                  ></el-option>
-                </el-select>
-              </el-form-item>
-            </el-col>
-          </el-row>
-          <el-row :gutter="10">
-            <el-col :span="20">
-              <el-form-item>
-                <span style="font-size:20px;color: red;"
-                  >警告!确定后,选中考试中待指定的课程会在推送试卷中随机选取一套试卷,是否确定执行?</span
-                >
-              </el-form-item>
-            </el-col>
-          </el-row>
-          <el-row>
-            <el-col
-              :span="24"
-              class="text-center"
-              style="border-top: 2px solid;padding-top: 10px;"
+          <el-form-item label="学校名称" prop="orgId">
+            <el-select
+              v-model="allotAllForm.orgId"
+              @change="searchAllotExamList(allotAllForm.orgId);"
+              placeholder="请选择"
+              class="w220"
             >
-              <el-button
-                type="primary"
-                :disabled="
-                  allotAllForm.orgId === '' || allotAllForm.examId === ''
-                "
-                @click="saveAllotAll"
-                >确定</el-button
-              >
-            </el-col>
-          </el-row>
+              <el-option
+                v-for="item in orgList"
+                :label="item.orgName"
+                :value="item.orgId"
+                :key="item.orgId"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+
+          <el-form-item label="考试名称" prop="examId">
+            <el-select
+              v-model="allotAllForm.examId"
+              placeholder="请选择"
+              class="w220"
+            >
+              <el-option
+                v-for="item in allotExamList"
+                :label="item.examName"
+                :value="item.examId"
+                :key="item.examId"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+
+          <div style="text-align: center">
+            <p style="color: red;">
+              警告:确定后当前考试中“未指定试卷”的课程会在已有的试卷中随机选取一套试卷分配关联,是否确定执行?
+            </p>
+            <el-button
+              type="primary"
+              @click="saveAllotAll"
+              :disabled="allotAllForm.examId == ''"
+              >确 定</el-button
+            >
+            <el-button @click="closeAllotAllDialog">取 消</el-button>
+          </div>
         </el-form>
       </el-dialog>
 
-      <el-dialog title="导出" :visible.sync="exportDialog">
-        <el-form :model="exportForm" label-position="right" label-width="80px">
-          <el-checkbox-group v-model="exportForm.types">
-            <el-checkbox label="1">试卷</el-checkbox>
-            <el-checkbox label="2">答案</el-checkbox>
-            <el-checkbox label="3">试卷结构</el-checkbox>
-          </el-checkbox-group>
+      <el-dialog
+        title="导出"
+        width="450px"
+        :visible.sync="exportDialog"
+        @close="closeExportDialog"
+      >
+        <el-form
+          :model="exportForm"
+          ref="exportForm"
+          :rules="rules"
+          label-position="right"
+          label-width="90px"
+        >
+          <el-form-item label="导出内容" prop="types">
+            <el-checkbox-group v-model="exportForm.types">
+              <el-checkbox label="1">试卷</el-checkbox>
+              <el-checkbox label="2">答案</el-checkbox>
+              <el-checkbox label="3">试卷结构</el-checkbox>
+            </el-checkbox-group>
+          </el-form-item>
+
           <div style="text-align: center">
-            <el-button type="primary" @click="doExport">确定导出</el-button>
+            <el-button
+              type="primary"
+              @click="doExport"
+              :disabled="exportForm.types.length == 0"
+              >确定导出</el-button
+            >
             <el-button @click="closeExportDialog">取 消</el-button>
           </div>
         </el-form>
       </el-dialog>
 
-      <el-dialog title="试卷整体导出" :visible.sync="exportAllDialog">
+      <el-dialog
+        title="试卷整体导出"
+        width="450px"
+        :visible.sync="exportAllDialog"
+        @close="closeExportAllDialog"
+      >
         <el-form
           :model="exportAllForm"
+          ref="exportAllForm"
+          :rules="rules"
           label-position="right"
-          label-width="100px"
+          label-width="90px"
         >
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="学校名称">
-                <el-select
-                  v-model="exportAllForm.orgId"
-                  @change="searchExamList(exportAllForm.orgId, 3);"
-                >
-                  <el-option label="请选择" value></el-option>
-                  <el-option
-                    v-for="item in orgList"
-                    :label="item.orgName"
-                    :value="item.orgId"
-                    :key="item.orgId"
-                  ></el-option>
-                </el-select>
-              </el-form-item>
-            </el-col>
-          </el-row>
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="考试名称">
-                <el-select
-                  v-model="exportAllForm.examId"
-                  @change="searchExamCoursePaperTotal"
-                >
-                  <el-option label="请选择" value></el-option>
-                  <el-option
-                    v-for="item in examList"
-                    :label="item.examName"
-                    :value="item.examId"
-                    :key="item.examId"
-                  ></el-option>
-                </el-select>
-              </el-form-item>
-            </el-col>
-          </el-row>
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="试卷总数">{{
-                exportAllForm.allNum
-              }}</el-form-item>
-            </el-col>
-          </el-row>
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="已有试卷数">{{
-                exportAllForm.existNum
-              }}</el-form-item>
-            </el-col>
-          </el-row>
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="缺少试卷数">{{
-                exportAllForm.missNum
-              }}</el-form-item>
-            </el-col>
-          </el-row>
-
-          <el-row :gutter="10">
-            <el-col :md="20">
-              <el-form-item label="导出内容">
-                <el-checkbox-group v-model="exportAllForm.types">
-                  <el-checkbox label="1">试卷</el-checkbox>
-                  <el-checkbox label="2">答案</el-checkbox>
-                  <el-checkbox label="3">试卷结构</el-checkbox>
-                </el-checkbox-group>
-              </el-form-item>
-            </el-col>
-          </el-row>
-
-          <el-row :gutter="10">
-            <el-col
-              :span="24"
-              class="text-center"
-              style="border-top: 2px solid;padding-top: 10px;"
+          <el-form-item label="学校名称" prop="orgId">
+            <el-select
+              v-model="exportAllForm.orgId"
+              @change="searchExportExamList(exportAllForm.orgId);"
+              placeholder="请选择"
+              class="w220"
             >
-              <el-button
-                type="primary"
-                :disabled="exportAllForm.existNum == 0"
-                @click="doExportAll"
-                >确定导出</el-button
-              >
-            </el-col>
-          </el-row>
+              <el-option
+                v-for="item in orgList"
+                :label="item.orgName"
+                :value="item.orgId"
+                :key="item.orgId"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+
+          <el-form-item label="考试名称" prop="examId">
+            <el-select
+              v-model="exportAllForm.examId"
+              @change="searchExamCoursePaperTotal"
+              placeholder="请选择"
+              class="w220"
+            >
+              <el-option
+                v-for="item in exportExamList"
+                :label="item.examName"
+                :value="item.examId"
+                :key="item.examId"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+
+          <el-form-item label="导出内容" prop="types">
+            <el-checkbox-group v-model="exportAllForm.types">
+              <el-checkbox label="1">试卷</el-checkbox>
+              <el-checkbox label="2">答案</el-checkbox>
+              <el-checkbox label="3">试卷结构</el-checkbox>
+            </el-checkbox-group>
+          </el-form-item>
+
+          <el-form-item label="试卷总数" prop="allNum">
+            {{ exportAllForm.allNum }}
+          </el-form-item>
+
+          <el-form-item label="已有试卷数" prop="existNum">
+            {{ exportAllForm.existNum }}
+          </el-form-item>
+
+          <el-form-item label="缺少试卷数" prop="missNum">
+            {{ exportAllForm.missNum }}
+          </el-form-item>
+
+          <div style="text-align: center">
+            <el-button
+              type="primary"
+              @click="doExportAll"
+              :disabled="exportAllForm.existNum == 0"
+              >确定导出</el-button
+            >
+            <el-button @click="closeExportAllDialog">取 消</el-button>
+          </div>
         </el-form>
       </el-dialog>
     </div>
@@ -455,6 +453,7 @@ export default {
       courseList: [],
       coursePaperList: [],
       coursePaperStatusList: coursePaperStatusList,
+      allotExamList: [],
       allotDialog: false,
       allotForm: {
         id: "",
@@ -467,28 +466,29 @@ export default {
         orgId: "",
         examId: ""
       },
+      selectElements: [],
+      exportExamList: [],
       exportDialog: false,
       exportForm: {
-        orgId: "",
-        examId: "",
-        courseCode: "",
-        courseName: "",
-        paperType: "",
-        coursePaperId: "",
-        courseId: "",
-        id: ""
+        ids: [],
+        types: []
       },
       exportAllDialog: false,
       exportAllForm: {
         orgId: "",
         examId: "",
-        exportList: [],
+        types: [],
         allNum: 0,
         existNum: 0,
-        missNum: 0,
-        types: []
+        missNum: 0
       },
       rules: {
+        orgId: [
+          { required: true, message: "学校不能为空!", trigger: "change" }
+        ],
+        examId: [
+          { required: true, message: "考试不能为空!", trigger: "change" }
+        ],
         coursePaperId: [
           { required: true, message: "试卷不能为空!", trigger: "change" }
         ],
@@ -497,13 +497,166 @@ export default {
         ],
         paperType: [
           { required: true, message: "试卷类型不能为空!", trigger: "change" }
+        ],
+        types: [
+          { required: true, message: "请选择导出内容!", trigger: "change" }
         ]
       }
     };
   },
   methods: {
-    searchExamCoursePaperTotal() {
-      /* xxx */
+    handleSelection(elements) {
+      /* 处理选中记录 */
+      this.selectElements = elements;
+    },
+    handlePager(current) {
+      /* 处理分页 */
+      this.formSearch.pageNo = current;
+      this.searchRecords();
+    },
+    searchRecords() {
+      /* 查询记录列表 */
+      let orgId = this.formSearch.orgId;
+      if (this.isEmptyNumber(orgId)) {
+        this.$notify({
+          message: "请选择学校!",
+          type: "warning"
+        });
+        return;
+      }
+
+      let examId = this.formSearch.examId;
+      if (this.isEmptyNumber(examId)) {
+        this.$notify({
+          message: "请选择考试!",
+          type: "warning"
+        });
+        return;
+      }
+
+      this.loading = true;
+      let url = PRINT_API + "/course/statistic/list";
+      this.$http.post(url, this.formSearch).then(
+        response => {
+          this.tableData = response.data.content;
+          this.totalElements = response.data.totalElements;
+          this.loading = false;
+        },
+        error => {
+          console.log(error);
+          this.loading = false;
+        }
+      );
+    },
+    searchExamList(orgId) {
+      /* 查询考试列表 */
+      this.formSearch.examId = "";
+      this.examList = [];
+      this.tableData = [];
+
+      if (!this.isEmptyNumber(orgId)) {
+        let url = PRINT_API + "/printing/project/exam/list?orgId=" + orgId;
+        this.$http.post(url).then(response => {
+          this.examList = response.data;
+        });
+      }
+    },
+    searchAllotExamList(orgId) {
+      /* 查询考试列表 */
+      this.allotAllForm.examId = "";
+      this.allotExamList = [];
+
+      if (!this.isEmptyNumber(orgId)) {
+        let url = PRINT_API + "/printing/project/exam/list?orgId=" + orgId;
+        this.$http.post(url).then(response => {
+          this.allotExamList = response.data;
+        });
+      }
+    },
+    searchExportExamList(orgId) {
+      /* 查询考试列表 */
+      this.exportAllForm.examId = "";
+      this.exportExamList = [];
+
+      if (!this.isEmptyNumber(orgId)) {
+        let url = PRINT_API + "/printing/project/exam/list?orgId=" + orgId;
+        this.$http.post(url).then(response => {
+          this.exportExamList = response.data;
+        });
+      }
+    },
+    searchCourseList(query) {
+      /* 查询课程列表 */
+      this.courseList = [];
+      let url = CORE_API + "/course/query?enable=true";
+
+      if (!this.isEmptyStr(query)) {
+        url += "&name=" + query;
+      }
+
+      this.$http.get(url).then(response => {
+        this.courseList = response.data;
+      });
+    },
+    refreshStatistic() {
+      /* 刷新当前统计信息 */
+      this.$confirm("刷新当前统计信息?", "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning"
+      })
+        .then(() => {
+          if (this.selectElements.length == 0) {
+            this.$notify({
+              message: "请选择要刷新的项!",
+              type: "warning"
+            });
+            return;
+          }
+
+          let params = {};
+          params.orgId = this.selectElements[0].orgId;
+          params.examId = this.selectElements[0].examId;
+          params.couses = [];
+          this.selectElements.forEach(element => {
+            params.couses.push({
+              courseId: element.courseId,
+              paperType: element.paperType
+            });
+          });
+
+          let url = PRINT_API + "/course/statistic/refresh";
+          this.$http.post(url, params).then(
+            () => {
+              this.$notify({
+                type: "success",
+                message: "刷新成功!"
+              });
+              this.searchRecords();
+            },
+            () => {
+              this.$notify({
+                type: "error",
+                message: "刷新失败!"
+              });
+            }
+          );
+        })
+        .catch(() => {
+          //ignore
+        });
+    },
+    preview(row) {
+      /* 预览试卷PDF */
+      let url = row.paperPdfUrl;
+      if (!url) {
+        this.$notify({
+          message: "当前试卷不存在!",
+          type: "warning"
+        });
+        return;
+      }
+      window.open(url);
     },
     openAllotDialog(row) {
       /* 试卷状态为"已有"时,打开试卷指定弹窗 */
@@ -513,6 +666,7 @@ export default {
         this.allotForm.coursePaperId = row.coursePaperId;
         this.allotForm.courseName = row.courseName;
         this.allotForm.paperType = row.paperType;
+
         let params = {
           orgId: row.orgId,
           examId: row.examId,
@@ -564,19 +718,51 @@ export default {
       });
     },
     openAllotAllDialog() {
-      /* 打开分配待指定试卷弹窗 */
+      /* 打开试卷整体分配弹窗 */
       this.allotAllDialog = true;
     },
     closeAllotAllDialog() {
-      /* 关闭分配待指定试卷弹窗 */
+      /* 关闭试卷整体分配弹窗 */
       this.allotAllDialog = false;
     },
     saveAllotAll() {
-      /* 保存分配待指定试卷 */
+      /* 保存试卷整体分配 */
+      this.$refs.allotAllForm.validate(valid => {
+        if (!valid) {
+          return false;
+        }
+
+        let url =
+          PRINT_API +
+          "/course/paper/allot/all/" +
+          this.allotAllForm.orgId +
+          "/" +
+          this.allotAllForm.examId;
+
+        this.$http.post(url).then(
+          () => {
+            this.$notify({
+              message: "试卷整体分配成功!",
+              type: "success"
+            });
+            this.allotAllDialog = false;
+          },
+          () => {
+            this.$notify({
+              message: "试卷整体分配失败!",
+              type: "error"
+            });
+          }
+        );
+      });
     },
-    openExportDialog() {
+    openExportDialog(row) {
       /* 打开批量导出弹窗 */
       this.exportDialog = true;
+      this.exportForm.ids = [];
+      if (row.id) {
+        this.exportForm.ids.push(row.id);
+      }
     },
     closeExportDialog() {
       /* 关闭批量导出弹窗 */
@@ -584,6 +770,49 @@ export default {
     },
     doExport() {
       /* 批量导出 */
+      let ids = [];
+      if (this.exportForm.ids.length > 0) {
+        ids = this.exportForm.ids;
+      } else {
+        if (this.selectElements.length == 0) {
+          this.$notify({
+            message: "请选择要导出的项!",
+            type: "warning"
+          });
+          return;
+        }
+
+        this.selectElements.forEach(element => {
+          if (element.paperStatus > 1) {
+            ids.push(element.id);
+          }
+        });
+      }
+
+      this.$refs.exportForm.validate(valid => {
+        if (!valid) {
+          return false;
+        }
+
+        if (ids.length == 0) {
+          this.$notify({
+            message: "包含未被指定试卷的课程则不可导出!",
+            type: "warning"
+          });
+          return;
+        }
+
+        this.closeExportDialog();
+        let url =
+          PRINT_API +
+          "/course/paper/export/batch?ids=" +
+          ids.join(",") +
+          "&types=" +
+          this.exportForm.types.join(",");
+
+        //console.log(url);
+        window.location.href = url;
+      });
     },
     openExportAllDialog() {
       /* 打开整体导出弹窗 */
@@ -595,94 +824,43 @@ export default {
     },
     doExportAll() {
       /* 整体导出 */
+      this.$refs.exportAllForm.validate(valid => {
+        if (!valid) {
+          return false;
+        }
+        this.closeExportAllDialog();
+        let url =
+          PRINT_API +
+          "/course/paper/export/all?orgId=" +
+          this.exportAllForm.orgId +
+          "&examId=" +
+          this.exportAllForm.examId +
+          "&types=" +
+          this.exportAllForm.types.join(",");
+
+        //console.log(url);
+        window.location.href = url;
+      });
     },
-    handlePager(current) {
-      /* 处理分页 */
-      this.formSearch.pageNo = current;
-      this.searchRecords();
-    },
-    searchRecords() {
-      /* 查询记录列表 */
-      let orgId = this.formSearch.orgId;
-      if (this.isEmptyNumber(orgId)) {
-        this.$notify({
-          message: "请选择学校!",
-          type: "warning"
-        });
-        return;
-      }
-
-      let examId = this.formSearch.examId;
-      if (this.isEmptyNumber(examId)) {
-        this.$notify({
-          message: "请选择考试!",
-          type: "warning"
-        });
-        return;
-      }
-
-      this.loading = true;
-      let url = PRINT_API + "/course/statistic/list";
-      this.$http.post(url, this.formSearch).then(
+    searchExamCoursePaperTotal() {
+      /* 查询考试的试卷数量情况 */
+      let url =
+        PRINT_API +
+        "/course/paper/total/" +
+        this.exportAllForm.orgId +
+        "/" +
+        this.exportAllForm.examId;
+      this.$http.post(url).then(
         response => {
-          this.tableData = response.data.content;
-          this.totalElements = response.data.totalElements;
-          this.loading = false;
+          let data = response.data;
+          this.exportAllForm.allNum = data.allNum;
+          this.exportAllForm.existNum = data.existNum;
+          this.exportAllForm.missNum = data.missNum;
         },
         error => {
           console.log(error);
-          this.loading = false;
         }
       );
-    },
-    searchExamList(orgId) {
-      /* 查询考试列表 */
-      this.formSearch.examId = "";
-      this.examList = [];
-      this.tableData = [];
-
-      if (!this.isEmptyNumber(orgId)) {
-        let url = PRINT_API + "/printing/project/exam/list?orgId=" + orgId;
-        this.$http.post(url).then(response => {
-          this.examList = response.data;
-        });
-      }
-    },
-    searchCourseList(query) {
-      /* 查询课程列表 */
-      this.courseList = [];
-      let url = CORE_API + "/course/query?enable=true";
-
-      if (!this.isEmptyStr(query)) {
-        url += "&name=" + query;
-      }
-
-      this.$http.get(url).then(response => {
-        this.courseList = response.data;
-      });
-    },
-    refreshStatistic() {
-      /* 刷新当前统计信息 */
-      this.$notify({
-        message: "Todo...",
-        type: "warning"
-      });
-    },
-    preview(row) {
-      /* 预览试卷PDF */
-      console.log(row);
-      this.$notify({
-        message: "Todo...",
-        type: "warning"
-      });
-    },
-    download(row) {
-      /* 下载试卷结构 */
-      console.log(row);
-      this.$notify({
-        message: "Todo...",
-        type: "warning"
-      });
     }
   },
   computed: {