WXL
2024-11-01 0c26cb58f143c56f3753f4745519502222cde4ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<template>
  <!-- 聊连页面记录 -->
  <div class="Followupdetailspage">
    <div>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>{{ TemplateName }}</span>
          <el-button
            style="float: right; padding: 3px 0; color: red"
            type="text"
            @click="$router.go(-1)"
            >退出测试</el-button
          >
          <el-button
            style="float: right; padding: 3px 0; margin-right: 10px"
            type="text"
            @click="drawer = true"
            >查看匹配结果</el-button
          >
        </div>
        <div class="borderdiv">
          <div v-for="item in Answerline">
            <div class="leftside" v-if="item.isEat == 1">
              <i class="el-icon-phone-outline"></i><span>{{ item.value }}</span>
            </div>
            <div class="offside" v-else-if="item.isEat == 2">
              <i class="el-icon-user"></i>
              <div class="offside-value">
                <el-input :disabled="true" v-model="item.value"></el-input>
              </div>
            </div>
            <div class="offside" v-else-if="item.isEat == 3">
              <i class="el-icon-user"></i>
              <div class="offside-value">
                <el-input v-model="item.value"></el-input>
                <el-radio v-model="radio" label="1">备选项</el-radio>
                <el-radio v-model="radio" label="2">备选项2</el-radio>
                <el-radio v-model="radio" label="3">备选项3</el-radio>
                <el-radio v-model="radio" label="4">备选项4</el-radio>
              </div>
            </div>
          </div>
        </div>
        <div style="margin-top: 15px">
          <el-input
            placeholder="请输入内容"
            @keyup.enter.native="sendFn"
            v-model="answer"
          >
            <el-button
              style="background-color: #7799fa; color: #ffff; border: 0"
              @click="sendFn"
              slot="append"
              type="primary"
              >发送</el-button
            >
          </el-input>
        </div>
      </el-card>
      <el-drawer title="匹配结果" :visible.sync="drawer" direction="rtl">
        <div class="preview-left">
          <!-- 单选 -->
          <div
            class="topic-dev"
            v-for="(item, index) in questionList"
            :key="item.aaa"
          >
            <div class="dev-text">
              {{ index + 1 }}、<span>{{ item.scriptContent }}</span>
            </div>
 
            <div class="dev-xx" v-if="item.valueType == 1">
              <el-radio-group v-model="item.radio">
                <el-radio
                  v-for="(items, index) in item.ivrLibaScriptTargetoptionList"
                  :key="items.id"
                  :label="items.id"
                  >{{ items.targetvalue }}</el-radio
                >
              </el-radio-group>
            </div>
            <div v-else>
              <el-input
                type="textarea"
                placeholder="未获取到信息"
                v-model.sync="item.questionResult"
                :rows="2"
              />
            </div>
          </div>
        </div>
      </el-drawer>
    </div>
  </div>
</template>
 
