risk_guide.js 4.66 KB
   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
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
//articleLists.js 文章列表
// 网络请求工具类
var networkUtil = require('../../utils/network_util.js')
var api = require('../../utils/apiFile.js')
// 事件监听
var event = require('../../utils/event.js')
var page
// 是否有更多
var hasMore
var isRefresh
// 获取应用实例
var app = getApp()

var pageLimit=15
var animation1 = wx.createAnimation({
duration:1000
})
Page({
data: {
list: [],
images: {},
titles: [],//"日常护理", "营养美食", "疾病护理", "亲子互动", "言传身教"
category:'',
current_index:0,
animationData:{},
swiperHeight:0
},
onLoad: function (e) {
// 数据初始化
var self = this
page = 1
hasMore = true
isRefresh = false
this.setData({
titles: app.globalData.artList,
category: app.globalData.artList[self.data.current_index].id,
images: app.globalData.artList[self.data.current_index].iconimage,
swiperHeight: wx.getSystemInfoSync().windowWidth * 0.42
})
this.requestData()
},
onUnload: function() {
},
/*---------事件处理函数--------*/
bindViewTap: function() {
wx.navigateTo({
url: '../home/home'
})
},
// 加载更多
loadMore:function(){
console.log("hasMore:", hasMore)
if(!hasMore || isRefresh == true){
return
}
page ++
networkUtil.showLoading()
this.requestData()
},
// 下拉刷新回调接口
refesh: function() {
page = 1;
hasMore = true
var self=this
this.setData({
list: [],
})
animation1 = wx.createAnimation({
duration: 1000
})
animation1.rotate(720).step()

this.setData({
animationData: animation1.export()
})


networkUtil.showLoading()
// 网络请求,重新请求一遍数据
this.requestData();
},
myScroll: function (e) {
console.log("e:", e)
// if(e.detail.scrollTop >= e.detail.scrollHeight-wx.getSystemInfoSync().windowHeight - 3){
// this.loadMore()
// }
this.loadMore()
},
titleClick:function(e){
// console.log(e)
var self=this
var current_index = e.currentTarget.dataset.index
var categoryid = e.currentTarget.dataset.categoryid
this.setData({
category: categoryid,
current_index: current_index,
images: app.globalData.artList[current_index].iconimage
})
page = 1;
hasMore = true
this.requestData()
},
toSearch(){
wx.navigateTo({
url: '../SearchPage/SearchPage',
})
},
toDetail:function(e){
var self = this
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: '../childcare_knowledge_detail/childcare_knowledge_detail?id=' + id + ' & category=' + self.data.category,
})
},

/*---------自定义函数--------*/
requestData(){
var self = this
isRefresh = true
networkUtil.showLoading()
var param = { page: page, limit: pageLimit, type: 2, categoryId: self.data.category}
// console.log(param)
networkUtil._get(api.articleList,param,function(res){
console.log(res)
isRefresh = false
var arr = []
if(page > 1) {// 加载更多模式
arr = self.data.list
}
if (res.data.data.length < pageLimit){
hasMore = false
}else{
hasMore = true
}
arr = arr.concat(res.data.data)
self.setData({
list:arr,
hasMore: hasMore
})
// var that = this;
setTimeout(function () {
animation1.rotate(0).step({ duration: 0, transformOrigin: "50%,50%", timingFunction: 'linear' })
self.setData({
animationData: animation1.export()
})
}, 300)
},function(res){
isRefresh = false
setTimeout(function () {
animation1.rotate(0).step({ duration: 0, transformOrigin: "50%,50%", timingFunction: 'linear' })
self.setData({
animationData: animation1.export()
})
}, 300)
})

},
// 文章点赞
articleLike: function (e){
console.log(e)
var self = this
var id = e.currentTarget.dataset.id
var index = e.currentTarget.dataset.index
// 已经点赞
if (self.data.list[index].isLike == 1) {
networkUtil.showErrorToast('您已经点过赞啦')
return;
}
networkUtil._post(api.articleLike, { id: id }, function (res) {
console.log(res)
self.data.list[index].likeCount++
self.data.list[index].isLike = 1
self.setData({
list: self.data.list
})
}, function (res) {
console.log(res)
})
}
})