riku
2022-09-15 bd3a9d7086f5a428b385599ba2cb08299b22c0df
pages/m_consult/consultonline/consultonline.js
@@ -1,8 +1,9 @@
// pages/m_consult/consultonline/consultonline.js
const b_search = require("../behaviors/b_search")
const app = getApp()
Page({
  behaviors: [b_search],
  /**
   * 页面的初始数据
   */
@@ -13,55 +14,20 @@
        time: '',
        userId: 'system',
        userName: '智能客服',
        text: '用户您好,很高兴为你服务',
      },
      {
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        text: '用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.用户您好,很高兴为您服务,本月信用自评结果较 好,继续保持哦.',
      },
        type: 0,
        text: '尊敬的用户,小白竭诚为您服务,您有什么问题呢',
      }
    ],
    focus: false,
    value: '',
    placeholder: '请输入关键字'
    placeholder: '请输入想要提问的内容'
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
@@ -85,27 +51,127 @@
      time: '',
      userId: app.globalData.accessToken.userId,
      userName: app.globalData.userInfo.acountname,
      type: 0,
      text: this.data.value,
    })
    this.getAnswer(this.data.value)
    this.lastKeyword = this.data.value
    this.setData({
      record,
      value: ''
    })
    this.getAnswer()
  },
  getAnswer(q) {
  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
    setTimeout(() => {
    if (results.length == 0) {
      record.push({
        id: 'system',
        time: '',
        userId: 'system',
        userName: '智能客服',
        text: '用户您好,很高兴为你服务',
        type: 0,
        text: '不好意思,暂无相关解答,请试试其他关键词'
      })
      this.setData({record})
    }, 1000);
    } 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
        })
      },
    })
  }
})