Files

145 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

var WxParse = null;
var app = getApp()
var that=null
var that0=null
var t=0
Page( {
data: {
loadingHidden:false,
nodataHidden:true,
bodyHidden:true,
Start: 0,
articles:[]
},
onLoad: function(options) {
that = this
t=options.t
if(t==0){
wx.setNavigationBarTitle({
title: "发图素材"
})
}else if(t==1){
wx.setNavigationBarTitle({
title: "健康知识"
})
}
that.getlist(0);//第一次加载数据
},
// 下拉刷新
onPullDownRefresh: function () {
that.clearCache();
that.getlist(0);//第一次加载数据
},
// 页面上拉触底事件(上拉加载更多)
onReachBottom: function () {
that.getlist(1);//后台获取新数据并追加渲染
}, getlist: function (gp) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action:(t==1?"getjkzslist":"getftsclist"),
userId:(!userId?"":userId),
LoginId:(!LoginId?"":LoginId),
Start:that.data.Start
},
method:"GET",
dataType:"json",
header: {
"content-type": "application/json" // 默认值
},
success (res) {
var tmpArr = null;
tmpArr = that.data.articles;
tmpArr.push.apply(tmpArr,res.data.data);
that.setData({
articles: tmpArr,
Start: that.data.Start+res.data.data.length,
loadingHidden:true
})
if(gp==0||gp==1){
if(res.data.data.length==0){
that.setData({
nodataHidden:false
})
}else{
that.setData({
nodataHidden:true
})
}
}
}
})
},
// 清缓存
clearCache:function(){
that.setData({
articles: [],
Start: 0,
loadingHidden:false
});
},ondetail:function(e) {
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: "../articledetail/index?id="+id
})
/*that.setData({
loadingHidden:false
})
var id = e.currentTarget.dataset.id
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action:"getnewdetail",
userId:(!userId?"":userId),
LoginId:(!LoginId?"":LoginId),
id:id
},
method:"POST",
dataType:"json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success (res) {
if(res.data.status==1){
WxParse.wxParse('body', 'html', res.data.content, that);
that.setData({
title:res.data.title,
video:res.data.video,
bodyHidden:false
})
}else{
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
that.setData({
loadingHidden:true
})
}
})*/
},closeserver:function(e) {
that.data.videoCtx.stop()
that.setData({
bodyHidden:true
})
},inserver :function(e) {
}
})