123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187 |
- <template>
- <div class="main_right_height">
- <div class="smart_content">
- <el-row>
- <!-- <el-col :span="1"> </el-col> -->
- <div style="text-align: right">
- <i
- class="el-icon-refresh"
- style="cursor: pointer; color: blue"
- @click="init()"
- ></i>
- </div>
- <el-col :span="24">
- <div
- class="chat-window"
- style="padding-left: 20px; padding-right: 20px; margin-top: 20px"
- id="contant1"
- ref="scrollview"
- >
- <div v-if="echoFlag" style="text-align: center">
- <i class="el-icon-loading"></i>
- </div>
- <!-- <div style="text-align: right">
- <i class="el-icon-loading"></i>
- </div> -->
- <div
- class="chat-msg-content"
- id="rongqi"
- v-for="(content, index) in chatContents"
- :key="index"
- >
- <div
- v-if="content.from == 1 && content.question !== ''"
- class="main_answer_right"
- style="margin-top: 10px"
- >
- <!-- &&!(chatContents.length - 1 == index) -->
- <div
- class="img-wrapper"
- v-if="
- (content.isType == 0 && chatContents.length - 1 == index) ||
- content.isType == -1 ||
- (content.isType == 5 && chatContents.length - 1 == index)
- "
- >
- <img width="60px" heigth="60px" class="img" :src="from1" />
- </div>
- <div
- class="message-wrapper message-wrapper-left"
- v-if="
- (content.isType == 0 && chatContents.length - 1 == index) ||
- content.isType == -1 ||
- (content.isType == 5 && chatContents.length - 1 == index)
- "
- >
- <div class="message" v-if="content.isType == 0">
- <el-radio-group
- v-model="answerList[content.index].checkItems"
- @input="nextHandle(content.index)"
- >
- <el-radio
- style="width: 100%"
- v-for="(item, index) in content.question"
- :key="index"
- size="small"
- :label="item"
- border
- >{{ item }}</el-radio
- >
- </el-radio-group>
- </div>
- <div class="message" v-if="content.isType == 5">
- <el-radio-group
- v-model="answerList[content.index].checkItems"
- @input="nextHandle(content.index)"
- >
- <el-radio
- v-for="(item, index) in content.question"
- :key="index"
- size="small"
- :label="item.label"
- border
- >{{ item.name }}</el-radio
- >
- </el-radio-group>
- </div>
- <div class="message" v-if="content.isType == -1">
- {{ content.question }}
- </div>
- </div>
- </div>
- <el-row v-if="content.from == 2" style="margin-top: 10px">
- <el-col :span="10"> </el-col>
- <el-col :span="14">
- <div class="main_answer_left" style="float: right">
- <div class="message-wrapper message-wrapper-right">
- <el-radio-group
- v-if="content.isScale"
- v-model="answerList[content.index].checkItems"
- @input="nextHandle(content.index)"
- >
- <el-radio
- style="width: 100%"
- v-for="(item, index) in content.question"
- :key="index"
- size="small"
- :label="item"
- border
- >{{ item }}</el-radio
- >
- </el-radio-group>
- <el-radio-group
- v-if="!content.isScale && content.isType == 0"
- v-model="content.radio"
- :disabled="!(chatContents.length - 1 == index)"
- @input="chooseAnswer(content)"
- >
- <el-radio
- style="width: 100%"
- v-for="item in content.question"
- :key="item.id"
- size="small"
- :label="item.nextQuestionNo"
- border
- >{{ item.answer }}</el-radio
- >
- </el-radio-group>
- <div
- class="send_class"
- v-if="content.isType == 1 || content.isType == 3"
- >
- <el-input
- :disabled="!(chatContents.length - 1 == index)"
- v-if="content.isType == 1 || content.isType == 3"
- v-model="content.text"
- @keyup.native.enter="sendMessageFun(content)"
- /><i
- v-show="chatContents.length - 1 == index"
- style="
- width: 20px;
- height: 20px;
- color: #57c02c;
- margin-left: 10px;
- "
- v-if="content.isType == 1 || content.isType == 3"
- @click="sendMessageFun(content)"
- class="el-icon-s-promotion"
- ></i>
- <!-- {{content}} -->
- </div>
- <div
- class="message_form2"
- style="color: #000000"
- v-if="content.isType == -1"
- >
- {{ content.question }}
- </div>
- </div>
- <div class="img-wrapper">
- <img width="60px" heigth="60px" class="img" :src="from2" />
- </div>
- </div>
- </el-col>
- </el-row>
- </div>
- </div>
- </el-col>
- <!-- <el-col :span="1"> </el-col> -->
- </el-row>
- <el-row v-show="inputFlag === 2" class="footSendSelect">
- <el-col :span="1"> </el-col>
- <el-col :span="22" style="margin-top: 20px; margin-bottom: 20px">
- <div>
- <el-radio
- style="margin-top: 10px"
- v-for="(item, index) in scale_checkItems"
- :key="index"
- v-model="radio"
- :label="item"
- fill="#57ACBB"
- @change="selectRadio(item)"
- >{{ item }}</el-radio
- >
- </div></el-col
- >
- <el-col :span="1"> </el-col>
- </el-row>
- <el-row v-show="inputFlag === 3" class="footSendSelect">
- <el-col :span="1"> </el-col>
- <el-col :span="22" style="margin-top: 20px; margin-bottom: 20px">
- <div>
- <el-radio
- :disabled="!scaleSelectFlag"
- style="margin-top: 10px"
- v-for="(item, index) in scale_checkItems"
- :key="index"
- v-model="radio"
- :label="item"
- fill="#57ACBB"
- @change="choiceTriger(item)"
- >{{ item }}</el-radio
- >
- </div></el-col
- >
- <el-col :span="1"> </el-col>
- </el-row>
- </div>
- <!-- 弹出框显示视频视频从头开始播放,下方有按钮--按钮点击进行访问下一题 -->
- <el-dialog
- :close-on-click-modal="false"
- title="刺激呈现"
- :visible.sync="centerDialogVisible"
- width="80%"
- center
- >
- <span>
- <video width="100%" height="100%" controls>
- <source src="../assets/EMDR.mp4" type="video/mp4" />
- </video>
- </span>
- <span slot="footer" class="dialog-footer">
- <!-- <el-button @click="centerDialogVisible = false">取 消</el-button> -->
- <el-button type="primary" @click="centerDialogVisible = false"
- >我已看完</el-button
- >
- </span>
- </el-dialog>
- <!-- <el-button @click="centerDialogVisible = true">打开窗口</el-button> -->
- </div>
- </template>
- <script>
- import HeadImg from "@/assets/lion.png";
- import HeadImg1 from "@/assets/newImage/peopleUser.png";
- import axios from "axios";
- import Video from "./Video.vue";
- export default {
- components: { Video },
- data() {
- return {
- centerDialogVisible: false,
- tmpRadio: "",
- radio: "",
- inputFlag: 1,
- desc: "",
- from1: HeadImg,
- from2: HeadImg1,
- chatContents: [],
- //前三个问题
- preList: [],
- questionList: [],
- //随机的4个数集合
- radomNumList: [],
- questionNum: 0,
- //随机4个问题的集合
- randomQuestion: [],
- //随机4个答案的集合
- randomAnswer: [],
- //全部题目
- scale_infos: [{ answer: "" }],
- //题目总数
- scale_all: 0,
- scale_checkItems: [],
- //进度参数
- scale_percent: [],
- //
- scale_index: 0,
- // 答案数据
- scale_result: [],
- //检测情绪前的发送数据条数
- threeAnswers: [],
- //负面情绪标志
- moonNegative: 0,
- scale_flag: "",
- pressure_flag: "",
- sendMsgFlag: true,
- scaleSelectFlag: true,
- radio3: "",
- scaleTestStart: false,
- flag: "",
- questionList: [],
- answerList: [],
- interveneId: "",
- //当回显接口正在调用时为true
- echoFlag: false,
- //当前返回历史记录
- currenRecordTotol: 0,
- //当前页
- pageNum: 1,
- //一页多少条
- pageSize: 10,
- printIndex: 0,
- flagTime: null,
- openDialogFlag: true,
- isTimeout: false,
- timeoutDes: "",
- //获取下一题问题的编号
- preQuestion: "",
- oNum: 1,
- currentId: "",
- };
- },
- created() {},
- mounted() {
- var scrollview = this.$refs["scrollview"];
- this.interveneId = this.$route.query.id;
- //
- // this.init("start");
- // this.selectScale("20220805135201");
- //上来就查询之前的聊天记录
- scrollview.addEventListener("scroll", this.handleScroll, true);
- //先调用接口知道是否出来弹窗
- this.selectPage();
- //判断是否是第一次进来,如果查询记录为空,则是第一次进来--则需要调用出初始化语句
- //如果不是第一次进来--则接着上次的记录说
- },
- beforeDestroy() {
- let that = this;
- var scrollview = this.$refs["scrollview"];
- scrollview.removeEventListener("scroll", that.handleScroll);
- },
- methods: {
- openDialog() {
- openDialogFlag = true;
- },
- handleScroll() {
- let scrollview = this.$refs["scrollview"];
- if (scrollview.scrollTop == 0) {
- //当前没有调接口的时候
- if (!this.echoFlag) {
- //判断上一次的页面是否足够10条如果不够就不查询了
- //页面页数加1
- if (this.currenRecordTotol == this.pageSize) {
- this.pageNum++;
- this.selectPage();
- }
- }
- //当等于0时需要调用加载上一页
- }
- // console.log("qlkhdeqj1");
- //滚动监听事件
- },
- //保存聊天记录--单条
- saveRecord(val) {
- let data = {
- identifier: sessionStorage.getItem("num"),
- label: val.label,
- content: val.content,
- userName: sessionStorage.getItem("name"),
- questionNo: val.questionNo,
- type: this.interveneId,
- num: this.oNum,
- };
- if (val.content && val.content.includes("测评结果")) {
- let result = sessionStorage.getItem("testResults");
- data.content = val.content + result;
- }
- console.log(data);
- // this.$message.success("保存成功");
- this.$http.post(`/intelligent/save`, data, (res) => {
- if (res.data.code == 200) {
- } else {
- }
- });
- },
- //查询聊天记录
- selectPage() {
- let that = this;
- that.echoFlag = true;
- this.$http.get(
- `/intelligent/dialogueRecords?identifier=${sessionStorage.getItem(
- "num"
- )}&pageNum=${that.pageNum}&pageSize=${that.pageSize}&type=${that.interveneId}`,
- {},
- (res) => {
- if (res.code == 200) {
- //res.data.greetings==
- // console.log(res.data.greetings==null)
- //
- if (that.pageNum == 1) {
- if (res.data.greetings == null) {
- that.isTimeout = false;
- that.timeoutDes = "";
- } else {
- that.isTimeout = true;
- that.timeoutDes = res.data.greetings;
- }
- } else {
- that.isTimeout = false;
- }
- // that.isTimeout = true;
- // that.timeoutDes = "三天没见了,你最近好吗";
- that.echoFlag = false;
- // res.data.
- if (res.data.intelligentDialogueEntities.content.length > 0) {
- that.currenRecordTotol =
- res.data.intelligentDialogueEntities.content.length;
- this.oNum = res.data.intelligentDialogueEntities.content[0].num;
- //判断当前是第几页
- //如果是第一个
- for (
- let i = 0;
- i < res.data.intelligentDialogueEntities.content.length;
- i++
- ) {
- if (res.data.intelligentDialogueEntities.content[i].label == "0") {
- //当是第一页第一个时,不取了
- //判断最后一个是不是填空还是选择
- //如果时填空或选择则后两个都不如库
- if (!(that.pageNum == 1 && i == 0)) {
- //当满足条件时
- this.chatContents.unshift({
- from: 1,
- //是否是量表的信息
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: -1,
- //可点击可不点击 0单选 1填空
- disabled: false,
- //问题
- question: res.data.intelligentDialogueEntities.content[i].content,
- //头像
- from1: HeadImg,
- });
- } else {
- that.preQuestion =
- res.data.intelligentDialogueEntities.content[0].questionNo;
- }
- } else {
- if (!(that.pageNum == 1 && i == 0)) {
- this.chatContents.unshift({
- from: 2,
- //是否是量表的信息
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: -1,
- //可点击可不点击 0单选 1填空
- disabled: false,
- //问题
- question: res.data.intelligentDialogueEntities.content[i].content,
- //头像
- from1: HeadImg,
- });
- }
- }
- }
- let contant1 = document.getElementById("contant1");
- this.sleep(300).then(() => {
- contant1.scrollTop = 2;
- });
- console.log(this.chatContents);
- } else {
- this.oNum = 1;
- }
- //如满足条件//应还有一个参数--用来表示是否需要显示提示几天不见的话语
- if (that.isTimeout) {
- that.chatContents.push({
- //是问题还是答案
- from: 1,
- //是否是量表的信息
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: -1,
- //可点击可不点击 0单选 1填空
- disabled: false,
- //问题
- question: "",
- //头像
- from1: HeadImg,
- });
- that.pFun(that.timeoutDes, true, "", false, true);
- } else {
- if (that.pageNum == 1) {
- //当是第一次进来时,需要调用question 获取第一次问答信息,但是传输的是type为5
- if (res.data.intelligentDialogueEntities.content.length == 0) {
- //将当前的设置为5
- that.interveneId = 5;
- that.getQuestion("", false);
- } else {
- let id = res.data.intelligentDialogueEntities.content[0].questionNo;
- that.getQuestion(id, false);
- }
- }
- }
- //当是第一页
- //且总条数为0时
- // if (that.pageNum == 1) {
- // //当是第一次进来时,需要调用question 获取第一次问答信息,但是传输的是type为5
- // if (res.data.intelligentDialogueEntities.content.length == 0) {
- // //将当前的设置为5
- // that.interveneId = 5;
- // that.getQuestion("", false);
- // } else {
- // let id =
- // res.data.intelligentDialogueEntities.content[0].questionNo;
- // that.getQuestion(id, false);
- // }
- // }
- } else {
- }
- }
- );
- },
- //保存测试记录
- saveChat() {
- let list = [];
- for (let i = 0; i < this.chatContents.length; i++) {
- //先判断当前类型是form是左侧还是右侧
- //当是对话左侧的时候
- if (this.chatContents[i].from == 1) {
- if (this.chatContents[i].question !== "") {
- if (this.chatContents[i].isType == -1) {
- //存储进去
- let ob = {
- from: this.chatContents[i].from,
- question: this.chatContents[i].question,
- };
- list.push(ob);
- } else if (this.chatContents[i].isType == 0) {
- //如果是选择题选择题且必定是量表
- let ob = {
- from: 2,
- question: this.answerList[this.chatContents[i].index].checkItems,
- };
- list.push(ob);
- } else if (this.chatContents[i].isType == 5) {
- let ob = {
- from: 2,
- question: this.answerList[this.chatContents[i].index].checkItems,
- };
- list.push(ob);
- }
- }
- //判断是不是量表
- //如果是
- //则判断是选择题还是描述
- //如果是描述
- } else if (this.chatContents[i].from == 2) {
- //如果是选择题的话
- if (this.chatContents[i].isType == 0) {
- for (let j = 0; j < this.chatContents[i].question.length; j++) {
- if (
- this.chatContents[i].question[j].nextQuestionNo ==
- this.chatContents[i].radio
- ) {
- let ob = {
- from: 2,
- question: this.chatContents[i].question[j].answer,
- };
- list.push(ob);
- }
- }
- } else if (this.chatContents[i].isType == 1) {
- //如果是填空题
- let ob = {
- from: 2,
- question: this.chatContents[i].text,
- };
- list.push(ob);
- }
- //先看
- }
- }
- // console.log(JSON.stringify(list));
- //调用保存接口
- this.saveRealFun(list);
- },
- saveRealFun(list) {
- this.$http.post(
- `/chat/complete/chat`,
- {
- content: list,
- userName: sessionStorage.getItem("name"),
- label: this.interveneId,
- identifier: sessionStorage.getItem("num"),
- num: this.oNum,
- },
- (res) => {
- if (res.data.code == 200) {
- } else {
- that.$message.error("访问服务器失败!");
- }
- }
- );
- },
- init() {
- this.getQuestion(1, true);
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- },
- sendMessageFun(val) {
- if (val.text == "") {
- this.$message.warning("请输入内容");
- return;
- }
- // 若问题类型为3,校验输入值是否为0~100的整数
- if (val.isType == 3) {
- var a = val.text;
- var reg = new RegExp("^(\\d|[1-9]\\d|100)$");
- if (!reg.test(a)) {
- this.$message.warning("请输入0~100之间的整数");
- return;
- }
- }
- let id = val.question[0].nextQuestionNo;
- let questionNo = val.question[0].questionNo;
- this.chatContents[this.chatContents.length - 1] = {
- //是问题还是答案
- from: 2,
- //是否是量表的信息
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: -1,
- //可点击可不点击 0单选 1填空
- disabled: false,
- //问题
- question: val.text,
- //头像
- from1: HeadImg1,
- };
- //发送填空题
- if (!id == "") {
- let paramsSave = {
- label: 1,
- content: val.text,
- questionNo: questionNo,
- };
- //当标志是5时,则不需要保存
- if (this.interveneId != 5) {
- this.saveRecord(paramsSave);
- this.getQuestion(id, true);
- } else {
- //当标志是5时需要调用修改昵称接口
- //且当前问题编号为2时
- if (questionNo == "2") {
- console.log(123);
- this.updateName(val.text, id);
- }
- }
- } else {
- this.chatContents.push({
- //是问题还是答案
- from: 1,
- //是否是量表的信息
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: -1,
- //可点击可不点击 0单选 1填空
- disabled: false,
- //问题
- question: "对话结束",
- //头像
- from1: HeadImg,
- });
- // let paramsSave = {
- // label: 1,
- // content: val.text,
- // questionNo: questionNo,
- // };
- // this.saveRecord(paramsSave);
- // this.saveChat();
- // let contant1 = document.getElementById("contant1");
- // this.sleep(101).then(() => {
- // contant1.scrollTop = contant1.scrollHeight;
- // });
- }
- },
- updateName(val, id) {
- let that = this;
- let data = {
- identifier: sessionStorage.getItem("num"),
- userName: val,
- };
- this.$http.post(`/v1/user/updateUserName`, data, (res) => {
- console.log("updateUserName");
- if (res.data.code == 200) {
- //当等于5且编号的能够与
- that.getQuestion(id, false);
- } else {
- }
- });
- },
- // 获取问题
- //第二个参数判断是否是需要回显的,如果是数据已返回就不回显了
- //或保存,当第二个参数为true时需要保存,当第二个参数为false时不需要保存
- //第三个参数判断是否出现
- getQuestion(id, flag) {
- let that = this;
- if (this.interveneId == 4) {
- if (id == "109" || id == "117" || id == "119") {
- this.centerDialogVisible = true;
- }
- }
- this.$http.get(
- `chat/getQuestion/${that.interveneId}`,
- {
- id: id,
- num: this.oNum,
- },
- (res) => {
- if (res.code == "200") {
- console.log("res");
- console.log(res);
- console.log(that.interveneId);
- if (that.interveneId == 5 && id == 3) {
- // that.interveneId = that.$route.query.id;
- //然后再调用question
- // that.getQuestion("", true);
- }
- let result = res.data;
- // 若无下一题,oNum加1进入下一部分
- if (result == null) {
- this.oNum = this.oNum < 5 ? ++this.oNum : 1;
- this.endHandle();
- this.getQuestion(1, true);
- return;
- }
- if (result.num) {
- that.oNum = result.num;
- }
- if (result.question && result.question.includes("测评结果")) {
- debugger;
- //当时量表抑郁的时候是这样显示结果的
- // let str = sessionStorage.getItem("testResults");
- if (that.interveneId == 2) {
- let str = sessionStorage.getItem("testResultsScore");
- if (str <= 4) {
- result.question =
- "您的情绪状态得分在正常范围内。请继续保持积极心态,关注生活中的美好,预防抑郁情绪。如有需要,随时与我沟通,一起守护您的心理健康。";
- } else if (str >= 5 && str <= 9) {
- result.question =
- "您可能正经历轻度抑郁。请放心,我会为您提供专业的心理支持,帮助您调节情绪,及时缓解抑郁情绪。我们一起努力,让心情重回明朗。";
- } else if (str >= 10 && str <= 14) {
- result.question =
- "您的抑郁情绪较为明显。我强烈建议您接受专业的心理治疗,以改善当前状况。我会与您并肩作战,共同应对这个挑战,助您早日走出阴霾。";
- } else if (str >= 15 && str <= 19) {
- result.question =
- "您可能正面临严重的抑郁情绪。面对生活中的阴霾与挑战,我真诚地建议您考虑咨询心理医生或精神科医生,把自己从不适的情绪中分离出来。";
- } else if (str >= 20) {
- result.question =
- "您的抑郁程度较为严重。";
- }
- }
- if (that.interveneId == 1) {
- let str = sessionStorage.getItem("testResultsScore");
- if (str <= 4) {
- result.question =
- "您的情绪状态得分在正常范围内。请继续保持心态平和,有效管理压力。如有需要,随时与我沟通,一起守护您的心理健康。";
- } else if (str >= 5 && str <= 9) {
- result.question =
- "您可能正经历轻度焦虑。请放心,我会为您提供专业的心理支持,帮助您学习应对焦虑的技巧。一起努力,让您的心情更加轻松自在。";
- } else if (str >= 10 && str <= 14) {
- result.question =
- "您的焦虑情绪较为明显。我建议您接受系统的心理咨询,以减轻焦虑对您生活的影响。我也会与您同行,共克困难。";
- } else if (str >= 15) {
- result.question =
- "您目前有较为严重的焦虑情绪。我真诚地希望您接受专业的医疗和心理援助。我会全力支持您,与您一起应对这个挑战,直至您重获内心安宁。";
- }
- }
- if (that.interveneId == 3) {
- let str = sessionStorage.getItem("testResultsScore");
- if (str <= 5) {
- result.question =
- "您的睡眠质量非常优秀。请继续保持健康的睡眠习惯,确保充足的休息时间,以维持良好的睡眠质量和日间功能。如有任何变化,请随时与我沟通。";
- } else if (str >= 6 && str <= 10) {
- result.question =
- "您的睡眠质量较好。为了进一步提升睡眠品质,建议您关注睡眠环境,减少干扰因素。我会与您一同探讨更多优化睡眠的方法,让您的睡眠更加深沉和高效。";
- } else if (str >= 11 && str <= 15) {
- result.question =
- "您的睡眠质量有待提升。请放心,我会提供专业的指导,帮助您改善入睡困难、睡眠干扰等问题。通过共同努力,我们能够让您享受到更健康的睡眠";
- } else if (str >= 16) {
- result.question =
- "您的睡眠质量非常差,这可能对您的健康和日间功能造成了严重影响。我强烈建议您立即开始改善睡眠,包括调整作息时间、减少压力等。我会全力支持您,与您一起克服睡眠障碍,恢复良好的睡眠质量";
- }
- }
- if (that.interveneId == 4) {
- let str = sessionStorage.getItem("testResultsScore");
- if (str <= 49) {
- result.question =
- "您的得分在正常范围内,显示您目前的焦虑水平是正常的。请继续保持心态平和,有效管理压力。如有任何焦虑情绪出现,请及时与我沟通,共同守护您的心理健康。";
- } else if (str >= 50 && str <= 59) {
- result.question =
- "您可能有轻度焦虑。请放心,我会提供专业的心理支持,帮助您学习应对焦虑的技巧。一起努力,让您的心情更加轻松自在。";
- } else if (str >= 60 && str <= 69) {
- result.question =
- "您的焦虑症状已较明显。我建议您接受系统的心理咨询,如放松训练、认知重构等,以减轻焦虑对您生活的影响。我会与您同行,共克时艰。";
- } else if (str >= 70) {
- result.question =
- "您可能正面临严重的焦虑症状。我强烈建议您立即寻求专业医疗和心理援助。我会全力支持您,与您一起应对这个挑战,直至您重获内心的安宁。";
- }
- }
- // result.question = str;
- }
- if (result.id) {
- that.currentId = result.id;
- }
- // 将本次问题加入对话
- this.chatContents.push({
- //是问题还是答案
- from: 1,
- //是否是量表的信息
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: -1,
- //可点击可不点击 0单选 1填空
- disabled: false,
- //问题
- question: "",
- //头像
- from1: HeadImg,
- });
- this.pFun(result.question, true, result, flag, false);
- }
- }
- );
- },
- // 本轮对话结束
- endHandle() {
- this.$alert("本段对话结束", "提示", {
- showCancelButton: true,
- cancelButtonText: "结束对话",
- confirmButtonText: "继续对话",
- callback: (action) => {
- if ("confirm" == action) {
- this.getQuestion(1, true);
- } else if ("cancel" == action) {
- this.$router.go(-1);
- }
- },
- });
- },
- //修改文本打印效果
- pFun(val, flag, result, saveFlag, isShow) {
- clearInterval(this.flagTime);
- let that = this;
- //3个循环播放
- this.chatContents[this.chatContents.length - 1].question = "";
- this.printIndex = 0;
- // let a = val;
- let a = "......";
- if (this.interveneId != 5) {
- let paramsSave = {
- label: 0,
- content: result ? result.question : "",
- questionNo: result.id,
- };
- if (saveFlag) {
- this.saveRecord(paramsSave);
- }
- }
- this.flagTime = setInterval(
- () => {
- if (this.printIndex < a.length) {
- this.chatContents[this.chatContents.length - 1].question += a.charAt(
- this.printIndex
- );
- this.printIndex++;
- if (a == "......") {
- if (this.printIndex == 4) {
- this.chatContents[this.chatContents.length - 1].question = "";
- this.printIndex = 0;
- a = val;
- }
- }
- if (flag) {
- if (a != "......") {
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- // contant1.scrollTo({top:contant1.scrollHeight,behavior: 'smooth'});
- });
- }
- }
- } else {
- if (flag) {
- that.buttonFlag = false;
- //清除定时器
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- clearInterval(this.flagTime);
- //在这判断负面情绪是否足够5个
- if (this.interveneId != 5) {
- // let paramsSave = {
- // label: 0,
- // content: result ? result.question : "",
- // questionNo: result.id,
- // };
- // if (saveFlag) {
- // this.saveRecord(paramsSave);
- // }
- if (isShow) {
- this.chatContents.push({
- id: 123456789,
- from: 2,
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: 0,
- disabled: false,
- question: [
- {
- id: "123456789",
- createTime: null,
- updateTime: null,
- questionNo: "-200",
- nextQuestionNo: "-200",
- questionType: "0",
- answer: "继续上次",
- label: "2",
- },
- {
- id: "1234567890",
- createTime: null,
- updateTime: null,
- questionNo: "-201",
- nextQuestionNo: "-201",
- questionType: "0",
- answer: "重新开始",
- label: "2",
- },
- ],
- from1: HeadImg,
- radio: false,
- text: "",
- });
- return;
- }
- }
- // identifier: sessionStorage.getItem("num"),
- // label: val.label,
- // content: val.content,
- // userName:sessionStorage.getItem("name"),
- // questionNo: val.questionNo,
- // type: this.interveneId,
- if (this.interveneId == 5 && result.id == "3") {
- this.interveneId = that.$route.query.id;
- this.getQuestion("", true);
- return;
- }
- if (!result.nextQuestionNo) {
- // 无下一题,查询答案
- this.getAnswer(result.id);
- //保存所选问题的答案
- } else if (/flag/g.test(result.nextQuestionNo)) {
- // 下一题为量表,查询量表内容
- this.flag = result.nextQuestionNo.split("-")[1];
- this.getScaleInfo(this.flag);
- // this.flag = "20210617121646";
- // this.getScaleInfo("20210617121646");
- } else {
- // 下一题非量表,继续查询下一题
- this.getQuestion(result.nextQuestionNo, true);
- }
- } else {
- this.printIndex = 0;
- this.chatContents[this.chatContents.length - 1].question = ".";
- }
- }
- },
- flag ? 60 : 300
- );
- },
- // 获取答案
- getAnswer(id) {
- this.$http.get(
- `chat/getAnswer/${id}/${this.interveneId}/${this.oNum}`,
- {},
- (res) => {
- if (res.code == "200") {
- if (res.data.length > 0) {
- let result = res.data;
- if (parseInt(result[0].questionType) == 1) {
- this.chatContents.push({
- id: result[0].id,
- from: 2,
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: parseInt(result[0].questionType),
- disabled: false,
- question: result,
- from1: HeadImg,
- radio: false,
- text: "",
- });
- } else {
- this.chatContents.push({
- from: 2,
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: parseInt(result[0].questionType),
- disabled: false,
- question: result,
- from1: HeadImg,
- radio: false,
- text: "",
- });
- }
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- } else {
- this.oNum = this.oNum < 5 ? ++this.oNum : 1;
- this.endHandle();
- }
- }
- }
- );
- },
- // 获取量表信息
- getScaleInfo(flag) {
- this.$http.get(`v1/scale/${flag}`, {}, (res) => {
- let data = res.data;
- let anwserListx = [];
- for (var i = 0; i < data.length; i++) {
- // if(data[i].questionType=='5'){
- // }
- anwserListx.push({
- answer: data[i].answer,
- checkItems: "",
- flag: data[i].flag,
- id: data[i].id,
- questionNo: data[i].questionNo,
- questionType: data[i].questionType,
- score: data[i].score,
- scoreDirection: data[i].scoreDirection,
- serialNo: data[i].serialNo,
- weight: data[i].weight,
- questionParam: data[i].questionParam,
- });
- }
- this.questionList = res.data;
- this.answerList = anwserListx;
- this.scaleTestStart = true;
- let checkItems = data[0].checkItems;
- //先判断时哪个类型
- //正常时是发布的类型是 描述和单选 --但是现在多一个特别的单选
- //
- this.chatContents.push({
- from: 1,
- isScale: true,
- disabled: false,
- isType: -1,
- question: data[0].answer,
- from1: HeadImg,
- });
- //当 questionType==0时 当questionType==5时
- if (data[0].questionType == 0) {
- this.chatContents.push({
- index: 0,
- from: 2,
- disabled: false,
- isScale: true,
- isType: 0,
- question: checkItems.split(";"),
- from1: HeadImg,
- });
- } else if (data[0].questionType == 5) {
- let dataTmp = JSON.parse(data[0].questionParam);
- let checkIt = "";
- for (let i = 0; i < dataTmp.length; i++) {
- if (dataTmp.length - 1 == i) {
- checkIt += dataTmp[i].label;
- } else {
- checkIt += dataTmp[i].label + ";";
- }
- }
- this.chatContents.push({
- index: 0,
- from: 2,
- disabled: false,
- isScale: true,
- isType: 5,
- question: checkIt.split(";"),
- from1: HeadImg,
- });
- }
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- });
- },
- // 选择答案
- chooseAnswer(val) {
- let id = val.radio;
- if (id == "-200") {
- //上一次的id
- this.chatContents[this.chatContents.length - 1] = {
- from: 2,
- isScale: false,
- isType: -1,
- question: "继续上次",
- from1: HeadImg,
- };
- this.getQuestion(this.preQuestion, false);
- return;
- }
- if (id == "-201") {
- this.chatContents[this.chatContents.length - 1] = {
- from: 2,
- isScale: false,
- isType: -1,
- question: "重新开始",
- from1: HeadImg,
- };
- this.oNum = 1;
- this.getQuestion(1, false);
- return;
- }
- console.log("下一题编号");
- console.log(id);
- //循环这个数组得到选择的答案
- let questionRadio = val.question;
- let contentRadio = "";
- let questionNo = "";
- for (let i = 0; i < questionRadio.length; i++) {
- if (questionRadio[i].nextQuestionNo == id) {
- contentRadio = questionRadio[i].answer;
- questionNo = questionRadio[i].questionNo;
- }
- }
- let paramsSave = {
- label: 1,
- content: contentRadio,
- questionNo: questionNo,
- };
- //当编号是5时不需要保存
- if (this.interveneId != 5) {
- this.saveRecord(paramsSave);
- }
- if (id == "") {
- this.chatContents.push({
- //是问题还是答案
- from: 1,
- //是否是量表的信息
- isScale: false,
- //是单选还是文字 0单选 1填空 -1描述
- isType: -1,
- //可点击可不点击 0单选 1填空
- disabled: false,
- //问题
- question: "对话结束",
- //头像
- from1: HeadImg,
- });
- // this.saveChat();
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- } else {
- //上一次的id
- this.chatContents[this.chatContents.length - 1] = {
- from: 2,
- isScale: false,
- isType: -1,
- question: contentRadio,
- from1: HeadImg,
- };
- this.getQuestion(id, true);
- }
- },
- // 量表选中切换下一题
- nextHandle(i) {
- this.chatContents[i].disabled = true;
- if (i < this.questionList.length - 1) {
- let ttmp = this.answerList[i].checkItems;
- this.chatContents[this.chatContents.length - 1] = {
- from: 2,
- isScale: false,
- isType: -1,
- question: ttmp,
- from1: HeadImg,
- };
- i = i + 1;
- let checkItems = this.questionList[i].checkItems;
- this.chatContents.push({
- index: i,
- from: 1,
- isScale: true,
- isType: -1,
- question: this.questionList[i].answer,
- from1: HeadImg,
- });
- if (this.questionList[i].questionType == 0) {
- this.chatContents.push({
- index: i,
- from: 2,
- isScale: true,
- isType: 0,
- question: checkItems.split(";"),
- from1: HeadImg,
- });
- } else if (this.questionList[i].questionType == 5) {
- let dataTmp = JSON.parse(this.questionList[i].questionParam);
- let checkIt = "";
- for (let j = 0; j < dataTmp.length; j++) {
- if (dataTmp.length - 1 == j) {
- checkIt += dataTmp[j].label;
- } else {
- checkIt += dataTmp[j].label + ";";
- }
- }
- this.chatContents.push({
- index: i,
- from: 2,
- isScale: true,
- isType: 5,
- question: checkIt.split(";"),
- from1: HeadImg,
- });
- }
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- } else {
- let ttmp = this.answerList[i].checkItems;
- this.chatContents[this.chatContents.length - 1] = {
- from: 2,
- isScale: false,
- isType: -1,
- question: ttmp,
- from1: HeadImg,
- };
- this.getScaleResult(this.flag);
- }
- },
- // 提交测试结果
- getScaleResult(flag) {
- this.$http.post(
- `v1/result/${flag}`,
- {
- scale_result: this.answerList,
- identifier: sessionStorage.getItem("num"),
- },
- (res) => {
- if (res.data.code == 200) {
- this.resultQuery(res.data.data);
- } else {
- that.$message.error("访问服务器失败!");
- }
- }
- );
- },
- // 查询测试结果
- resultQuery(id) {
- this.$http.post(`v1/record/find/${id}`, {}, (res) => {
- if (res.data.code == 200 && res.data.data) {
- this.resultJsonParams = res.data.data;
- let testResult = JSON.parse(res.data.data.userRecordEntity.testResult);
- sessionStorage.setItem(
- "testResults",
- res.data.data.userRecordEntity.testResults
- );
- // console.log(res.data.data.userRecordEntity.testResults);
- // console.log(testResult);
- if (this.interveneId == 1) {
- let score = Number(testResult[0].newTableContext.result[0].score);
- sessionStorage.setItem("testResultsScore", score);
- this.getNext(this.currentId);
- } else if (this.interveneId == 2) {
- let score = Number(testResult[0].newTableContext.result[0].score);
- sessionStorage.setItem("testResultsScore", score);
- this.getNext(this.currentId);
- } else if (this.interveneId == 3) {
- debugger;
- // let score = Number(testResult[0].newTableContext.result[0].score);
- let score = Number(testResult[0].tableContext[7].value[0]);
- sessionStorage.setItem("testResultsScore", score);
- this.getNext(this.currentId);
- // this.chatContents.push({
- // from: 1,
- // isScale: false,
- // isType: -1,
- // question: res.data.data.userRecordEntity.testResults,
- // from1: HeadImg,
- // });
- // this.getQuestion(44, true);
- } else if (this.interveneId == 4) {
- debugger;
- let score = Number(testResult[0].tableContext[0].value[0]);
- sessionStorage.setItem("testResultsScore", score);
- this.getNext(this.currentId);
- // this.chatContents.push({
- // from: 1,
- // isScale: false,
- // isType: -1,
- // question: res.data.data.userRecordEntity.testResults,
- // from1: HeadImg,
- // });
- // this.getQuestion(46, true);
- }
- }
- });
- },
- getNext(result) {
- this.$http.get(
- `chat/getNextQuestionByScaleResult?label=${this.interveneId}&result=${result}&num=${this.oNum}`,
- {},
- (res) => {
- if (res.code == 200) {
- if (res.data && res.data.nextQuestionNo) {
- this.getQuestion(res.data.nextQuestionNo, true);
- }
- }
- }
- );
- },
- sleep(time) {
- return new Promise((resolve) => setTimeout(resolve, time));
- },
- sendMsg() {
- this.sendMsgFlag = false;
- let contant1 = document.getElementById("contant1");
- let tmp = {
- from: 2,
- isScale: false,
- answer: this.desc,
- from1: HeadImg,
- };
- this.chatContents.push(tmp);
- // 让滚动条始终在最底部
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- //第一个问题出来后先对答案进行解析
- this.selectMood(this.desc);
- this.desc = "";
- },
- //调用接口查询情绪
- selectMood(val) {
- // this.sendMsgFlag=true;
- let that = this;
- axios.post(`http://127.0.0.1:9999/sentiment`, { text: val }).then((res) => {
- that.sendMsgFlag = true;
- that.threeAnswers.push(res.data.sentiment);
- //是否问问题的标志
- //当答案小于3时需要接着提问
- if (that.threeAnswers.length < 3) {
- that.askQuestions();
- } else if (that.threeAnswers.length === 3) {
- //当等于3时需要判断是否接着提问
- //当负面情绪小于2时则终止询问
- //当负面情绪大于等于2时需要再次提问
- that.judgeMood(2);
- } else if (that.threeAnswers.length === 4) {
- //当问题等于4时再次询问
- that.askQuestions();
- } else if (that.threeAnswers.length === 5) {
- //调用判断结果负面情绪是否大于等于3
- that.judgeMood(3);
- }
- //当回答的答案大于等于3时判断是否结束,当负面情绪大于等于2时
- // that.judgeMood();
- });
- },
- //当回答的答案大于等于3时判断是否结束,当负面情绪大于等于2时
- judgeMood(val) {
- this.moonNegative = 0;
- for (let i = 0; i < this.threeAnswers.length; i++) {
- if (
- this.threeAnswers[i] === "厌恶" ||
- this.threeAnswers[i] === "恐惧" ||
- this.threeAnswers[i] === "悲伤" ||
- this.threeAnswers[i] === "愤怒"
- ) {
- this.moonNegative += 1;
- }
- }
- if (this.moonNegative >= val) {
- if (val === 2) {
- //需要再拿根据情绪生成两个数据
- //如果是2个负面
- //循环情绪得到判断哪一个是负面情绪
- for (let j = 0; j < this.threeAnswers.length; j++) {
- if (
- this.threeAnswers[j] === "厌恶" ||
- this.threeAnswers[j] === "恐惧" ||
- this.threeAnswers[j] === "悲伤" ||
- this.threeAnswers[j] === "愤怒"
- ) {
- //调用方法进行测试
- this.afterListFun(this.preList[j].type);
- }
- }
- this.askQuestions();
- } else {
- this.inputFlag = 2;
- //进行提问
- this.chatContents.push({
- from: 1,
- isScale: false,
- question: "请问您近期是否存在以下方面的困扰(请选择)",
- from1: HeadImg,
- });
- this.scale_checkItems = ["抑郁", "焦虑", "压力", "睡眠问题", "无"];
- }
- } else {
- //发送一条信息说你的心理状态良好
- this.askEnd("您的心理状态良好请继续保持!");
- this.inputFlag = 0;
- }
- },
- selectRadio(val) {
- this.answerSelect(val);
- if (val === "无") {
- this.askEnd("您可能存在心理健康方面问题,建议寻求专业人员的指导");
- this.inputFlag = 0;
- //隐藏选项框和输入框进行提示
- } else if (val === "睡眠问题") {
- this.inputFlag = 3;
- this.askEnd(
- "为了进一步判断您是否存在睡眠方面的问题,下面我会问您一些问题,请您选择作答"
- );
- // this.askEnd("睡眠问卷");
- this.scale_checkItems = ["好的"];
- this.inputFlag = 2;
- this.scale_flag = "20210910163158";
- // this.selectScale(this.scale_flag);
- //调用接口睡眠量表
- } else if (val === "抑郁" || val === "焦虑" || val === "压力") {
- if (val === "抑郁") {
- this.pressure_flag = "抑郁";
- }
- if (val === "焦虑") {
- this.pressure_flag = "焦虑";
- }
- if (val === "压力") {
- this.pressure_flag = "压力";
- }
- this.inputFlag = 3;
- this.askEnd(
- "为了进一步判断您是否存在心理健康方面的问题,下面我会问您一些问题,请您选择作答"
- );
- // this.askEnd("抑郁、焦虑、压力问卷");
- this.scale_checkItems = ["好的"];
- this.inputFlag = 2;
- this.scale_flag = "20220805135201";
- // this.selectScale(this.scale_flag);
- //调用接口抑郁焦虑压力问卷
- } else if (val === "好的") {
- this.inputFlag = 3;
- // if(this.scale_flag==='20210910163158'){
- // }
- this.selectScale(this.scale_flag);
- } else if (val === "是") {
- //从头开始
- this.init("reStart");
- this.inputFlag = 1;
- } else if (val === "否") {
- //结束测试
- this.askEnd("对话结束");
- this.inputFlag = 0;
- }
- },
- choiceTriger(item) {
- let that = this;
- that.radioChange(item);
- },
- // 选中选项
- radioChange(item) {
- this.tmpRadio = item;
- var scaleInfoTemp = Object.assign({}, this.scale_infos[this.scale_index]);
- this.radio = "";
- scaleInfoTemp.checkItems = item;
- this.scale_result.push(scaleInfoTemp);
- // bbc测试判断是否展示20~24题
- if (item != "是" && this.scale_flag == "20211101163739" && this.scale_index == 19) {
- this.scale_index = 24;
- for (let i = 20; i < 24; i++) {
- this.scale_result.push(this.scale_infos[i]);
- }
- this.scale_checkItems = this.scale_infos[this.scale_index].checkItems.split(";");
- return;
- }
- //如果是单选题
- if (scaleInfoTemp.questionType == "0") {
- if (this.scale_index <= this.scale_infos.length - 1) this.scale_index += 1;
- this.answerSelect(this.tmpRadio);
- //scale_index == 题目总数,表示结束
- if (this.scale_index == this.scale_infos.length) {
- this.scale_index -= 1;
- this.scaleSelectFlag = false;
- //发送测试结果给后台
- // this.$message({
- // message: "测试完成,即将生成测试报告!",
- // type: "success",
- // });
- // console.log("==--3--------->", this.testPlanId);
- console.log(
- "==---4-------->",
- sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f")
- );
- this.$http.post(
- `v1/result/${this.scale_flag}`,
- {
- scale_result: this.scale_result,
- identifier: sessionStorage.getItem("num"),
- },
- (res) => {
- this.next_and_last_button = false;
- if (res.data.code == 200) {
- this.resultJson = res.data.data;
- if (this.scale_flag == "20210725100704") {
- } else {
- this.getAnswerQuestionPaymentSuccess(this.resultJson);
- }
- } else {
- this.$message.error("访问服务器失败!");
- }
- }
- );
- } else {
- // 我觉得很难让自己安静下来
- this.askEnd(this.scale_infos[this.scale_index].answer);
- this.scale_checkItems = this.scale_infos[this.scale_index].checkItems.split(
- ";"
- );
- }
- }
- },
- getAnswerQuestionPaymentSuccess(id) {
- // sessionStorage.setItem("back_page", "1");
- let _this = this;
- _this.$http.post(`v1/record/find/${id}`, {}, (res) => {
- _this.scaleSelectFlag = true;
- if (res.data.code == 200 && res.data.data) {
- _this.resultJsonParams = res.data.data;
- let testResult = JSON.parse(res.data.data.userRecordEntity.testResult)[0]
- .version;
- if (_this.scale_flag === "20210910163158") {
- let sleep = JSON.parse(_this.resultJsonParams.userRecordEntity.testResult);
- sleep = sleep[0].newTableContext.result[0].improvementSuggestions;
- _this.askEnd(sleep);
- _this.askEnd("您还想跟我再聊一聊吗?");
- this.scale_checkItems = ["是", "否"];
- this.inputFlag = 2;
- }
- if (_this.scale_flag === "20220805135201") {
- let sleep = JSON.parse(_this.resultJsonParams.userRecordEntity.testResult);
- sleep = sleep[0].tableContext;
- let str = "";
- for (let i = 0; i < sleep.length; i++) {
- if (_this.pressure_flag === "压力") {
- if (sleep[i].name === "压力指导语") {
- str = "压力建议:" + sleep[i].value[0] + " ";
- }
- }
- if (_this.pressure_flag === "焦虑") {
- if (sleep[i].name === "焦虑指导语") {
- str = "焦虑建议:" + sleep[i].value[0] + " ";
- }
- }
- if (_this.pressure_flag === "抑郁") {
- if (sleep[i].name === "抑郁指导语") {
- str = "抑郁建议:" + sleep[i].value[0] + " ";
- }
- }
- // if (sleep[i].name === "压力建议") {
- // str += "压力建议:" + sleep[i].value[0] + " ";
- // }
- // if (sleep[i].name === "焦虑建议") {
- // str += "焦虑建议:" + sleep[i].value[0] + " ";
- // }
- // if (sleep[i].name === "抑郁建议") {
- // str += "抑郁建议:" + sleep[i].value[0] + " ";
- // }
- }
- _this.askEnd(str);
- _this.askEnd("您还想跟我再聊一聊吗?");
- this.scale_checkItems = ["是", "否"];
- this.inputFlag = 2;
- }
- // let testResult = JSON.parse(
- // res.data.data.userRecordEntity.testResult
- // )[0].version;
- // if (testResult == 2) {
- // _this.$router.push({
- // name: "scaleResultSCl",
- // params: { tableData: _this.resultJsonParams }
- // });
- // } else {
- // _this.$router.push({
- // name: "scaleResult",
- // params: { tableData: _this.resultJsonParams }
- // });
- // }
- }
- });
- },
- //调用查询量表的接口
- //20210910163158 睡眠状况自评量表
- //20220805135201 抑郁-焦虑-压力量表简版(DASS-21)
- selectScale(flag) {
- this.$http.get(`v1/scale/${flag}`, {}, (res) => {
- this.scale_infos = res.data;
- console.log(this.scale_infos);
- this.scale_all = this.scale_infos.length;
- this.askEnd(this.scale_infos[this.scale_index].answer);
- this.scale_checkItems = this.scale_infos[this.scale_index].checkItems.split(";");
- console.log(this.scale_checkItems);
- this.scale_percent = parseInt((this.scale_index + 1) / this.scale_all);
- this.scale_percent = ((this.scale_index + 1) * 100) / this.scale_all;
- });
- },
- askEnd(val) {
- this.chatContents.push({
- from: 1,
- isScale: false,
- question: val,
- from1: HeadImg,
- });
- let contant1 = document.getElementById("contant1");
- this.sleep(101).then(() => {
- contant1.scrollTop = contant1.scrollHeight;
- });
- },
- answerSelect(val) {
- this.chatContents.push({
- from: 2,
- isScale: false,
- answer: val,
- from1: HeadImg,
- });
- },
- askQuestions() {
- this.chatContents.push({
- from: 1,
- isScale: false,
- question: this.preList[this.threeAnswers.length].des,
- from1: HeadImg,
- });
- this.questionNum++;
- },
- goBack() {
- this.$router.go(-1);
- },
- //判断是否是是已婚
- //如果是已婚
- //取随机数1-5否则取1-7
- //格式为需要新加一个情绪判断
- getDom() {
- //判断是否是已婚
- ////已婚0 未婚 1 离异 2
- let married = sessionStorage.getItem("isMarried");
- if (married == "0") {
- //从7个中抽取3个
- console.log(this.getDomList(3, 7));
- } else {
- //从5个中抽取三个
- this.getDomList(3, 5);
- }
- },
- //val抽取几个,totol总共数据
- getDomList(val, totol) {
- let arr = [];
- while (arr.length < val) {
- let num = parseInt(Math.random() * totol + 1);
- // parseInt取正,小数点后面的数字全部抹掉
- // Math.random() 0-1的随机数
- if (arr.indexOf(num) == -1) {
- // this.arr.indexOf(num)若等于-1则证明arr这个数组里没有num这个随机数,因此可以放进这个数组里
- arr.push(num);
- }
- }
- //循环的数组的到想要的那三个问题
- for (let i = 0; i < arr.length; i++) {
- this.switchFun(arr[i]);
- }
- return arr;
- },
- afterListFun(val) {
- let listLin = [];
- //this.preList[val].type
- switch (val) {
- case "1-1":
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "2-1") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case "1-2":
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "2-2") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case "1-3":
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "2-3") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case "1-4":
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "2-4") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case "1-5":
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "2-5") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case "1-6":
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "2-6") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case "1-7":
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "2-7") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- }
- },
- switchFun(val) {
- let listLin = [];
- console.log(val);
- // let listOne = [];
- // if (numKey == 1) {
- // listOne = ["1-1", "1-2", "1-3", "1-4", "1-5", "1-6", "1-7"];
- // } else {
- // listOne = ["2-1", "2-2", "2-3", "2-4", "2-5", "2-6", "2-7"];
- // }
- switch (val) {
- case 1:
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "1-1") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case 2:
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "1-2") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case 3:
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "1-3") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case 4:
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "1-4") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case 5:
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "1-5") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case 6:
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "1-6") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- case 7:
- {
- for (let i = 0; i < this.questionList.length; i++) {
- if (this.questionList[i].type == "1-7") {
- listLin.push(this.questionList[i]);
- }
- }
- //根据获数组长度获取随机数
- let len = parseInt(Math.random() * listLin.length);
- this.preList.push(listLin[len]);
- }
- break;
- }
- },
- questionFun() {
- let tmp = [];
- let value = null;
- let flag = true;
- while (flag) {
- if (tmp.length === 0) {
- value = Math.floor(Math.random() * 49);
- tmp.push(value);
- } else {
- value = Math.floor(Math.random() * 49);
- let repeat = false; //是否重复
- for (let i = 0; i < tmp.length; i++) {
- if (value == tmp[i]) {
- repeat = true;
- break;
- }
- }
- if (!repeat && tmp.length < 5) {
- tmp.push(value);
- if (tmp.length === 5) {
- flag = false;
- }
- }
- }
- }
- return tmp;
- },
- },
- };
- </script>
- <style scoped>
- .mainTable-top {
- margin-top: 5%;
- }
- .mainTable-top-two {
- margin-top: 10%;
- }
- .mainTable-tab {
- cursor: pointer;
- margin-left: 100px;
- margin-right: 100px;
- border-radius: 5px;
- border: 1px solid #000000;
- text-align: center;
- height: 150px;
- margin-bottom: 100px;
- }
- .mainTable-tab-p {
- padding-top: 40px;
- }
- .musicTitle {
- display: block;
- font-size: 18px;
- color: #57acbb;
- margin-bottom: 5px;
- }
- .main_answer_left {
- display: flex;
- /* text-align: left; */
- }
- .main_answer_right {
- display: flex;
- /* text-align: right; */
- }
- .message-wrapper {
- background-color: #ffffff;
- }
- .message-wrapper-left {
- margin-left: 10px;
- /* border-radius: 0 1rem 1rem 1rem; */
- border-radius: 4px 4px 4px 4px;
- max-width: 20.86667rem;
- display: inline-table;
- }
- .message-wrapper-right {
- margin-right: 10px;
- border-radius: 4px 4px 4px 4px;
- max-width: 20.86667rem;
- display: inline-table;
- /* background-color: #1fd18e; */
- color: #ffffff;
- /* margin-top: 25px; */
- padding: 18px;
- }
- .message {
- word-break: break-all;
- padding: 18px;
- /* font-size: 20px; */
- }
- .message_form2 {
- word-break: break-all;
- /* font-size: 20px; */
- }
- .xl_d_button {
- background: rgb(87, 172, 187);
- opacity: 1;
- border-radius: 50%;
- font-size: 20px;
- font-family: PingFang SC;
- font-weight: 400;
- color: #ffffff;
- width: 40px;
- line-height: 40px;
- text-align: center;
- }
- .xl_d_button:hover {
- background: rgb(87, 172, 187);
- opacity: 1;
- /* border-radius: 18px; */
- font-size: 14px;
- font-family: PingFang SC;
- font-weight: 400;
- color: #ffffff;
- }
- .xl_d_button:focus {
- background: rgb(87, 172, 187);
- opacity: 1;
- /* border-radius: 18px; */
- font-size: 14px;
- font-family: PingFang SC;
- font-weight: 400;
- color: #ffffff;
- }
- .refrshSmart {
- float: right;
- cursor: pointer;
- }
- .xl_input >>> .el-input__inner {
- border: 0;
- border-radius: 4px;
- background-color: #f4f4f4;
- }
- .footSend {
- background: #ffffff;
- position: absolute;
- height: 80px;
- margin-left: 2%;
- width: 90%;
- border-radius: 14px;
- bottom: 50px;
- }
- .smart_line_class {
- /* background: #BBC5D4; */
- position: absolute;
- height: 1px;
- margin-left: 2%;
- width: 90%;
- border-radius: 14px;
- bottom: 150px;
- border-bottom: 1px solid #bbc5d4;
- }
- .footSend >>> .el-textarea__inner {
- border: 0px solid #ffffff !important;
- border-radius: 14px !important;
- }
- .footSendSelect {
- background: #ffffff;
- /* padding-bottom: 40px; */
- position: absolute;
- margin-left: 2%;
- width: 90%;
- bottom: 40px;
- }
- .xl_d_send {
- margin-top: 18px;
- color: #087b50;
- background: #c6f0ed !important;
- opacity: 1;
- font-size: 14px;
- font-family: PingFang SC;
- font-weight: 400;
- text-align: center;
- border: 0px;
- border-radius: 10px;
- }
- .xl_d_send:hover {
- margin-top: 18px;
- color: #087b50;
- background: #c6f0ed !important;
- opacity: 1;
- font-size: 14px;
- font-family: PingFang SC;
- font-weight: 400;
- text-align: center;
- border-radius: 10px;
- }
- .xl_d_send:focus {
- margin-top: 18px;
- color: #087b50;
- background: #c6f0ed !important;
- opacity: 1;
- font-size: 14px;
- font-family: PingFang SC;
- font-weight: 400;
- text-align: center;
- border-radius: 10px;
- }
- .xl_d_send.is-disabled,
- .xl_d_send.is-disabled:hover,
- .xl_d_send.is-disabled:focus {
- margin-top: 18px;
- color: #087b50;
- background: #c6f0ed !important;
- opacity: 1;
- font-size: 14px;
- font-family: PingFang SC;
- font-weight: 400;
- text-align: center;
- border-radius: 10px;
- }
- .main_right_height {
- /* padding:40px; */
- height: 100vh !important;
- display: block !important;
- overflow-y: auto !important;
- background-color: #ffffff;
- }
- .smart_content {
- height: 88%;
- margin-top: 5%;
- width: 94%;
- margin-left: 3%;
- border-radius: 40px;
- background: #f6f6f6;
- /* display:flex; */
- }
- .chat-window {
- height: 82vh;
- overflow: auto;
- /* overflow-y:hidden; */
- }
- /* .contant1{
- height:70vh;
- overflow:auto;
- } */
- ::v-deep .el-radio.is-bordered + .el-radio.is-bordered {
- display: block;
- margin: 10px 0 0 0;
- }
- .send_class {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- </style>
|