WXL
2024-09-09 9ff0d92f9e7a58c405ef64e028cc7baf90d5f378
src/views/outsideChainwt.vue
@@ -1,7 +1,7 @@
<template>
  <div class="questionnaire">
    <div class="CONTENT">
      <div class="title">二期问卷调查表</div>
      <div class="title">{{ taskname ? taskname : "问卷" }}</div>
      <div class="preview-left">
        <!-- 单选 -->
        <div
@@ -9,43 +9,97 @@
          v-for="(item, index) in questionList"
          :key="item.aaa"
        >
          <div class="dev-text">
            {{ index + 1 }}、<span>{{ item.questionText }}</span>
          </div>
          <div class="dev-xx" v-if="item.valueType == 1">
            <el-radio-group v-model="item.asrtext">
              <el-radio
                v-for="(items, index) in item.ivrLibaScriptTargetoptionList"
                :key="items.id"
                :label="items.targetvalue"
                >{{ items.targetvalue }}</el-radio
          <div class="scriptTopic-dev" :key="index" v-if="item.scriptType == 1">
            <div class="dev-text">
              {{ index + 1 }}、[单选]<span>{{ item.scriptContent }}</span>
            </div>
            <div class="dev-xx">
              <el-radio-group
                v-model="item.scriptResult"
                @change="handleOptionChange($event, index, item)"
              >
            </el-radio-group>
                <el-radio
                  v-for="(items, index) in item.svyLibTemplateTargetoptions"
                  :key="index"
                  :label="items.optioncontent"
                  >{{ items.optioncontent }}</el-radio
                >
              </el-radio-group>
            </div>
            <div v-show="item.prompt">
              <el-alert :title="item.prompt" type="warning"> </el-alert>
            </div>
          </div>
          <div v-else>
            <el-input
              type="textarea"
              placeholder="请输入内容"
              v-model.sync="item.asrtext"
              :rows="2"
            />
          <!-- 多选 -->
          <div class="scriptTopic-dev" :key="index" v-if="item.scriptType == 2">
            <div class="dev-text">
              {{ index + 1 }}、[多选]<span>{{ item.scriptContent }}</span>
            </div>
            <div class="dev-xx">
              <el-checkbox-group
                v-model="item.scriptResult"
                @change="updateScore($event, index, item)"
              >
                <el-checkbox
                  @change="$forceUpdate()"
                  v-for="(items, indexs) in item.svyLibTemplateTargetoptions"
                  :key="indexs"
                  :label="items.optioncontent"
                >
                  {{ items.optioncontent }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
            <div v-show="item.prompt && item.scriptResult[0]">
              <el-alert :title="item.prompt" type="warning"> </el-alert>
            </div>
          </div>
          <!-- 填空 -->
          <div class="scriptTopic-dev" :key="index" v-if="item.scriptType == 4">
            <div class="dev-text">
              {{ index + 1 }}、[问答]<span>{{ item.scriptContent }}</span>
            </div>
            <div class="dev-xx">
              <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入答案"
                v-model="item.scriptResult"
                clearable
              >
              </el-input>
            </div>
          </div>
        </div>
      </div>
      <el-form :model="formData" label-width="80px">
        <el-form-item>
          <el-button type="primary" @click="submitForm">提交问卷</el-button>
          <el-button type="primary" @click="cache(true)">提交问卷</el-button>
          <!-- <el-button type="primary" @click="cache">缓存问卷</el-button> -->
        </el-form-item>
      </el-form>
    </div>
    <div class="CONTENT" v-if="accomplish">
      <div class="preview-left">
      </div>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      width="50%"
    >
      <div>
        <el-alert :title="revisitAfter" type="success"> </el-alert>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getExternalfollowup,
  SetsaveQuestionAnswer,
  getCachequestionnaire,
  Cachequestionnaire,
  Submitaquestionnaire,
} from "@/api/AiCentre/index";
import JSEncrypt from "jsencrypt";
export default {
@@ -54,6 +108,10 @@
      taskid: 355,
      patid: 265823,
      questionList: null,
      revisitAfter: null,
      dialogVisible:false,
      Endornot: true,
      accomplish:false,
      // 前端公钥
      publicKey:
        "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKR0yHv0rbJWQE+Sc7/FwpW66qMd9qX2k6z+SDgkSdxWh/1GbBoAP7bDQQRF6vXmoKsD2ya42H6XRLSDXAoayuMCAwEAAQ== ",
@@ -67,31 +125,69 @@
      },
    };
  },
  mounted() {
    window.addEventListener("beforeunload", this.cache);
  },
  beforeDestroy() {
    window.removeEventListener("beforeunload", this.cache);
  },
  created() {
    this.getQuestionnaire();
  },
  methods: {
    // 获取数据
    getQuestionnaire() {
      let taskid = this.$route.query.param1;
      let patid = this.$route.query.param2;
      this.taskid = decodeURIComponent(this.$route.query.param1);
      this.patid = decodeURIComponent(this.$route.query.param2);
      this.taskname = this.$route.query.param3;
      // let taskid =
      //   "OFp7tn/B6x7IzKJetvGWHdSWBj7msRlnlj6am9dyuHTH6sEt4uBbVCUXs5kcF/e4O2W6vqHf2Bz9K3/evbYDmw==";
      // let patid =
      //   "CVk0j8O86AeCqhV5WPsBBYDg9fec0wDoDlP9imYK4wDBNIkxywZzMJEGlPagOxnq6qr2WYZo0U8MUGWRGnq8ZA==";
      this.taskid = this.decrypt(taskid);
      this.patid = this.decrypt(patid);
      // this.$modal.msgSuccess("用户id为" + this.patid);
      // this.$modal.msgSuccess("任务id为" + this.taskid);
      let taskids = this.encrypt(this.taskid);
      let patids = this.encrypt(this.patid);
      getExternalfollowup({ param1: taskids, param2: patids }).then((res) => {
        if (res.code == 200) {
          this.questionList = res.rows;
      // this.taskid = this.decrypt(taskid);
      // this.patid = this.decrypt(patid);
      // let taskids = this.encrypt(this.taskid);
      // let patids = this.encrypt(this.patid);
      // 先取缓存
      getCachequestionnaire({ param1: this.taskid, param2: this.patid }).then(
        (res) => {
          if (res.code == 200) {
            this.questionList = res.data;
            if (this.questionList[0]) {
              this.questionList.forEach((item) => {
                if (item.scriptResult && item.scriptType != 2) {
                  item.scriptResult = JSON.parse(item.scriptResult);
                } else if (item.scriptResult && item.scriptType == 2) {
                  item.scriptResult = item.scriptResult.split("&");
                }
              });
              return;
            } else {
              this.getExternalfollowup();
            }
          } else {
            this.getExternalfollowup();
          }
        }
      });
      );
    },
    // 获取数据
    getExternalfollowup() {
      getExternalfollowup({ param1: this.taskid, param2: this.patid }).then(
        (res) => {
          if (res.code == 200) {
            this.questionList = res.data.script;
            this.revisitAfter = res.data.revisitAfter;
            // 处理题目收集结果格式
            this.questionList.forEach((item) => {
              item.nextScriptno = Number(item.nextScriptno);
              if (item.scriptType == 2) {
                item.scriptResult = [];
              }
            });
          }
        }
      );
    },
    // 加密函数
    encrypt(txt) {
@@ -99,7 +195,6 @@
      encryptor.setPublicKey(this.publicKey); // 设置公钥
      return encryptor.encrypt(txt); // 对数据进行加密
    },
    // 解密函数
    decrypt(txt) {
      const encryptor = new JSEncrypt();
@@ -109,33 +204,80 @@
    // 提交
    submitForm() {
      // 提交表单逻辑
      console.log(this.questionList);
      let form = {
        param1: this.encrypt(this.taskid),
        param2: this.encrypt(this.patid),
        ivrTaskcalldetailList: [],
        param1: this.taskid,
        param2: this.patid,
        serviceSubtaskDetailList: [],
      };
      this.questionList.forEach((item) => {
        let optionarr = [];
        item.ivrLibaScriptTargetoptionList.forEach((option) => {
          optionarr.push(option.targetvalue);
        });
        let ivrTaskcalldetail = {
          asrtext: item.asrtext,
          valueType: item.valueType,
          questiontext: item.questionText,
          targetoptions: optionarr.join(","),
        };
        form.ivrTaskcalldetailList.push(ivrTaskcalldetail);
      });
      console.log(form, "form");
      SetsaveQuestionAnswer(form).then((res) => {
      const arr = structuredClone(this.questionList);
      // arr.forEach((item) => {
      //   item.asrtext = JSON.stringify(item.scriptResult);
      //   if (item.scriptType == 2 && item.scriptResult[0]) {
      //     item.scriptResult = item.scriptResult.join("&");
      //   }
      // });
      form.serviceSubtaskDetailList = arr;
      Submitaquestionnaire(form).then((res) => {
        if (res.code == 200) {
          if (this.revisitAfter) {
            this.dialogVisible=true
          }
          this.$modal.msgSuccess("提交成功");
        }
      });
      // 可以将数据提交到后端或者进行其他处理
    },
    // 缓存
    cache(subm) {
      console.log("进入缓存");
      let form = {
        param1: this.taskid,
        param2: this.patid,
        svyLibTemplateScriptVOS: [],
      };
      const arr = structuredClone(this.questionList);
      arr.forEach((item) => {
        if (item.scriptType == 2 && item.scriptResult[0]) {
          item.scriptResult = item.scriptResult.join("&");
        } else if (item.scriptType != 2 && item.scriptResult) {
          item.scriptResult = JSON.stringify(item.scriptResult);
        }
      });
      form.svyLibTemplateScriptVOS = arr;
      Cachequestionnaire(form).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess("提交成功");
          if (subm) {
            this.submitForm();
          }
        }
      });
    },
    // 处理单选选项
    handleOptionChange(selectedvalue, index, arr) {
      // 查找选中的选项对象
      const selectedOption = arr.svyLibTemplateTargetoptions.find(
        (option) => option.optioncontent == selectedvalue
      );
      if (selectedOption) {
        // 将选中的选项对象的 id 赋值给 obj.sonId
        this.questionList[index].nextScriptno = selectedOption.nextQuestion;
        this.questionList[index].score = selectedOption.score;
        this.questionList[index].prompt = selectedOption.prompt;
      }
    },
    // 处理多选选项
    updateScore(selectedvalues, index, arr) {
      // ��加分数
      let score = 0;
      selectedvalues.forEach((value) => {
        const selectedOption = arr.svyLibTemplateTargetoptions.find(
          (option) => option.optioncontent == value
        );
        if (selectedOption) {
          score += Number(selectedOption.score);
        }
      });
      this.questionList[index].score = score;
    },
  },
};
@@ -143,11 +285,6 @@
<style lang="scss" scoped>
.questionnaire {
  // background-image: url("../assets/images/chainbackground.jpg");
  // background-repeat: no-repeat;
  // background-position: center center;
  // background-size: cover;
  // height: 100vh;
  background-image: url("../assets/images/chainbackground.jpg");
  background-size: cover;
  background-attachment: fixed; /* 保持背景固定 */
@@ -182,4 +319,14 @@
    }
  }
}
::v-deep.el-alert--warning.is-light {
    background-color: #fbf9f3;
    color: #ffba00;
}
::v-deep{
  .el-alert__title {
    font-size: 18px;
    line-height: 18px;
}
}
</style>