WXL
2024-06-27 76c30727c77065c808b1c0fb3146080e423e5fe6
src/views/knowledge/questionbank/particulars/index.vue
@@ -6,43 +6,76 @@
          <div class="headline">
            题目设置详情
            <span style="margin-left: 30px"
              ><el-button type="primary" @click="compileissue"
                >保存</el-button
              ><el-button type="primary" @click="Saveproblem"
                >保 存</el-button
              > </span
            ><span style="margin-left: 30px"
              ><el-button type="success" round @click="drawer = true"
                >+选择指标</el-button
              ></span
            >
          </div>
          <div style="margin-left: 8%">
            <el-form-item label="问题分类">
              <el-select
                v-model="topicobj.assortid"
                size="medium"
                filterable
                placeholder="请选择分类"
              >
                <el-option-group
                  v-for="group in classifylist"
                  :key="group.id"
                  :label="group.name"
                >
                  <el-option
                    v-for="item in group.svyLibTopicCategoryList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-option-group>
              </el-select>
            </el-form-item>
            <el-row :gutter="10">
              <el-col :span="6"
              <el-col :span="8">
                <el-form-item label="问题分类">
                  <el-select
                    v-model="topicobj.categoryid"
                    size="medium"
                    filterable
                    placeholder="请选择分类"
                  >
                    <el-option-group
                      v-for="group in classifylist"
                      :key="group.id"
                      :label="group.name"
                    >
                      <el-option
                        v-for="item in group.svyLibScriptCategoryList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-option-group>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="评价类型">
                  <el-select
                    v-model="topicobj.scoretype"
                    placeholder="请选择分类"
                  >
                    <el-option
                      v-for="group in appraiselist"
                      :key="group.value"
                      :label="group.label"
                      :value="group.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="topicobj.scoretype == 1">
                <el-form-item label="题目得分">
                  <el-input
                    v-model="topicobj.score"
                    placeholder="请输入分数"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="10">
              <el-col :span="8"
                ><el-form-item label="题目标题">
                  <el-input
                    v-model="topicobj.topic"
                    placeholder="请输入标题"
                  ></el-input> </el-form-item
              ></el-col>
              <el-col :span="6"
              <el-col :span="8"
                ><el-form-item label="是否可用">
                  <el-select
                    v-model="topicobj.isavailable"
@@ -80,7 +113,7 @@
              ></el-col>
            </el-row>
            <el-row :gutter="10">
              <el-col :span="6"
              <el-col :span="8"
                ><el-form-item label="是否必填">
                  <el-select
                    v-model="topicobj.ismandatory"
@@ -98,17 +131,17 @@
                    </el-option>
                  </el-select> </el-form-item
              ></el-col>
              <el-col :span="6"
              <el-col :span="8"
                ><el-form-item label="题目类型">
                  <el-select
                    v-model="topicobj.topictype"
                    v-model="topicobj.scripttype"
                    size="medium"
                    filterable
                    placeholder="请选择分类"
                  >
                    <el-option
                      class="topicobjaa"
                      v-for="item in xjxsoptions"
                      v-for="item in valuetype"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
@@ -119,9 +152,10 @@
              <el-col :span="8"
                ><el-form-item label="适用方式">
                  <el-select
                    v-model="topicobj.suitway"
                    v-model="suitwaylist"
                    size="medium"
                    filterable
                    multiple
                    placeholder="请选择分类"
                  >
                    <el-option
@@ -138,10 +172,18 @@
              <el-input
                style="width: 40vw"
                type="textarea"
                id="topicContent"
                v-model="topicobj.topicContent"
                @focus="handleInput('topicContent')"
                placeholder="请输入标题"
                id="script"
                v-model="topicobj.script"
                @focus="handleInput('script')"
                placeholder="请输入题目内容"
              ></el-input>
            </el-form-item>
            <el-form-item label="题目说明">
              <el-input
                style="width: 40vw"
                type="textarea"
                v-model="topicobj.scriptContent"
                placeholder="请输入说明"
              ></el-input>
            </el-form-item>
