riku
2022-09-14 2206df0da6499846c78a358cf95ca33c218a5c5d
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
// pages/m_consult/consultonline/consultonline.js
const b_search = require("../behaviors/b_search")
const app = getApp()
 
Page({
  behaviors: [b_search],
  /**
   * 页面的初始数据
   */
  data: {
    userId: app.globalData.accessToken.userId,
    record: [{
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        type: 0,
        text: '用户您好,很高兴为你服务',
      },
      {
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        type: 0,
        text: '用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.',
      },
 
    ],
 
    focus: false,
    value: '',
    placeholder: '请输入想要提问的内容'
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 
  },
 
  clearInput() {
    this.setData({
      value: '',
      focus: true,
    });
  },
 
  inputChange(e) {
    this.setData({
      value: e.detail.value
    });
  },
 
  send() {
    let record = this.data.record
    record.push({
      id: '',
      time: '',
      userId: app.globalData.accessToken.userId,
      userName: app.globalData.userInfo.acountname,
      text: this.data.value,
    })
    const keyword = this.data.value
    this.setData({
      record,
      value: ''
    })
 
    this.getAnswer(keyword)
  },
 
  getAnswer(q) {
    this.search({
      keyword: q,
      type: undefined
    })
  },
 
  loadComplete() {
    const results = this.data.results
    console.log(results);
 
    let record = this.data.record
    results.forEach(r => {
      record.push({
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        type: r.typeId,
        text: r,
      })
    });
 
    this.setData({record})
  }
})