//articleLists.js 文章列表 // 网络请求工具类 var networkUtil = require('../../utils/network_util.js') var api = require('../../utils/apiFile.js') // 事件监听 var event = require('../../utils/event.js') var util = require('../../utils/util.js') Page({ data: { knowledge: null, images: [], titles: ["日常护理", "营养美食", "疾病护理", "亲子互动", "言传qq"], id: 0, category: '', current_index: 0, title:'', swiperHeight:0 }, onLoad: function (options) { // this.data.id = e.id // this.data.category = e.category // 记录上层传递的信息 // category = options.category // articleId = options.id // categoryIndex = options.categoryIndex // articleIdIndex = options.artIndex // wx.setNavigationBarTitle({ // title: options.category, // success: function (res) { // } // }) this.requestData(options.id) }, onUnload: function () { }, /*---------事件处理函数--------*/ bindViewTap: function () { wx.navigateTo({ url: '../home/home' }) }, // 加载更多 loadMore: function (e) { if (!hasMore || isRefresh == true) { return } page++ this.requestData() }, // 下拉刷新回调接口 onPullDownRefresh: function () { page = 1; hasMore = true // 网络请求,重新请求一遍数据 this.requestData(); }, myScroll: function (e) { if (e.detail.scrollTop >= e.detail.scrollHeight - wx.getSystemInfoSync().windowHeight - 3) { this.loadMore() } }, titleClick: function (e) { console.log(e) var index = e.currentTarget.dataset.index this.setData({ current_index: index }) }, /*---------自定义函数--------*/ requestData(id) { var self = this networkUtil.showLoading() // var param = { page: page, limit: 15, type: 2, categoryId: self.data.id } networkUtil._get(api.articles + '/' + id, {}, function (res) { console.log('数据-----',res) res.data.content = util.convertHtmlToText(res.data.content) var date = new Date(res.data.created * 1000) res.data.time = date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日 ' + date.getHours() + ':' + date.getMinutes() self.setData({ knowledge: res.data, swiperHeight: wx.getSystemInfoSync().windowWidth * 0.55 }) }, function (res) { }) }, // 文章点赞 articleLike() { var self = this // 已经点赞 if (self.data.knowledge.isLike == 1) { networkUtil.showErrorToast('您已经点过赞啦') return; } networkUtil._post(api.articleLike, { id: self.data.knowledge.id}, function (res) { console.log(res) var art = self.data.knowledge art.likeCount++ art.isLike = 1 self.setData({ knowledge: art }) // if (categoryIndex) { // // 更新首页数据 // event.emit('likeChanged', { categoryIndex: categoryIndex, articleIdIndex: articleIdIndex }); // } else { // event.emit('listLikeChanged', { categoryIndex: categoryIndex, articleIdIndex: articleIdIndex }); // } }, function (res) { console.log(res) }) } })