liusheng
4 天以前 bbbc478129f72b26e2ec4a2e981ed8698a96880c
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
@@ -407,6 +417,12 @@
      // 后端私钥
      privateKey:
        " MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAtDOpbUQhcEoYy77agRhIHmAzs7H+KHJhN56gTTI9fWq23j77nI055MFV3oQQziIrNUTNaPpEQhZXBpI0+f9K9QIDAQABAkB3n0fcWfrcoMN/FU3VnrnZOEF6CzFNxkgU9P8y36QECWKZ9JhYQkNpKrMC9oXlN3VSaRigV7B+L/I/a0Rs1W+tAiEA4jx7xcXJ4y4BNwAmVHt6NNiEkzIwWnwC/0qsEu8NsOsCIQDL6MMn1D2uznC6OuOWpxDCkBh1JL1NzZTZeH2G+hj7nwIgKGAC9tjFnvWm4dn0/T7MIIJDpsFeP8fCAS2iZ/6hwuECIAS/eLvWr1EAsZNEh8QcQ8GkBU3E+ztyjAK8UX/xFt/VAiBf79/1tDErX4/DChecM8w3c3DhbBcjuE3fHZn7p6/UKg==",
      // 满意度/廉洁题的默认选项(仅在题目未填写时生效)
      defaultAnswers: [
        { keyword: "您对医护人员的满意度为", answer: "优" },
        { keyword: "您对医院环境、设施等整体的满意度为", answer: "优" },
        { keyword: "是否有医护人员主动索要红包、锦旗或表扬信", answer: "无" },
      ],
      formData: {
        question1: "",
        question2: "",
@@ -601,6 +617,8 @@
                  item.scriptResult = item.scriptResult.split("&");
                }
              });
              // 默认勾选满意度/廉洁题(已作答的不会被覆盖)
              this.applyDefaultAnswers(this.questionList);
              this.loading = false;
              return;
@@ -634,12 +652,40 @@
                item.scriptResult = [];
              }
            });
            // 默认勾选满意度/廉洁题
            this.applyDefaultAnswers(this.questionList);
            this.loading = false;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 给指定题目设置默认选项(仅在未填写时生效)
    applyDefaultAnswers(list) {
      if (!Array.isArray(list)) return;
      list.forEach((item) => {
        if (item.scriptType != 1) return;
        // 已有答案时不覆盖
        if (
          item.scriptResult !== undefined &&
          item.scriptResult !== null &&
          item.scriptResult !== ""
        ) {
          return;
        }
        const content = (item.scriptContent || "").trim();
        const matched = this.defaultAnswers.find((d) =>
          content.includes(d.keyword)
        );
        if (!matched) return;
        const option = (item.svyTaskTemplateTargetoptions || []).find(
          (o) => (o.optioncontent || "").trim() === matched.answer
        );
        if (option) {
          item.scriptResult = option.optioncontent;
        }
      });
    },
    // 加密函数
    encrypt(txt) {
@@ -695,6 +741,10 @@
    // 缓存
    cache(subm) {
      console.log("进入缓存");
      // 提交场景:先做必填项校验
      if (subm === true && !this.validateRequired()) {
        return;
      }
      // 提交场景:开启加载状态,防止重复点击
      if (subm === true) {
        this.submitting = true;
@@ -764,6 +814,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;
    },
    // 获取可见题目的正确序号(解决跳题后序号不连续的问题)
    getVisibleQuestionIndex(index) {
@@ -1041,6 +1131,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 +1170,12 @@
  min-width: 16px;
}
.required-star {
  color: #f56c6c;
  margin-right: 2px;
  font-weight: 600;
}
// .question-text {
//   line-height: 1.5;
//   color: #2c3e50;