@@ -231,7 +273,7 @@
                </div>
              </el-form-item>
            </el-row>
            <el-form-item label="通知变量" prop="name">
            <!-- <el-form-item label="通知变量" prop="name">
              <div style="margin-bottom: 5px" v-for="item in variablelist">
                <el-row>
                  <el-col :span="5">
@@ -278,68 +320,86 @@
                  </div>
                </div>
              </el-col></el-row
            >
            > -->
          </div>
          <div class="headline">
            选项设置<span style="margin-left: 30px"
              ><el-button type="primary" round @click="addoption"
                >+新增</el-button
              ></span
            ><span style="margin-left: 30px"
              ><el-button type="success" round @click="drawer = true"
                >+选择指标</el-button
              ></span
          <div v-if="topicobj.valueType == 1">
            <div class="headline">
              选项设置<span style="margin-left: 30px"
                ><el-button type="primary" round @click="addoption"
                  >+新增</el-button
                ></span
              >
            </div>
            <div
              class="topicxq"
              v-for="item in topicobj.svyLibScriptOptions"
              v-if="item.isoperation != 3"
            >
          </div>
          <div
            class="topicxq"
            v-for="item in topicobj.svyLibTopicoptions"
            v-if="item.isoperation != 3"
          >
            <el-row :gutter="10">
              <el-col :span="11"
                ><el-form-item label="选项">
                  <el-input
                    type="text"
                    placeholder="请输入选项"
                    v-model="item.optioncontent"
                    show-word-limit
              <el-row :gutter="10">
                <el-col :span="11"
                  ><el-form-item label="选项">
                    <el-input
                      type="text"
                      placeholder="请输入选项"
                      v-model="item.optioncontent"
                      show-word-limit
                    >
                    </el-input> </el-form-item
                ></el-col>
                <el-col :span="11">
                  <el-form-item v-if="topicobj.scoretype == 1" label="分值">
                    <el-input
                      type="text"
                      placeholder="请输入选项分值"
                      v-model="item.score"
                      show-word-limit
                    >
                    </el-input>
                  </el-form-item>
                  <el-form-item
                    v-else-if="topicobj.scoretype == 2"
                    label="ABC等级"
                  >
                  </el-input> </el-form-item
              ></el-col>
              <el-col :span="11"
                ><el-form-item label="分值">
                  <el-input
                    type="text"
                    placeholder="请输入"
                    v-model="item.score"
                    show-word-limit
                    <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-input> </el-form-item
              ></el-col>
              <el-col :span="2">
                <el-button
                  type="danger"
                  icon="el-icon-delete"
                  circle
                  @click="deletexuanx(item)"
                ></el-button>
              </el-col>
            </el-row>
                    <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-col :span="2">
                  <el-button
                    type="danger"
                    icon="el-icon-delete"
                    circle
                    @click="deletexuanx(item)"
                  ></el-button>
                </el-col>
              </el-row>
            <el-row :gutter="10">
              <el-form-item label="选中提示">
                <el-input
                  style="width: 40vw"
                  type="textarea"
                  autosize
                  placeholder="请输入内容"
                  v-model="item.prompt"
                >
                </el-input
              ></el-form-item>
            </el-row>
              <el-row :gutter="10">
                <el-form-item label="选中提示">
                  <el-input
                    style="width: 40vw"
                    type="textarea"
                    autosize
                    placeholder="请输入内容"
                    v-model="item.prompt"
                  >
                  </el-input
                ></el-form-item>
              </el-row>
            </div>
          </div>
        </el-form>
      </el-card>
@@ -348,7 +408,7 @@
      title="添加选项"
      :visible.sync="drawer"
      custom-class="demo-drawer"
      width="66%"
      size="50%"
    >
      <div class="preview-left">
        <el-form
@@ -409,7 +469,7 @@
                type="text"
                @click="selectlabel(scope.row)"
                ><span class="button-textxg"
                  ><i class="el-icon-circle-plus-outline"></i>添加</span
                  ><i class="el-icon-circle-plus-outline"></i>选择</span
                ></el-button
              >
            </template>
