WXL
2024-06-27 76c30727c77065c808b1c0fb3146080e423e5fe6
src/views/knowledge/questionnaire/compilequer/index.vue
@@ -298,7 +298,13 @@
            >
          </div>
          <div style="display: flex">
            <span style="width: 180px; font-size: 20px; font-weight: normal; color: red"
            <span
              style="
                width: 180px;
                font-size: 20px;
                font-weight: normal;
                color: red;
              "
              >问卷总分:</span
            >
            <el-input
@@ -314,8 +320,8 @@
                <el-table-column
                  label="序号"
                  align="center"
                  key="guid"
                  prop="guid"
                  key="sort"
                  prop="sort"
                />
                <el-table-column
                  label="题目标题"
@@ -427,26 +433,37 @@
                  v-for="item in topicobj.svyLibTemplateTargetoptions"
                >
                  <el-row :gutter="10">
                    <el-col :span="11"
                      ><el-form-item label="题号">
                    <el-col :span="11">
                      <el-form-item v-if="topicobj.scoretype == 1" label="分值">
                        <el-input
                          type="text"
                          placeholder="请输入"
                          v-model="item.id"
                          show-word-limit
                        >
                        </el-input> </el-form-item
                    ></el-col>
                    <el-col :span="11"
                      ><el-form-item label="分值">
                        <el-input
                          type="text"
                          placeholder="请输入"
                          placeholder="请输入选项分值"
                          v-model="item.score"
                          show-word-limit
                        >
                        </el-input> </el-form-item
                    ></el-col>
                        </el-input>
                      </el-form-item>
                      <el-form-item
                        v-else-if="topicobj.scoretype == 2"
                        label="ABC等级"
                      >
                        <el-radio-group v-model="item.score">
                          <el-radio label="A">A</el-radio>
                          <el-radio label="B">B</el-radio>
                          <el-radio label="C">C</el-radio>
                        </el-radio-group>
                      </el-form-item>
                      <el-form-item
                        v-else-if="topicobj.scoretype == 3"
                        label="优良等级"
                      >
                        <el-radio-group v-model="item.score">
                          <el-radio label="优">优</el-radio>
                          <el-radio label="良">良</el-radio>
                          <el-radio label="差">差</el-radio>
                        </el-radio-group>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="10">
                    <el-col :span="11"
@@ -464,19 +481,19 @@
                        <el-input
                          type="text"
                          placeholder="请输入题号"
                          v-model="item.jump"
                          v-model="item.nextQuestion"
                          show-word-limit
                        >
                        </el-input> </el-form-item
                    ></el-col>
                    <el-col :span="2">
                    <!-- <el-col :span="2">
                      <el-button
                        type="danger"
                        icon="el-icon-delete"
                        circle
                        @click="deletexuanx(item)"
                      ></el-button>
                    </el-col>
                    </el-col> -->
                  </el-row>
                  <el-row :gutter="10">
                    <el-form-item label="选中提示">
@@ -680,7 +697,7 @@
      topicobj: {},
      // 总条数
      total: 1,
      ruleForm: {},
      ruleForm: { svyLibScripts: [], tempDetpRelevances: [] },
      rules: {},
      rulesa: {},
      optionsclass: [], //分类列表
@@ -740,14 +757,38 @@
      tempDetpRelevanceslist: [],
      optionstag: [],
      valuetype: [],
      usable: [],
      required: [],
      usable: [
        { value: "0", label: "可用" },
        { value: "1", label: "停用" },
      ],
      required: [
        { value: "1", label: "必填" },
        { value: "2", label: "不必填" },
      ],
      mode: [], //方式
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      arr: [
        [
          { id: 1, grade: "5" },
          { id: 2, grade: "5" },
          { id: 3, grade: "5" },
          { id: 4, grade: "5" },
        ],
        [
          { id: 1, grade: "5" },
          { id: 3, grade: "5" },
          { id: 4, grade: "5" },
        ],
        [
          { id: 1, grade: "5" },
          { id: 2, grade: "5" },
          { id: 4, grade: "5" },
        ],
      ],
    };
  },
