From 2088fc58f63e6d72e48ae3fd5da5fa27d12bc0a5 Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期五, 01 十一月 2024 13:59:30 +0800
Subject: [PATCH] 优化手机号、座机号验证

---
 src/views/exam/paper/edit.vue |  131 +++++++++++++++++++++++++++++--------------
 1 files changed, 89 insertions(+), 42 deletions(-)

diff --git a/src/views/exam/paper/edit.vue b/src/views/exam/paper/edit.vue
index 53411d1..d9b6041 100644
--- a/src/views/exam/paper/edit.vue
+++ b/src/views/exam/paper/edit.vue
@@ -1,21 +1,16 @@
 <template>
   <div class="app-container">
     <el-form :model="form" ref="form" label-width="150px" v-loading="formLoading" :rules="rules">
-      <el-form-item label="瀛︾锛�" prop="subjectId" required>
-        <el-select v-model="form.subjectId" placeholder="瀛︾">
-          <el-option v-for="item in subjects" :key="item.id" :label="item.name" :value="item.id"/>
-        </el-select>
-      </el-form-item>
-      <el-form-item label="璇曞嵎绫诲瀷锛�" prop="paperType" required>
+      <el-form-item label="璇曞嵎绫诲瀷锛�" prop="paperType">
         <el-select v-model="form.paperType" placeholder="璇曞嵎绫诲瀷">
           <el-option v-for="item in paperTypeEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
         </el-select>
       </el-form-item>
-      <el-form-item label="璇曞嵎鍚嶇О锛�" prop="name" required>
+      <el-form-item label="璇曞嵎鍚嶇О锛�" prop="name">
         <el-input style="width: 300px" v-model="form.name"/>
       </el-form-item>
       <!-- 棰樼洰璇︾粏淇℃伅 -->
-      <el-form-item :key="index" :label="'鏍囬'+(index+1)+'锛�'" required
+      <el-form-item :key="index" :label="'鏍囬'+(index+1)+'锛�'"
                     v-for="(titleItem,index) in form.questionTitleList"
                     v-show="form.paperType===1 || (form.paperType ===3 && form.id)">
         <el-input v-model="titleItem.title" style="width: 50%"/>
@@ -68,7 +63,7 @@
                            v-show="form.deductType === 2 || form.deductType === 3" :min="0"/>
         </div>
       </el-form-item>
-      <el-form-item label="寤鸿鏃堕暱(鍒嗛挓)锛�" prop="suggestTime" required>
+      <el-form-item label="寤鸿鏃堕暱(鍒嗛挓)锛�" prop="suggestTime">
         <el-input-number v-model="form.suggestTime" placeholder="鍒嗛挓" :min="0"/>
       </el-form-item>
       <el-form-item label="鏉冮檺锛�" prop="visibility">
@@ -77,23 +72,26 @@
       </el-form-item>
       <!-- 棰樼洰閰嶇疆淇℃伅 闅忔満璇曞嵎鎴栨柊寤洪殢搴忔墠鏄剧ず -->
       <el-form-item v-show="form.paperType ===2 || (form.paperType ===3 && !form.id)" :key="index"
-                    :label="translateQuestionType(item.questionType)+'锛�'" v-for="(item,index) in form.questionSetting">
+                    :label="translateQuestionType(item.questionType)+'锛�'" v-for="(item,index) in form.questionSetting"
+      >
         <div>
           <span style="margin-right: 10px">{{ '鏍囬' }}</span>
           <el-input v-model="item.title" style="margin-bottom: 20px;margin-right: 30px;width: 800px"/>
-          <el-button type="primary" @click=addToQuestionSetting(item.questionType) >娣诲姞</el-button>
+          <el-button type="primary" @click=addToQuestionSetting(item.questionType)>娣诲姞</el-button>
 
-          <div style="display: flex;" :key="index" v-for="(setting,index) in item.settingList">
-            <span style="margin-right: 10px;margin-bottom: 10px;">{{ '闅惧害' }}</span>
+          <div style="display: flex;margin-bottom: 10px;" :key="index" v-for="(setting,index) in item.settingList">
+            <span style="margin-right: 10px;">{{ '闅惧害' }}</span>
             <el-rate v-model="setting.difficult" :precision="0" :min="0" style="margin-right: 25px;padding: 5px 0"/>
             <span style="margin-right: 10px">{{ '绉戠洰' }}</span>
-            <el-select v-model="setting.subjectId" placeholder="瀛︾" style="margin-right: 25px">
+            <el-select v-model="setting.subjectId" placeholder="瀛︾" clearable style="margin-right: 25px">
               <el-option v-for="item in subjects" :key="item.id" :label="item.name" :value="item.id"/>
             </el-select>
             <span style="margin-right: 10px">{{ '鏁伴噺' }}</span>
             <el-input-number v-model="setting.num" :precision="0" :min="0" style="margin-right: 25px"/>
             <span style="margin-right: 10px">{{ '姣忛鍒嗘暟' }}</span>
-            <el-input-number v-model="setting.score" :min="0" :precision="1"/>
+            <el-input-number v-model="setting.score" :min="0" :precision="1" style="margin-right: 25px"/>
+            <el-button type="danger" icon="el-icon-delete" circle
+                       @click="removeQuestionSetting(item,index)"></el-button>
           </div>
 
         </div>
@@ -125,10 +123,15 @@
       </el-form-item>
     </el-form>
 
-    <el-dialog :visible.sync="questionPage.showDialog" width="70%">
+    <el-dialog :visible.sync="questionPage.showDialog" width="70%" :close-on-click-modal="false">
       <el-form :model="questionPage.queryParam" ref="queryForm" :inline="true">
