const app = getApp(); var WxParse = require('../wxParse/wxParse.js'); Page({ /** * 页面的初始数据 */ data: { contacts: [], bottom: '', searchinput: '', scrollTop: 0 }, bottomInput: function(e) { this.setData({ searchinput: e.detail.value, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function() { // this.custom(); // this.message(); }, submit: function() { var that = this; var text = this.data.searchinput; if (!text) { return app.showModal("请输入你想咨询的内容!") } var contacts = this.data.contacts; var month = new Date().getMonth() + 1; var obj = { senderType: 1, content: text, createTime: new Date().getFullYear() + "-" + month + "-" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() }; contacts.push(obj); that.setData({ contacts, searchinput: '' }) wx.request({ url: app.globalData.url + '/api/faq/find/answer/' + text, success: function(res) { if (res.data.answer != null) { var answ = { senderType: 2, flag: 'answer', content: res.data.answer, title: text } contacts.push(answ) } else { var resp = { flag: 'noAnsw', senderType: 2, content: '这个问题听不懂,正在学习中......', } contacts.push(resp) } if (res.data.list.length > 0) { var resp = { data: res.data.list, flag: 'request', senderType: 2, createTime: new Date().getFullYear() + "-" + month + "-" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() } contacts.push(resp) that.setData({ contacts }, that.pageScrollToBottom); console.log(contacts) } else { var resp = { flag: 'noAnsw', senderType: 2, content: '这个问题听不懂,正在学习中......', } contacts.push(resp) that.setData({ contacts }, that.pageScrollToBottom); } } }) }, // 获取容器高度,使页面滚动到容器底部 pageScrollToBottom: function() { this.setData({ scrollTop: 999999999999 }) }, showAnsw: function(e) { var that = this; var title = e.currentTarget.dataset.title; var contacts = this.data.contacts; wx.request({ url: app.globalData.url + '/api/faq/find/answer/' + title, success: function(res) { console.log(res); var content = res.data.answer; WxParse.wxParse('content', 'html', content, that, 5); var req = { senderType: 1, content: title } var answ = { senderType: 2, flag: 'answer', content: res.data, title: title } contacts.push(req); contacts.push(answ); that.setData({ contacts }, that.pageScrollToBottom); } }) } })