forked from nsjcy/frontEnd/nsjcy

liuwh
2020-05-09 894ab56e0e650dda334273f21f948677163f134b
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
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);
      }
 
    })
  }
})