// pages/m_consult/consulthome/consulthome.js
const consultservice = require("../../../service/consultservice")
const moment = require('../../../utils/moment.min')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
searchTips: '请输入关键字搜索',
hotTopics: [],
tabList: [{
name: '热门',
tag: 0
}, {
name: '文件',
tag: 0
}, {
name: '条目',
tag: 0
}, {
name: '问答',
tag: 0
}, {
name: '案例',
tag: 0
}],
pageList: [
[],
[],
[],
[],
[],
],
//案例所涉及的要点
caseTag: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getHotTopic()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
// 搜索
gotoSearch() {
wx.navigateTo({
url: "/pages/m_consult/consultsearch/consultsearch"
})
},
// 功能按钮
goto(e) {
var url = ""
var index = e.currentTarget.dataset.index
switch (index) {
case "0":
url = "/pages/m_consult/consultproblem/consultproblem"
break;
case "1":
url = "/pages/m_consult/consultsearch/consultsearch"
break;
case "2":
url = "/pages/m_consult/consultonline/consultonline"
break;
}
if (url != "") {
wx.navigateTo({
url: url
})
} else {
wx.showToast({
title: '功能敬请期待',
duration: 1000,
icon: 'none',
mask: true,
})
}
},
/**
* 获取热门搜索内容
*/
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
})
}
})
// 2. 热门法律法规条目
consultservice.getTopicItem(app.globalData.accessToken.userId, {
success(res) {
res.forEach(r => {
r.miItemContent = r.miItemContent.replaceAll('\\n', '
')
});
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', '
')
r.ecMeaning = r.ecMeaning.replaceAll('\\n', '
')
r.ecExamined = r.ecExamined.replaceAll('\\n', '
')
r.ecEnlightenment = r.ecEnlightenment.replaceAll('\\n', '
')
r.ecOccurDate = that.formatTime(r.ecOccurDate)
});
that.setData({
'pageList[4]': res
})
console.log(that.data.pageList);
}
})
},
// 去往文件详情
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
})
},
})
},
// 去往条目详情
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
}
},
})