riku
2022-09-19 47e86f543415585ab1e1b2b1ed1d98830817a1be
pages/m_consult/consulthome/consulthome.js
@@ -1,25 +1,14 @@
// pages/m_consult/consulthome/consulthome.js
const consultservice = require("../../../service/consultservice")
const moment = require('../../../utils/moment.min')
const app = getApp()
Page({
  // behaviors: [behavior],
  /**
   * 页面的初始数据
   */
  data: {
    searchTips: '请输入关键字搜索',
    hotTopics: [],
    tabList: [{
      name: '热门',
      tag: 0
    }, {
      name: '文件',
      tag: 0
    }, {
      name: '条目',
      tag: 0
    }, {
      name: '问答',
@@ -27,39 +16,35 @@
    }, {
      name: '案例',
      tag: 0
    }],
    pageList: [
      [],
      [],
      [],
      [],
      [],
    ],
    //案例所涉及的要点
    caseTag: []
    }, {
      name: '条目',
      tag: 0
    }, {
      name: '文件',
      tag: 0
    }, ],
    refresh: false,
    // 热门内容查询条件
    keyAll: {keyword: '', type: undefined},
    key1: {keyword: '', type: 1},
    key2: {keyword: '', type: 2},
    key3: {keyword: '', type: 3},
    key4: {keyword: '', type: 4},
    reachBottom: [false, false, false, false, false],
    tabIndex: 0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getHotTopic()
    // this.getHotTopic()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  onReachBottom() {
    let reachBottom = [false, false, false, false, false]
    reachBottom[this.data.tabIndex] = true
    this.setData({reachBottom})
  },
  // 搜索
@@ -98,140 +83,19 @@
    }
  },
  /**
   * 获取热门搜索内容
   */
  getHotTopic() {
    var that = this
    // 1. 热门法律法规
    consultservice.getTopicLaw(app.globalData.accessToken.userId, {
      success(res) {
        res.forEach(r => {
          r.mfKeywordLv1 = r.mfKeywordLv1.split('、').slice(0, 5)
          r.mfReleaseDate = that.formatTime(r.mfReleaseDate)
          r.mfEffectiveDate = that.formatTime(r.mfEffectiveDate)
          r.mfClosingDate = that.formatTime(r.mfClosingDate)
        });
        that.setData({
          'pageList[0]': res,
          'pageList[1]': res
        })
      }
  loadingDone(e){
    this.setData({
      refresh: false
    })
    // 2. 热门法律法规条目
    consultservice.getTopicItem(app.globalData.accessToken.userId, {
      success(res) {
        res.forEach(r => {
          r.miItemContent = r.miItemContent.replaceAll('\\n', '<br/>')
        });
        that.setData({
          'pageList[2]': res
        })
      }
    })
    // 3. 热门问答
    consultservice.getTopicQA(app.globalData.accessToken.userId, {
      success(res) {
        res.forEach(r => {
          r.cqCreateTime = that.formatTime(r.cqCreateTime)
        });
        that.setData({
          'pageList[3]': res
        })
      }
    })
    // 4. 热门案例
    consultservice.getTopicCase(app.globalData.accessToken.userId, {
      success(res) {
        res.forEach(r => {
          r.ecSummary = r.ecSummary.replaceAll('\\n', '<br/>')
          r.ecMeaning = r.ecMeaning.replaceAll('\\n', '<br/>')
          r.ecExamined = r.ecExamined.replaceAll('\\n', '<br/>')
          r.ecEnlightenment = r.ecEnlightenment.replaceAll('\\n', '<br/>')
          r.ecOccurDate = that.formatTime(r.ecOccurDate)
        });
        that.setData({
          'pageList[4]': res
        })
        console.log(that.data.pageList);
      }
    this.setData({
      refresh: true
    })
  },
  // 去往文件详情
  gotoFile(e) {
    const iList = e.currentTarget.dataset.index.split(',')
    const i1 = iList[0]
    const i2 = iList[1]
    var fileId = this.data.pageList[i1][i2].mfGuid
    wx.navigateTo({
      url: '/pages/m_consult/consultdetail/consultdetail',
      success: (res) => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          fileId: fileId
        })
      },
  onTabChange(e) {
    // console.log(e.detail);
    this.setData({
      tabIndex: e.detail
    })
  },
  // 去往条目详情
  gotoItem(e) {
    const iList = e.currentTarget.dataset.index.split(',')
    const i1 = iList[0]
    const i2 = iList[1]
    var itemId = this.data.pageList[i1][i2].miGuid
    wx.navigateTo({
      url: '/pages/m_consult/consultdetailitem/consultdetailitem',
      success: (res) => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          itemId: itemId
        })
      },
    })
  },
  // 去往问答详情
  gotoQA(e) {
    const iList = e.currentTarget.dataset.index.split(',')
    const i1 = iList[0]
    const i2 = iList[1]
    var qId = this.data.pageList[i1][i2].cqGuid
    wx.navigateTo({
      url: '/pages/m_consult/consultdetailqa/consultdetailqa',
      success: (res) => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          qId: qId
        })
      },
    })
  },
  // 去往案例详情
  gotoCase(e) {
    const iList = e.currentTarget.dataset.index.split(',')
    const i1 = iList[0]
    const i2 = iList[1]
    var caseId = this.data.pageList[i1][i2].ecGuid
    wx.navigateTo({
      url: '/pages/m_consult/consultdetailcase/consultdetailcase',
      success: (res) => {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          caseId: caseId
        })
      },
    })
  },
  formatTime(t) {
    if (t) {
      return moment(t).format("YYYY.MM.DD")
    } else {
      return undefined
    }
  },
  }
})