WXL
2024-09-04 7eaee92ee52e1501480adbbe8a1af9ddecc04275
src/views/knowledge/questionnaire/compilequer/index.vue
@@ -198,37 +198,56 @@
            </el-select>
          </el-form-item>
          <el-form-item label="适用院区" prop="region">
            <el-select
              v-model="ruleForm.campus"
              size="medium"
              filterable
              placeholder="请选择分类"
          <el-row>
            <el-col :span="10"
              ><el-form-item label="适用院区" prop="region">
                <el-select
                  v-model="ruleForm.campus"
                  size="medium"
                  filterable
                  placeholder="请选择分类"
                >
                  <el-option
                    class="ruleFormaa"
                    v-for="item in courtyardlist"
                    :key="item.label"
                    :label="item.label"
                    :value="item.label"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item label="适用科室" prop="region">
                <el-cascader
                style="width: 400px;"
                  v-model="tempDetpRelevanceslist"
                  :options="deptList"
                  :props="props"
                  :show-all-levels="false"
                  clearable
                >
                  <template slot-scope="{ node, data }">
                    <span>{{ data.deptName }}</span>
                    <span v-if="!node.isLeaf">
                      ({{ data.children.length }})
                    </span>
                  </template>
                </el-cascader>
              </el-form-item></el-col
            >
              <el-option
                class="ruleFormaa"
                v-for="item in courtyardlist"
                :key="item.label"
                :label="item.label"
                :value="item.label"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="适用科室" prop="region">
            <el-cascader
              v-model="tempDetpRelevanceslist"
              :options="deptList"
              :props="props"
              :show-all-levels="false"
              clearable
          </el-row>
          <el-form-item label="问卷结束语">
            <el-input
              style="width: 40vw"
              type="textarea"
              autosize
              placeholder="请输入内容"
              v-model="ruleForm.conclusion"
            >
              <template slot-scope="{ node, data }">
                <span>{{ data.deptName }}</span>
                <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
              </template>
            </el-cascader>
          </el-form-item>
            </el-input
          ></el-form-item>
          <el-form-item>
            <el-button type="success" @click="nextstep('ruleForm')"
              >下一步</el-button
@@ -242,7 +261,18 @@
      </div>
      <!-- 问卷设置 -->
      <div v-if="Editprogress == 2">
        <div class="leftvlue-jbxx">问卷题目设置</div>
        <div class="leftvlue-jbxx">
          问卷题目设置
          <span style=""
            ><el-button
              type="warning"
              icon="el-icon-finished"
              round
              @click="test"
              >题目规则效验</el-button
            ></span
          >
        </div>
        <el-divider></el-divider>
        <div style="display: flex; justify-content: space-between">
          <div>
