// pages/mConsult/consultonline/consultonline.js const bSearch = require("../behaviors/bSearch") const app = getApp() Page({ behaviors: [bSearch], /** * 页面的初始数据 */ data: { userId: app.globalData.accessToken.userId, record: [{ id: 'system', time: '', userId: 'system', userName: '智能客服', type: 0, text: '尊敬的用户,小白竭诚为您服务,您有什么问题呢', } ], focus: false, value: '', placeholder: '请输入想要提问的内容' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ userId: app.globalData.accessToken.userId }) }, 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, }) console.log('-----------chat------------------'); console.log(record); console.log(this.data.userId); 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.sort((a, b) => { return b.typeId - a.typeId }) 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/mConsult/consultresultmore/consultresultmore', success: (res) => { // 通过 eventChannel 向被打开页面传送数据 res.eventChannel.emit('acceptDataFromOpenerPage', { typeId: typeId, keyword: keyword }) }, }) } })