-        <el-form-item label="ID锛�">
-          <el-input v-model="questionPage.queryParam.id" clearable></el-input>
+        <el-form-item label="棰樺共锛�">
+          <el-input v-model="questionPage.queryParam.content" @input="queryForm"></el-input>
+        </el-form-item>
+        <el-form-item label="瀛︾锛�">
+          <el-select v-model="questionPage.queryParam.subjectIdInt" placeholder="瀛︾" @change="queryForm" clearable>
+            <el-option v-for="item in subjects" :key="item.id" :label="item.name" :value="item.id"/>
+          </el-select>
         </el-form-item>
         <el-form-item>
           <el-button type="primary" @click="queryForm">鏌ヨ</el-button>
@@ -171,7 +174,6 @@
     return {
       form: {
         id: null,
-        subjectId: null,
         paperType: 1,
         name: '',
         num: 0,
@@ -243,12 +245,6 @@
       subjects: [],
       formLoading: false,
       rules: {
-        level: [
-          { required: true, message: '璇烽�夋嫨骞寸骇', trigger: 'change' }
-        ],
-        subjectId: [
-          { required: true, message: '璇烽�夋嫨瀛︾', trigger: 'change' }
-        ],
         paperType: [
           { required: true, message: '璇烽�夋嫨璇曞嵎绫诲瀷', trigger: 'change' }
         ],
@@ -264,6 +260,7 @@
         showDialog: false,
         queryParam: {
           id: null,
+          subjectIdInt: null,
           questionType: [],
           subjectId: [],
           pageIndex: 1,
@@ -386,6 +383,14 @@
     addQuestion (titleItem) {
       this.currentTitleItem = titleItem
       this.questionPage.queryParam.questionType = []
+      this.questionPage.queryParam.status = 1
+      if (!titleItem.questionType) {
+        this.$message({
+          message: '璇峰厛閫夋嫨棰樺瀷',
+          type: 'warning'
+        })
+        return
+      }
       this.questionPage.queryParam.questionType.push(titleItem.questionType)
       this.questionPage.showDialog = true
       this.search()
@@ -405,9 +410,17 @@
       this.updateTotalScore()
       this.form.num = this.form.num - 1
     },
+    removeQuestionSetting (item, index) {
+      item.settingList.splice(index, 1)
+    },
     queryForm () {
       this.questionPage.queryParam.pageIndex = 1
-      this.search()
+      if (!this.questionPage.queryParam.subjectIdInt){
+        this.search()
+      }else{
+        this.questionPage.queryParam.subjectId = [this.questionPage.queryParam.subjectIdInt]
+        this.search()
+      }
     },
     confirmQuestionSelect () {
       let _this = this
@@ -420,8 +433,6 @@
       this.questionPage.showDialog = false
     },
     search () {
-      this.questionPage.queryParam.subjectId = []
-      this.questionPage.queryParam.subjectId.push(this.form.subjectId)
       this.questionPage.listLoading = true
       questionApi.pageList(this.questionPage.queryParam).then(data => {
         const re = data.data
@@ -448,14 +459,46 @@
         deductTypeScore: 0,
         visibility: '1',
         questionSetting: [
-          { questionType: 1, title: '鍗曢�夐', score: null, num: null },
-          { questionType: 2, title: '澶氶�夐', score: null, num: null },
-          { questionType: 3, title: '鍒ゆ柇棰�', score: null, num: null },
-          { questionType: 4, title: '濉┖棰�', score: null, num: null },
-          { questionType: 5, title: '绠�绛旈', score: null, num: null },
-          { questionType: 6, title: '璇煶棰�', score: null, num: null },
-          { questionType: 7, title: '璁$畻棰�', score: null, num: null },
-          { questionType: 8, title: '鍒嗘瀽棰�', score: null, num: null },
+          {
+            title: '鍗曢�夐',
+            questionType: 1,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          },
+          {
+            title: '澶氶�夐',
+            questionType: 2,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          },
+          {
+            title: '鍒ゆ柇棰�',
+            questionType: 3,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          },
+          {
+            title: '濉┖棰�',
+            questionType: 4,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          },
+          {
+            title: '绠�绛旈',
+            questionType: 5,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          },
+          {
+            title: '璇煶棰�',
+            questionType: 6,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          },
+          {
+            title: '璁$畻棰�',
+            questionType: 7,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          },
+          {
+            title: '鍒嗘瀽棰�',
+            questionType: 8,
+            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
+          }
         ],
         questionTitleList: []
       }
@@ -470,8 +513,10 @@
     totalNum () {
       if (this.form.paperType === 2 || this.form.paperType === 3) {
         let total = 0
-        for (let item of this.form.questionSetting) {
-          total += parseInt(item.num || 0, 10)
+        for (let settings of this.form.questionSetting) {
+          for (let item of settings.settingList) {
+            total += parseInt(item.num || 0, 10)
+          }
         }
         this.form.num = total
         return total
@@ -482,10 +527,12 @@
     totalScore () {
       if (this.form.paperType === 2 || this.form.paperType === 3) {
         let total = 0
-        for (let item of this.form.questionSetting) {
-          const num = parseInt(item.num || 0, 10)
-          const score = parseFloat(item.score || 0)
-          total += num * score
+        for (let settings of this.form.questionSetting) {
+          for (let item of settings.settingList) {
+            const num = parseInt(item.num || 0, 10)
+            const score = parseFloat(item.score || 0)
+            total += num * score
+          }
         }
         this.form.score = total.toFixed(1)
         return total.toFixed(1) // 淇濈暀涓�浣嶅皬鏁�

--
Gitblit v1.8.0