@@ -349,7 +379,15 @@
                  key="nextScriptno"
                  prop="nextScriptno"
                  :show-overflow-tooltip="true"
                />
                >
                  <template slot-scope="scope">
                    <span>{{
                      scope.row.nextScriptno == 0
                        ? "已是最后一题"
                        : scope.row.nextScriptno
                    }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  v-if="Operateit"
@@ -405,7 +443,7 @@
                      ></el-input> </el-form-item
                  ></el-col>
                  <el-col :span="12">
                    <el-form-item label="下题跳转" v-if="!topicobj.branchFlag">
                    <el-form-item label="下题跳转">
                      <el-input
                        v-model="topicobj.nextScriptno"
                        placeholder="请输入题号"
@@ -433,12 +471,16 @@
                        </el-option> </el-select></el-form-item
                  ></el-col>
                  <el-col :span="12">
                    <el-form-item label="题目分数">
                    <el-form-item
                      label="题目分值"
                      v-if="topicobj.scoretype == 1"
                    >
                      <el-input
                        v-model="topicobj.scriptTopic"
                        placeholder="请输入标题"
                      ></el-input> </el-form-item
                  ></el-col>
                        v-model="topicobj.score"
                        placeholder="请输入题号"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
@@ -465,25 +507,25 @@
                    </el-form-item></el-col
                  >
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item
                      label="题目分值"
                      v-if="topicobj.scoretype == 1"
                    >
                      <el-input
                        v-model="topicobj.score"
                        placeholder="请输入题号"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="是否由选项配置跳转">
                <el-form-item
                  label="是否由选项配置跳转"
                  v-if="topicobj.scriptType == 1"
                >
                  <el-radio-group v-model="topicobj.branchFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="0">否</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="选中提示" v-if="topicobj.scriptType != 1">
                  <el-input
                    style="width: 24vw"
                    type="textarea"
                    autosize
                    placeholder="请输入内容"
                    v-model="topicobj.prompt"
                  >
                  </el-input
                ></el-form-item>
                <div
                  v-if="topicobj.scriptType == 1 || topicobj.scriptType == 2"
                >
@@ -506,7 +548,7 @@
                      <el-col :span="8">
                        <el-form-item
                          v-if="topicobj.scoretype == 1"
                          label="分值"
                          label="选项分值"
                        >
                          <el-input
                            class="custom-width"
@@ -539,11 +581,12 @@
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="10">
                    <el-row :gutter="10" v-if="topicobj.branchFlag == 1">
                      <el-col :span="20"
                        ><el-form-item label="下题跳转(序号)">
                          <el-input
                            type="text"
                            @blur="branchFlagfn"
                            placeholder="请输入题号"
                            v-model="item.nextQuestion"
                            show-word-limit
@@ -551,10 +594,10 @@
                          </el-input> </el-form-item
                      ></el-col>
                    </el-row>
                    <el-row :gutter="10">
                    <el-row :gutter="10" v-if="topicobj.scriptType == 1">
                      <el-form-item label="选中提示">
                        <el-input
                          style="width: 20vw"
                          style="width: 24vw"
                          type="textarea"
                          autosize
                          placeholder="请输入内容"
@@ -635,62 +678,61 @@
        <div class="leftvlue-jbxx">问卷预览</div>
        <el-divider></el-divider>
        <div class="preview-left">
          <!-- 单选 -->
          <div
            class="scriptTopic-dev"
            v-for="item in ruleForm.svyTemplateLibScripts"
            :key="item.sort"
            v-if="item.scriptType == 1"
          >
            <div class="dev-text">
              {{ item.sort }}、[单选]<span>{{ item.scriptContent }}</span>
          <div v-for="item in ruleForm.svyTemplateLibScripts">
            <!-- 单选 -->
            <div
              class="scriptTopic-dev"
              :key="item.sort"
              v-if="item.scriptType == 1"
            >
              <div class="dev-text">
                {{ item.sort }}、[单选]<span>{{ item.scriptContent }}</span>
              </div>
              <div class="dev-xx">
                <el-radio-group v-model="item.remark">
                  <el-radio
                    v-for="(items, index) in item.svyLibTemplateTargetoptions"
                    :key="index"
                    :label="index"
                    >{{ items.optioncontent }}</el-radio
                  >
                </el-radio-group>
              </div>
            </div>
            <div class="dev-xx">
              <el-radio-group v-model="item.remark">
                <el-radio
                  v-for="(items, index) in item.svyLibTemplateTargetoptions"
                  :key="index"
                  :label="index"
                  >{{ items.optioncontent }}</el-radio
                >
              </el-radio-group>
            <!-- 多选 -->
            <div
              class="scriptTopic-dev"
              :key="item.sort"
              v-if="item.scriptType == 2"
            >
              <div class="dev-text">
                {{ item.sort }}、[多选]<span>{{ item.scriptContent }}</span>
              </div>
              <div class="dev-xx">
                <el-checkbox-group v-model="qremark">
                  <el-checkbox
                    v-for="(items, index) in item.svyLibTemplateTargetoptions"
                    :key="index"
                    :label="index"
                  >
                    {{ items.optioncontent }}
                  </el-checkbox>
                </el-checkbox-group>
              </div>
            </div>
          </div>
          <!-- 多选 -->
          <div
            class="scriptTopic-dev"
            v-for="item in ruleForm.svyTemplateLibScripts"
            :key="item.sort"
            v-if="item.scriptType == 2"
          >
            <div class="dev-text">
              {{ item.sort }}、[多选]<span>{{ item.scriptContent }}</span>
            </div>
            <div class="dev-xx">
              <el-checkbox-group v-model="qremark">
                <el-checkbox
                  v-for="(items, index) in item.svyLibTemplateTargetoptions"
                  :key="index"
                  :label="index"
                >
                  {{ items.optioncontent }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </div>
          <!-- 填空 -->
          <div
            class="scriptTopic-dev"
            v-for="item in ruleForm.svyTemplateLibScripts"
            :key="item.sort"
            v-if="item.scriptType == 3"
          >
            <div class="dev-text">
              {{ item.sort }}、[填空]<span>{{ item.scriptContent }}</span>
            </div>
            <div class="dev-xx">
              <el-input placeholder="请输入答案" v-model="radioas" clearable>
              </el-input>
            <!-- 填空 -->
            <div
              class="scriptTopic-dev"
              :key="item.sort"
              v-if="item.scriptType == 4"
            >
              <div class="dev-text">
                {{ item.sort }}、[填空]<span>{{ item.scriptContent }}</span>
              </div>
              <div class="dev-xx">
                <el-input placeholder="请输入答案" v-model="radioas" clearable>
                </el-input>
              </div>
            </div>
          </div>
        </div>
@@ -1056,7 +1098,7 @@
                        </el-radio-group>
                      </el-form-item>
                    </el-row>
                    <el-row :gutter="10">
                    <el-row :gutter="10" v-if="item.scriptType == 1">
                      <el-form-item label="选中提示">
                        <el-input
                          style="width: 400px"
@@ -1136,7 +1178,7 @@
import { getToken } from "@/utils/auth";
export default {
  name: "Qcompilequer",
  name: "Questionnaireinfo",
  components: { OptionalForm },
@@ -1263,10 +1305,29 @@
      ],
    };
  },
  activated() {
    console.log(this.id);
    if (this.id != this.$route.query.id) {
      this.getissueinfo();
      this.gettabList();
    } else {
      this.ruleForm.svyTemplateLibScripts =
        this.ruleForm.svyTemplateLibScripts.filter(
          (item) => item.isoperation != 3
        );
      this.ruleForm.svyLibTemplateTagList =
        this.ruleForm.svyLibTemplateTagList.filter(
          (item) => item.isoperation != 3
        );
      this.delScriptVOList = [];
      this.$forceUpdate();
      console.log(this.ruleForm.svyTemplateLibScripts);
    }
  },
  created() {
    this.gettabList();
    this.getissueinfo();
    this.gettabList();
    this.mode = store.getters.Askmode;
    this.languagelist = store.getters.languagelist;
    this.usable = store.getters.usable;
@@ -1319,6 +1380,13 @@
    // 获取数据
    getissueinfo() {
      this.id = this.$route.query.id;
      this.ruleForm = {
        svyTemplateLibScripts: [],
        tempDetpRelevances: [],
        svyLibTemplateTagList: [],
      };
      this.topicobj = {};
      if (this.id) {
        getQtemplateobj({ svyid: this.id }).then((res) => {
          this.ruleForm = res.rows[0];
@@ -1347,9 +1415,13 @@
      });
    },
    submitForm(formName) {
      this.$modal.loading("正在上传数据,请稍候...");
      this.ruleForm.suitway = this.ruleForm.suitway.join(",");
      this.$modal.loading("正在修正保存数据,请稍候...");
      if (this.ruleForm.suitway) {
        this.ruleForm.suitway = this.ruleForm.suitway.join(",");
      }
      if (!this.ruleForm.categoryid) {
        this.ruleForm.categoryid = -1;
      }
      if (this.id) {
        this.ruleForm.isoperation = 2;
        compileQtemplate(this.ruleForm).then((res) => {
@@ -1360,7 +1432,9 @@
        });
      } else {
        this.ruleForm.isoperation = 1;
        this.ruleForm.version = this.ruleForm.version ? ruleForm : "1.0";
        this.ruleForm.version = this.ruleForm.version
          ? this.ruleForm.version
          : "1.0";
        compileQtemplate(this.ruleForm).then((res) => {
          this.$modal.msgSuccess("新增成功");
          this.confirmillness(res.data);
@@ -1443,7 +1517,6 @@
    // 新增题目
    addtopic(row) {
      row.isoperation = 1;
      console.log(row, "row");
      row.svyLibScriptOptions.forEach((item) => {
        item.isoperation = 1;
      });
@@ -1462,7 +1535,6 @@
    handleUpdate(row) {
      this.topicobj = row;
      this.radioas = "";
      console.log(this.topicobj, "看数据");
      // getissuelist({ svyid: row.svyid }).then((res) => {
      // });
    },
@@ -1485,13 +1557,10 @@
      this.sortFn();
    },
    sortFn() {
      console.log(this.ruleForm.svyTemplateLibScripts, "序前值");
      this.ruleForm.svyTemplateLibScripts.forEach((item, index) => {
        item.sort = Number(index) + 1;
        console.log(this.ruleForm.svyTemplateLibScripts.length, "length");
        if (item.sort == this.ruleForm.svyTemplateLibScripts.length) {
          item.nextScriptno = "已是最后一题";
          item.nextScriptno = 0;
        } else {
          item.nextScriptno = item.sort + 1;
        }
@@ -1520,7 +1589,7 @@
          this.drawer = false;
          this.sortFn();
          this.$modal.msgSuccess("题目新增成功,保存模版失效");
          this.$modal.msgSuccess("题目新增成功,保存模板失效");
        });
    },
    // 新增变量
@@ -1624,14 +1693,12 @@
      this.illnessVisible = false;
      this.$modal.msgSuccess("编辑成功");
    },
    // --------------------------
    resetQuery() {
      this.queryParams = { pageNum: 1, pageSize: 10 };
      this.getaddtopiclist();
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // --------------------------
    // 问卷分数限制算法
    // 混合路线
    generateCombinations(arrays, currentIndex = 0, currentCombination = []) {
@@ -1655,16 +1722,13 @@
    },
    // 执行
    test() {
      const arrays = [
        ["2", "3", "4", "5"],
        ["1", "2", "5", "6"],
        ["3", "4", "5", "3"],
        ["3", "2", "5", "7"],
      ];
      console.log(this.ruleForm.svyTemplateLibScripts);
      const arraysa = [
        {
          id: 1,
          grade: "5",
          Topicjump: "2",
          branchFlag: "0",
          arr: [
            { name: "不错", skip: 2 },
            { name: "一般", skip: 2 },
@@ -1675,86 +1739,220 @@
        {
          id: 2,
          grade: "5",
          Topicjump: "4",
          branchFlag: "1",
          arr: [
            { name: "优秀", skip: 3 },
            { name: "优秀", skip: 4 },
            { name: "良好", skip: 3 },
            { name: "一般", skip: 3 },
            { name: "较差", skip: 4 },
            { name: "较差", skip: 3 },
          ],
        },
        {
          id: 3,
          grade: "5",
          Topicjump: "4",
          branchFlag: "1",
          arr: [
            { name: "是的", skip: 4 },
            { name: "不清楚", skip: 4 },
            { name: "不清楚", skip: 5 },
            { name: "还可", skip: 4 },
            { name: "一般", skip: 4 },
          ],
        },
        {
          id: 4,
          grade: "5",
          Topicjump: "5",
          branchFlag: "0",
          bac: null,
        },
        {
          id: 5,
          Topicjump: "0",
          branchFlag: "0",
          arr: [
            { name: "真不错", skip: null },
            { name: "还可以", skip: null },
            { name: "一般般", skip: null },
            { name: "不清楚", skip: null },
            { name: "真不错", skip: 0 },
            { name: "还可以", skip: 0 },
            { name: "一般般", skip: 0 },
            { name: "不清楚", skip: 0 },
          ],
        },
      ];
      // const newMixArray = this.generateCombinations(arrays);
      const newMixArray = this.getExecutionOrders(arraysa);
      const csnewMixArray = this.csgetExecutionOrders(arraysa);
      console.log(csnewMixArray, "测试全部路线");
      const newMixArray = this.getExecutionOrders(
        this.ruleForm.svyTemplateLibScripts
      );
      console.log(newMixArray, "全部路线");
      this.screen(newMixArray);
      this.sumArray(newMixArray);
    },
    getExecutionOrders(data) {
      let orders = [];
    // 遍历方法
    csgetExecutionOrders(arrays) {
      const allPaths = [];
      const findPath = (currentId, path) => {
        const current = arrays.find((item) => item.id.toString() === currentId);
        if (!current) return;
        path.push(current);
      const explore = (currentOrder, id) => {
        console.log(currentOrder, "currentOrder", id);
        const currentQuestion = data[currentOrder[currentOrder.length - 1]];
        if (
          currentQuestion.arr.some(
            (option) =>
              option.skip !== null && !currentOrder.includes(option.skip)
          )
        ) {
          currentQuestion.arr.forEach((option) => {
            if (option.skip !== null && !currentOrder.includes(option.skip)) {
              explore([...currentOrder, option.skip]);
            }
        if (current.branchFlag === "1") {
          current.arr.forEach((option) => {
            findPath(option.skip.toString(), path.slice());
          });
        } else {
          orders.push(
            currentOrder.map((id) => ({
              id: data[id].id,
              grade: data[id].grade,
            }))
          );
          const nextId = parseInt(current.Topicjump);
          if (nextId !== 0) {
            findPath(nextId.toString(), path.slice());
          } else {
            allPaths.push(path.slice());
          }
        }
      };
      console.log(data, "data");
      data.forEach((entry) => {
        explore([entry.id], entry.id);
      });
      return orders;
      findPath("1", []);
      return allPaths;
    },
    // 遍历方法
    getExecutionOrders(arrays) {
      const allPaths = [];
      const findPath = (currentId, path) => {
        const current = arrays.find(
          (item) => item.sort.toString() === currentId
        );
        if (!current) return;
        path.push(current);
        if (current.branchFlag == "1") {
          current.svyLibTemplateTargetoptions.forEach((option) => {
            findPath(option.nextQuestion.toString(), path.slice());
          });
        } else {
          const nextId = parseInt(current.nextScriptno);
          if (nextId !== 0) {
            findPath(nextId.toString(), path.slice());
          } else {
            allPaths.push(path.slice());
          }
        }
      };
      findPath("1", []);
      return allPaths;
    },
    // 数组求和
    sumArray(arr) {
      return arr.reduce((acc, curr) => acc + parseInt(curr), 0);
    },
    // 筛选错误路线
    screen(data) {
      const arraysGreaterThan10 = data.filter((arr) => this.sumArray(arr) > 21);
      // const arrsum = arr;
      // arrsum.forEach((item) => {
      //   // 判断题目和模板层级
      //   console.log(item, "一条链路");
      console.log(arraysGreaterThan10, "筛选错误路线大于13分");
      //   const totalScore = item.reduce((accumulator, current) => {
      //     return accumulator + Number(current.score);
      //   }, 0);
      //   console.log(totalScore);
      //   console.log(this.ruleForm.scriptScore);
      //   if (totalScore == this.ruleForm.scriptScore) {
      //     this.ClaimNofn(arr);
      //     this.$modal.msgSuccess("分数核验成功");
      //   }
      // });
      const allGreaterThanTen = arr.every((array) => {
        const totalScore = array.reduce((accumulator, current) => {
          return accumulator + Number(current.score);
        }, 0);
        console.log(totalScore);
        console.log(this.ruleForm.scriptScore);
        return totalScore == this.ruleForm.scriptScore;
      });
      if (allGreaterThanTen) {
        this.$modal.msgSuccess("分值校验成功");
      } else {
        this.$modal.msgError("题目分值累加和模板分值不符");
      }
    },
    // 遍历是否重复是否都用上
    ClaimNofn(arr) {
      arr.forEach((item) => {
        const Aarr = item;
        const Barr = this.ruleForm.svyTemplateLibScripts;
        const notInB = A.filter(
          (itemA) => !B.some((itemB) => itemB.id === itemA.id)
        );
        if (notInB.length) {
          this.$modal.msgError("题目未全部使用");
        } else {
          this.$modal.msgSuccess("题目全部使用");
        }
      });
      arr.forEach((item) => {
        const idCount = arr.reduce((acc, item) => {
          acc[item.id] = (acc[item.id] || 0) + 1;
          return acc;
        }, {});
        const whether = item.values(idCount).some((count) => count > 1); // 如果有任何 id 的计数大于 1 就返回 true
        if (!whether) this.$modal.msgError("配置项有题目重复");
      });
    },
    // 题目和选项间的分值判断
    Scorejudgment() {
      let scorearr = this.topicobj.svyLibScriptOptions;
      let isValid = scorearr.every((score, index) => {
        if (this.topicobj.scriptType == 1) {
          if (score.score) {
            if (
              Number(score.score) < 0 ||
              Number(score.score) > Number(this.topicobj.score)
            ) {
              console.log(score, "错误分值");
              this.$message({
                message: "选项分值必须在0到" + this.topicobj.score + "分之间",
                type: "warning",
              });
              return false;
            }
            return true;
          } else {
            this.$message({
              message: "选项分值未设置",
              type: "warning",
            });
            return false;
          }
        } else if (this.topicobj.scriptType == 2) {
          // 累加分值
          const totalScore = scorearr.reduce((acc, score) => {
            if (score.score) {
              return acc + Number(score.score);
            }
            return acc; // 如果 score.score 不存在,不累加
          }, 0);
          // 检查累加的分值是否等于 this.topicobj.score
          if (totalScore !== Number(this.topicobj.score)) {
            this.$message({
              message:
                "多选题选项分值总和必须等于 " + this.topicobj.score + " 分",
              type: "warning",
            });
            return false;
          }
          return true; // 如果总分正确,返回 true
        } else if (this.topicobj.scriptType == 4) {
          return true;
        }
      });
      if (isValid) {
        this.compileissue();
      }
    },
    // ---------------------------------------------------------
    // 新问题新增
    addoption() {
      if (!this.indexform.svyLibTemplateTargetoptions) {
@@ -1781,6 +1979,13 @@
        this.$forceUpdate();
      } else {
        this.$message.error("图片插入失败");
      }
    },
    branchFlagfn(row) {
      console.log(row);
      if (this.topicobj.branchFlag == 1 && this.topicobj.nextScriptno != 0) {
        this.topicobj.nextScriptno =
          this.topicobj.svyLibTemplateTargetoptions[0].nextQuestion;
      }
    },
  },
@@ -1816,6 +2021,8 @@
    font-size: 20px;
  }
  .leftvlue-jbxx {
    display: flex; /* 使用 Flexbox 布局 */
    justify-content: space-between;
    font-size: 24px;
    border-left: 5px solid #41a1be;
    padding-left: 5px;