riku
2022-09-15 bd3a9d7086f5a428b385599ba2cb08299b22c0df
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
// 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: '尊敬的用户,小白竭诚为您服务,您有什么问题呢',
      }
    ],
 
    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,
      type: 0,
      text: this.data.value,
    })
    this.lastKeyword = this.data.value
    this.setData({
      record,
      value: ''
    })
 
    this.getAnswer()
  },
 
  getAnswer() {
    this.search({
      keyword: this.lastKeyword,
      type: undefined
    }, 1, 1)
    // let record = this.data.record
    // const r = {
    //   id: 'system',
    //   time: '',
    //   userId: 'system',
    //   userName: '智能客服',
    //   type: 1,
    //   text: {
    //     tabList: [
    //       {name: '问答',tag: 0}, 
    //       {name: '案例',tag: 0}, 
    //       {name: '条目',tag: 0}, 
    //       {name: '文件',tag: 0}
    //     ],
    //     key1: {keyword: q, type: 1},
    //     key2: {keyword: q, type: 2},
    //     key3: {keyword: q, type: 3},
    //     key4: {keyword: q, type: 4},
    //     // pageList: p
    //   },
    // }
    // this.data.record.push(r)
    // let last = this.data.record.length - 1
    // this.setData({
    //   [`record[${last}]`]: r
    // })
    // this.setData({
    //   record,
    // })
  },
 
  loadComplete() {
    const results = this.data.results
    let record = this.data.record
 
    if (results.length == 0) {
      record.push({
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        type: 0,
        text: '不好意思,暂无相关解答,请试试其他关键词'
      })
    } else {
      record.push({
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        type: 0,
        text: '小白给您提供参考如下'
      })
      const map = new Map()
      results.forEach(r => {
        if (!map.has(r.typeName)) {
          r.keyword = this.lastKeyword
          map.set(r.typeName, [])
          map.get(r.typeName).push(r)
        }
      });
      const t = []
      const p = []
      for (let item of map) {
        t.push({
          name: item[0],
          tag: 0
        })
        p.push(item[1])
      }
      record.push({
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        type: 1,
        refresh: true,
        text: {
          tabList: t,
          pageList: p
        },
      })
    }
    this.setData({
      record,
    })
  },
 
  gotoMore(e) {
    const iList = e.currentTarget.dataset.index
    const i1 = iList[0]
    const i2 = iList[1]
    const {keyword, typeId} = this.data.record[i1].text.pageList[i2][0]
    console.log(keyword);
    console.log(typeId);
    wx.navigateTo({
      url: '/pages/m_consult/consultresultmore/consultresultmore',
      success: (res) => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          typeId: typeId,
          keyword: keyword
        })
      },
    })
  }
})