<script>
import {
  sendWebsocket,
  websocketSend,
  closeWebsocket,
} from "@/websocket/websocket.js";
import store from "@/store";
export default {
  data() {
    return {
      answer: "", //回答
      id: null,
      TemplateName: "随访模板名称", //模板名
      radio: "1",
      userid: "",
      input: "还不错",
      drawer: false,
      radio: "2",
      code: "",
      timeout: "5",
      Answerline: [],
      questionList: [],
    };
  },
 
  created() {
    this.TemplateName = this.$route.query.name;
    this.userid = store.getters.Id;
    console.log(store.getters.Id,'11');
 
    this.requstWs(); //进入页面创建连接
  },
  mounted() {
    // 获取class为borderdiv的元素
    const borderdiv = document.querySelector(".borderdiv");
 
    // 创建一个MutationObserver实例,用于监听元素的变化
    const observer = new MutationObserver(() => {
      // 当元素高度变化时,将滚动条滚动到最下方
      borderdiv.scrollTop = borderdiv.scrollHeight;
    });
 
    // 配置MutationObserver实例的观察目标和观察选项
    observer.observe(borderdiv, {
      attributes: true,
      childList: true,
      subtree: true,
    });
 
    // 当不再需要监听时,可以使用disconnect方法停止观察
    // observer.disconnect();
  },
 
  methods: {
    // 建立连接
    requstWs(message, next, file) {
      console.log("连接");
      this.id = this.$route.query.id;
      this.timeout = this.$route.query.timeout;
      // 防止用户多次连续点击发起请求,所以要先关闭上次的ws请求。
      closeWebsocket();
      console.log(this.id);
      const obj = {
        type: "text",
        userId: this.userid,
        templateId: this.id,
        content: null,
      };
      // 发起ws请求
      sendWebsocket(
        "ws://192.168.2.13:8095/chat?userId="+this.userid,
        obj,
        this.wsMessage,
        this.wsError
      );
    },
    // 接收ws返回的数据
    wsMessage(data) {
      let dataJson = data;
      let timerId = null;
      dataJson = JSON.parse(dataJson);
      dataJson = JSON.parse(dataJson);
      console.log(dataJson, "数据");
      // 首次接收数据
      // if (!this.Answerline[0]) {
      //   this.Answerline.push({
      //     value: dataJson.kcb,
      //     isEat: 1,
      //   });
      // }
      timerId = setTimeout(() => {
        if (!this.answer) {
          this.sendFn(); // 后调用
        }
      }, this.timeout * 1000);
      if (condition) {
 
      }
      // clearTimeout(timerId)
      // 优先加入通用库匹配文本
      if (dataJson.nowQuestion.submoduleText) {
        this.Answerline.push({
          value: dataJson.nowQuestion.submoduleText,
          isEat: 1,
        });
      }
      // 是否结束
      if (dataJson.jsy) {
        this.Answerline.push({
          value: dataJson.jsy,
          isEat: 1,
        });
      } else if (dataJson.nowQuestion.scriptContent) {
        this.Answerline.push({
          value: dataJson.nowQuestion.scriptContent,
          isEat: 1,
        });
      }
      this.questionList = dataJson.questionList;
      this.questionList = this.questionList.map((item) => {
        item.ivrLibaScriptTargetoptionList.forEach((row) => {
          if (row.isUserOperation) {
            item.radio = row.id;
          }
        });
        return item;
      });
      console.log(this.questionList);
 
      // IMUI.appendMessage(data);
    },
    //ws错误回调
    wsError(data) {
      console.log(data);
    },
 
    sendFn() {
      console.log("发送");
 
      // 消息发送
      const obj = {
        type: "text",
        userId: this.userid,
        templateId: "",
        questionMessage: { content: this.answer },
      };
      console.log(obj, "入参");
      // 发起ws请求
      sendWebsocket(
        "ws://192.168.2.13:8095/chat?userId="+this.userid,
        obj,
        this.wsMessage,
        this.wsError
      );
      this.Answerline.push({
        value: this.answer,
        isEat: 2,
      });
      this.answer = "";
    },
  },
};
</script>
 
<style lang="scss" scoped>
.Followupdetailspage {
  margin: 10px;
}
.Followuserinfo {
  margin: 20px 10px;
  align-items: center;
  padding: 30px;
  background: #ffff;
  border: 1px solid #dcdfe6;
  -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
    0 0 6px 0 rgba(0, 0, 0, 0.04);
  .userinfo-text {
    font-size: 20px;
    margin-right: 20px;
    margin-bottom: 10px;
  }
  .userinfo-value {
    color: rgb(15, 139, 211);
    span {
      margin-right: 20px;
    }
  }
}
.borderdiv {
  height: 100vh;
  font-size: 20px;
  padding: 30px;
  max-height: 700px;
  overflow: auto;
  .leftside {
    margin-bottom: 30px;
    max-width: 566px;
    margin-left: 20px;
    padding: 10px;
    color: #fff;
    background: rgb(110, 196, 247);
    border-radius: 10px;
    span {
      word-wrap: break-word;
    }
  }
  .offside {
    display: flex;
    flex-direction: row-reverse;
    margin-bottom: 10px;
    .offside-value {
      padding: 10px;
      background: rgb(217, 173, 253);
      border-radius: 10px;
      color: #fff;
      margin-right: 20px;
    }
  }
}
.preview-left {
  margin: 20px;
  //   margin: 20px;
  padding: 30px;
  background: #ffff;
  border: 1px solid #dcdfe6;
  -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
    0 0 6px 0 rgba(0, 0, 0, 0.04);
  .topic-dev {
    margin-bottom: 25px;
    font-size: 20px !important;
    .dev-text {
      margin-bottom: 10px;
    }
  }
}
::v-deep.offside-value .el-radio__label {
  color: #fff;
}
::v-deep.el-input.is-disabled .el-input__inner {
  background-color: #fff;
  border-color: #dfe4ed;
  color: #000;
  cursor: not-allowed;
}
.mulsz {
  font-size: 25px;
  margin-top: 20px;
}
.text {
  font-size: 14px;
}
 
.item {
  margin-bottom: 18px;
}
.clearfix {
  font-size: 20px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
</style>