@@ -760,6 +801,7 @@
    this.required = store.getters.required;
    this.valuetype = store.getters.valuetype;
    this.courtyardlist = store.getters.courtyardlist;
    this.test();
  },
  methods: {
@@ -785,21 +827,23 @@
    // 获取数据
    getissueinfo() {
      this.id = this.$route.query.id;
      getQtemplatelist({ svyid: this.id }).then((res) => {
        this.ruleForm = res.rows[0];
        this.dynamicTags = this.ruleForm.labelInfo.split(",");
        this.tempDetpRelevanceslist = JSON.parse(this.ruleForm.deptNames);
        this.ruleForm.suitway = this.ruleForm.suitway.split(",");
        console.log(this.tempDetpRelevanceslist);
      });
      if (this.id) {
        getQtemplatelist({ svyid: this.id }).then((res) => {
          this.ruleForm = res.rows[0];
          this.dynamicTags = this.ruleForm.labelInfo.split(",");
          this.tempDetpRelevanceslist = JSON.parse(this.ruleForm.deptNames);
          this.ruleForm.suitway = this.ruleForm.suitway.split(",");
          console.log(this.tempDetpRelevanceslist);
        });
        getillness({ outid: this.id, type: 5 }).then((res) => {
          this.illnesslist = res.rows;
        });
      }
      getillnesslist({
        pageNum: 1,
        pageSize: 100,
      }).then((response) => {
        this.optionsillness = response.rows;
      });
      getillness({ outid: this.id, type: 5 }).then((res) => {
        this.illnesslist = res.rows;
      });
      listDept(this.queryParams).then((response) => {
        this.deptList = this.handleTree(response.data, "deptId");
@@ -811,19 +855,28 @@
      });
    },
    submitForm(formName) {
      this.$modal.loading("正在上传数据,请稍候...");
      this.ruleForm.labelInfo = this.dynamicTags.join(",");
      this.ruleForm.suitway = this.ruleForm.suitway.join(",");
      if (this.id) {
        this.ruleForm.isoperation = 2;
        compileQtemplate(this.ruleForm).then((response) => {
        compileQtemplate(this.ruleForm).then((res) => {
          this.$modal.msgSuccess("修改成功");
          this.confirmillness();
          this.$modal.closeLoading();
          this.$router.go(-1);
        });
      } else {
        this.ruleForm.isoperation = 1;
        compileQtemplate(this.ruleForm).then((response) => {
        compileQtemplate(this.ruleForm).then((res) => {
          this.$modal.msgSuccess("新增成功");
          this.confirmillness(res.data);
          this.$modal.closeLoading();
          this.$router.go(-1);
        });
      }
@@ -835,6 +888,7 @@
      this.ruleForm.svyLibScripts = this.ruleForm.svyLibScripts.concat(
        this.delScriptVOList
      );
      console.log(this.tempDetpRelevanceslist, "this.tempDetpRelevanceslist");
      const result = this.tempDetpRelevanceslist.map(
        (subArr) => subArr[subArr.length - 1]
      );
@@ -894,6 +948,7 @@
    // 获取题目列表
    getaddtopiclist() {
      this.drawer = true;
      this.queryParams.scoretype = this.ruleForm.scoreType;
      getissuelist(this.queryParams).then((res) => {
        this.loading = false;
        this.userList = res.rows;
@@ -907,6 +962,7 @@
      row.svyLibScriptOptions.forEach((item) => {
        item.isoperation = 1;
      });
      row.svyLibTemplateTargetoptions = row.svyLibScriptOptions;
      this.ruleForm.svyLibScripts.push(row);
      this.$modal.msgSuccess("新增成功");
    },
@@ -936,16 +992,9 @@
      this.sortFn();
    },
    sortFn() {
      this.ruleForm.svyLibScripts = this.ruleForm.svyLibScripts.map(
        (item, index) => {
          return {
            guid: index + 1,
            svyid: item.svyid,
            script: item.script,
            script: item.script,
          };
        }
      );
      this.ruleForm.svyLibScripts.forEach((item, index) => {
        item.sort = index + 1;
      });
      console.log(this.ruleForm.svyLibScripts);
    },
@@ -1074,8 +1123,11 @@
      this.inputValueillness = "";
    },
    // 保存
    confirmillness() {
    confirmillness(guid) {
      this.illnesslist.forEach((item, index) => {
        if (guid) {
          item.outid = guid;
        }
        if (!item.id) {
          addtargetillness(item).then((res) => {});
        }
@@ -1094,6 +1146,129 @@
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 问卷分数限制算法
    // 混合路线
    generateCombinations(arrays, currentIndex = 0, currentCombination = []) {
      if (currentIndex === arrays.length) {
        return [currentCombination];
      }
      const currentArray = arrays[currentIndex];
      const newCombinations = [];
      for (const item of currentArray) {
        const newCombination = [...currentCombination, item];
        const combinations = this.generateCombinations(
          arrays,
          currentIndex + 1,
          newCombination
        );
        newCombinations.push(...combinations);
      }
      return newCombinations;
    },
    // 执行
    test() {
      const arrays = [
        ["2", "3", "4", "5"],
        ["1", "2", "5", "6"],
        ["3", "4", "5", "3"],
        ["3", "2", "5", "7"],
      ];
      const arraysa = [
        {
          id: 1,
          grade: "5",
          arr: [
            { name: "不错", skip: 2 },
            { name: "一般", skip: 2 },
            { name: "还不错", skip: 2 },
            { name: "很棒", skip: 3 },
          ],
        },
        {
          id: 2,
          grade: "5",
          arr: [
            { name: "优秀", skip: 3 },
            { name: "良好", skip: 3 },
            { name: "一般", skip: 3 },
            { name: "较差", skip: 4 },
          ],
        },
        {
          id: 3,
          grade: "5",
          arr: [
            { name: "是的", skip: 4 },
            { name: "不清楚", skip: 4 },
            { name: "还可", skip: 4 },
            { name: "一般", skip: 4 },
          ],
        },
        {
          id: 4,
          grade: "5",
          arr: [
            { name: "真不错", skip: null },
            { name: "还可以", skip: null },
            { name: "一般般", skip: null },
            { name: "不清楚", skip: null },
          ],
        },
      ];
      // const newMixArray = this.generateCombinations(arrays);
      const newMixArray = this.getExecutionOrders(arraysa);
      console.log(newMixArray, "全部路线");
      this.screen(newMixArray);
    },
    getExecutionOrders(data) {
      let orders = [];
      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]);
            }
          });
        } else {
          orders.push(
            currentOrder.map((id) => ({
              id: data[id].id,
              grade: data[id].grade,
            }))
          );
        }
      };
      console.log(data, "data");
      data.forEach((entry) => {
        explore([entry.id], entry.id);
      });
      return orders;
    },
    // 数组求和
    sumArray(arr) {
      return arr.reduce((acc, curr) => acc + parseInt(curr), 0);
    },
    // 筛选错误路线
    screen(data) {
      const arraysGreaterThan10 = data.filter((arr) => this.sumArray(arr) > 21);
      console.log(arraysGreaterThan10, "筛选错误路线大于13分");
    },
  },
};
</script>