@@ -449,7 +509,7 @@
  data() {
    return {
      topicobj: {
        svyLibTopicoptions: [],
        svyLibScriptOptions: [],
      },
      inputVisible: false,
      inputValue: "",
@@ -458,6 +518,7 @@
      drawer: false,
      loading: false,
      id: [],
      suitwaylist: [],
      targetList: [],
      dynamicTags: [],
      optionsclass: [],
@@ -491,8 +552,13 @@
      illnesslistapi: [],
      illnesslist: [],
      classifylist: [],
      appraiselist: [
        { label: "分数", value: "1" },
        { label: "ABC等级", value: "2" },
        { label: "优良等级", value: "3" },
      ],
      optionstag: [],
      xjxsoptions: [],
      valuetype: [],
      usable: [],
      mode: [], //方式
    };
@@ -505,7 +571,7 @@
    this.mode = store.getters.mode;
    this.languagelist = store.getters.languagelist;
    this.usable = store.getters.usable;
    this.xjxsoptions = store.getters.xjxsoptions;
    this.valuetype = store.getters.askvaluetype;
    this.required = store.getters.required;
  },
@@ -533,12 +599,18 @@
    // 获取数据
    getissueinfo() {
      this.id = this.$route.query.id;
      // 分类
      getissueclassify({}).then((res) => {
        this.classifylist = res.rows;
        console.log(this.classifylist, "分类");
      });
      if (!this.id) {
        return;
      }
      getissuelist({ topicid: this.id }).then((res) => {
      getissuelist({ id: this.id }).then((res) => {
        this.topicobj = res.rows[0];
        this.dynamicTags = this.topicobj.tag.split(",");
        this.suitwaylist = this.topicobj.suitway.split(",");
        this.variablelist = JSON.parse(this.topicobj.otherdata)
          ? JSON.parse(this.topicobj.otherdata)
          : this.variablelist;
@@ -552,10 +624,6 @@
      getillness({ outid: this.id, type: 4 }).then((res) => {
        this.illnesslist = res.rows;
      });
      // 分类
      getissueclassify({}).then((res) => {
        this.classifylist = res.rows;
      });
    },
    gettargetInfo() {
      gettargetInfo(this.queryParams).then((res) => {
@@ -565,7 +633,7 @@
    },
    // 新增或修改详情
    compileissue() {
      this.topicobj.svyLibTopicoptions = this.topicobj.svyLibTopicoptions.map(
      this.topicobj.svyLibScriptOptions = this.topicobj.svyLibScriptOptions.map(
        (item) => {
          if (item.isoperation != 1 && item.isoperation != 3) {
            item.isoperation = 2;
@@ -575,6 +643,7 @@
      );
      this.topicobj.otherdata = JSON.stringify(this.variablelist);
      this.topicobj.tag = this.dynamicTags.join(",");
      this.topicobj.suitway = this.suitwaylist.join(",");
      if (this.id) {
        this.topicobj.isoperation = 2;
        compileissue(this.topicobj).then((res) => {
@@ -617,31 +686,95 @@
        deltargetillness(this.illnesslistapi.join(",")).then((res) => {});
      }
    },
    // 判断分值
    Scorejudgment() {
      let scorearr = this.topicobj.svyLibScriptOptions;
      let isValid = scorearr.every((score) => {
        if (score.score) {
          console.log(Number(score.score), this.topicobj.score, "分值");
          if (
            Number(score.score) <= 0 ||
            Number(score.score) > Number(this.topicobj.score)
          ) {
            console.log(22);
            this.$message({
              message: "选项分值必须大于0小于等于" + this.topicobj.score + "分",
              type: "warning",
            });
            return false;
          }
          return true;
        } else {
          this.$message({
            message: "选项分值未设置",
            type: "warning",
          });
          return false;
        }
      });
      if (isValid) {
        this.compileissue();
        // console.log("到保存了");
      }
    },
    Saveproblem() {
      if (this.topicobj.scoretype == 1) {
        console.log(321);
        this.Scorejudgment();
      } else {
        this.compileissue();
      }
    },
    // 删除标签
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
    },
    // 删除选项
    deletexuanx(row) {
      const index = this.getIndexInArray(this.topicobj.svyLibTopicoptions, row);
      if (this.topicobj.svyLibTopicoptions[index].topicid) {
        this.topicobj.svyLibTopicoptions[index].isoperation = 3;
      const index = this.getIndexInArray(
        this.topicobj.svyLibScriptOptions,
        row
      );
      if (this.topicobj.svyLibScriptOptions[index].id) {
        this.topicobj.svyLibScriptOptions[index].isoperation = 3;
      } else {
        this.topicobj.svyLibTopicoptions.splice(index, 1);
        this.topicobj.svyLibScriptOptions.splice(index, 1);
      }
    },
    // 新增选项
    addoption() {
      this.topicobj.svyLibTopicoptions.push({
      console.log(this.topicobj, "obj");
      this.topicobj.svyLibScriptOptions.push({
        score: "",
        isoperation: 1,
      });
    },
    // 选择指标
    selectlabel(row) {
      const labellist = row.targetoptionList;
      labellist.forEach((item) => {
        this.topicobj.svyLibTopicoptions.push({
          optioncontent: item.targetvalue,
          isoperation: 1,
        });
      });
      this.$modal
        .confirm(
          '是否选择标题为"' + row.targetname + '"的指标并替换填充问题信息?'
        )
        .then(() => {
          console.log(row);
          console.log(this.topicobj);
          this.topicobj.topic = row.targetname;
          this.topicobj.valueType = row.valueType;
          this.topicobj.scriptContent = row.targetdesc;
          this.topicobj.isavailable = "0";
          this.topicobj.language = "普通话";
          this.topicobj.svyLibScriptOptions = [];
          const labellist = row.targetoptionList;
          labellist.forEach((item) => {
            this.topicobj.svyLibScriptOptions.push({
              optioncontent: item.targetvalue,
              isoperation: 1,
            });
          });
          this.drawer = false;
        })
        .catch(() => {});
    },
    // 标签-----------------
@@ -744,27 +877,27 @@
      this.inputVisibleillness = false;
      this.inputValueillness = "";
    },
    // 保存
    confirmillness() {
      this.illnesslist.forEach((item, index) => {
        if (!item.id) {
          addtargetillness(item).then((res) => {});
        }
      });
      if (this.illnesslistapi.length) {
        deltargetillness(this.illnesslistapi.join(",")).then((res) => {});
      }
      this.illnessVisible = false;
      this.$modal.msgSuccess("编辑成功");
    },
    // // 保存
    // confirmillness() {
    //   this.illnesslist.forEach((item, index) => {
    //     if (!item.id) {
    //       addtargetillness(item).then((res) => {});
    //     }
    //   });
    //   if (this.illnesslistapi.length) {
    //     deltargetillness(this.illnesslistapi.join(",")).then((res) => {});
    //   }
    //   this.illnessVisible = false;
    //   this.$modal.msgSuccess("编辑成功");
    // },
    resetQuery() {},
    // 便捷标签
    tsgnameto(row) {
      let inputValueArr = "";
      let el = document.querySelector("#" + this.currentInputId);
      //el.selectionStart; 这就是当前光标所在的位置(字符串中字符的index)
      if (this.currentInputId == "topicContent") {
        inputValueArr = this.topicobj.topicContent.split("");
      if (this.currentInputId == "script") {
        inputValueArr = this.topicobj.script.split("");
        console.log(123);
      } else if (this.currentInputId == "nomatchtext") {
        inputValueArr = this.topicobj.nomatchtext.split("");
@@ -786,8 +919,8 @@
      // 把数组重新转换为字符串并赋值
      inputValueArr = inputValueArr.join("");
      console.log(inputValueArr);
      if (this.currentInputId == "topicContent") {
        this.topicobj.topicContent = inputValueArr;
      if (this.currentInputId == "script") {
        this.topicobj.script = inputValueArr;
      } else if (this.currentInputId == "nomatchtext") {
        this.topicobj.nomatchtext = inputValueArr;
      } else if (this.currentInputId == "sliencetext") {
@@ -823,6 +956,49 @@
      console.log("输入框的值已更新:", this.currentInputId);
      // 在这里执行更新数据的逻辑
    },
    // 混合路线
    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 newMixArray = this.generateCombinations(arrays);
      console.log(newMixArray, "全部路线");
      this.screen(newMixArray);
    },
    // 数组求和
    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>