From e9f35f9782f3d99d742c294fe503fc1294f203c4 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期一, 14 九月 2026 11:10:31 +0800
Subject: [PATCH] 测试完成

---
 src/views/outsideChainwtnew.vue |   70 ++++++++++++++++++++++++++++++++++-
 1 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/src/views/outsideChainwtnew.vue b/src/views/outsideChainwtnew.vue
index 5dd3cb3..f37bec9 100644
--- a/src/views/outsideChainwtnew.vue
+++ b/src/views/outsideChainwtnew.vue
@@ -64,6 +64,7 @@
                       item.prompt &&
                       item.scriptResult &&
                       (item.scriptType !== 2 || item.scriptResult.length > 0),
+                    'required-error': item.requiredError,
                   }"
                 >
                   <!-- 棰樼洰棰樺共 -->
@@ -71,7 +72,11 @@
                     <span class="question-number"
                       >{{ getQuestionNumber(group, index) }}.</span
                     >
-                    <span class="question-text">{{ item.scriptContent }}</span>
+                    <span class="question-text"
+                      ><span v-if="isRequired(item)" class="required-star"
+                        >*</span
+                      >{{ item.scriptContent }}</span
+                    >
                     <span class="question-type-tag">
                       {{
                         item.scriptType == 1
@@ -201,6 +206,7 @@
                   item.prompt &&
                   item.scriptResult &&
                   (item.scriptType !== 2 || item.scriptResult.length > 0),
+                'required-error': item.requiredError,
               }"
             >
               <!-- 棰樼洰棰樺共 -->
@@ -208,7 +214,11 @@
                 <span class="question-number"
                   >{{ getVisibleQuestionIndex(index) }}.</span
                 >
-                <span class="question-text">{{ item.scriptContent }}</span>
+                <span class="question-text"
+                  ><span v-if="isRequired(item)" class="required-star"
+                    >*</span
+                  >{{ item.scriptContent }}</span
+                >
                 <span class="question-type-tag">
                   {{
                     item.scriptType == 1
@@ -695,6 +705,10 @@
     // 缂撳瓨
     cache(subm) {
       console.log("杩涘叆缂撳瓨");
+      // 鎻愪氦鍦烘櫙锛氬厛鍋氬繀濉」鏍¢獙
+      if (subm === true && !this.validateRequired()) {
+        return;
+      }
       // 鎻愪氦鍦烘櫙锛氬紑鍚姞杞界姸鎬侊紝闃叉閲嶅鐐瑰嚮
       if (subm === true) {
         this.submitting = true;
@@ -764,6 +778,46 @@
             this.$modal.msgError("鎻愪氦澶辫触锛岃閲嶈瘯");
           }
         });
+    },
+    // 鏄惁蹇呭~锛�1蹇呭~ 2涓嶅繀濉級
+    isRequired(item) {
+      return item.ismandatory == 1 || item.ismandatory == "1";
+    },
+    // 鍒ゆ柇棰樼洰鏄惁鏈~鍐�
+    isQuestionEmpty(item) {
+      const val = item.scriptResult;
+      if (item.scriptType == 2) {
+        return !val || (Array.isArray(val) && val.length === 0);
+      }
+      return val === undefined || val === null || val === "";
+    },
+    // 淇濆瓨鍓嶅繀濉」鏍¢獙
+    validateRequired() {
+      const list = this.questionList || [];
+      list.forEach((item) => {
+        if (item.requiredError) this.$set(item, "requiredError", false);
+      });
+      const unfilled = [];
+      list.forEach((item) => {
+        if (item.ishide) return;
+        if (!this.isRequired(item)) return;
+        if (this.isQuestionEmpty(item)) unfilled.push(item);
+      });
+      if (unfilled.length > 0) {
+        unfilled.forEach((item) => this.$set(item, "requiredError", true));
+        this.$modal.msgWarning(
+          `杩樻湁 ${unfilled.length} 閬撳繀濉鏈~鍐欙紝璇疯ˉ鍏呭悗鍐嶆彁浜
+        );
+        this.$nextTick(() => {
+          const idx = this.visibleQuestions.indexOf(unfilled[0]);
+          const els = this.$el.querySelectorAll(".question-item");
+          if (els[idx]) {
+            els[idx].scrollIntoView({ behavior: "smooth", block: "center" });
+          }
+        });
+        return false;
+      }
+      return true;
     },
     // 鑾峰彇鍙棰樼洰鐨勬纭簭鍙凤紙瑙e喅璺抽鍚庡簭鍙蜂笉杩炵画鐨勯棶棰橈級
     getVisibleQuestionIndex(index) {
@@ -1041,6 +1095,12 @@
     border-left: 4px solid #e6a23c;
   }
 
+  &.required-error {
+    border-color: #f56c6c;
+    border-left: 4px solid #f56c6c;
+    background: #fef0f0;
+  }
+
   &:last-child {
     margin-bottom: 0;
   }
@@ -1074,6 +1134,12 @@
   min-width: 16px;
 }
 
+.required-star {
+  color: #f56c6c;
+  margin-right: 2px;
+  font-weight: 600;
+}
+
 // .question-text {
 //   line-height: 1.5;
 //   color: #2c3e50;

--
Gitblit v1.9.3