Files
HnyhuaXCX/pages/news/index.js

144 lines
3.5 KiB
JavaScript

var WxParse = null;
var app = getApp()
var that=null
Page( {
data: {
loadingHidden:false,
nodataHidden:true,
bodyHidden:true,
Start: 0,
nav:0,
helps:[],
title:"",
body:""
},onShow: function () {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 1
})
}
},
onLoad: function(options) {
that = this
WxParse = require('../../wxParse/wxParse.js')
that.clearCache();//清本页缓存
that.getlist(0);//第一次加载数据
}, getlist: function (gp) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action:"getnewslist",
userId:(!userId?"":userId),
LoginId:(!LoginId?"":LoginId),
t:that.data.nav,
Start:that.data.Start
},
method:"GET",
dataType:"json",
header: {
"content-type": "application/json" // 默认值
},
success (res) {
var tmpArr = null;
tmpArr = that.data.helps;
tmpArr.push.apply(tmpArr,res.data.data);
that.setData({
helps: 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
})
}
}
}
})
},
// 下拉刷新
onPullDownRefresh: function () {
that.clearCache();
that.getlist(0);//第一次加载数据
},
// 页面上拉触底事件(上拉加载更多)
onReachBottom: function () {
that.getlist(1);//后台获取新数据并追加渲染
},
// 清缓存
clearCache:function(){
that.setData({
helps: [],
Start: 0,
loadingHidden:false
});
},ondetail:function(e) {
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,
bodyHidden:false
})
}else{
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
that.setData({
loadingHidden:true
})
}
})
},closeserver:function(e) {
that.setData({
bodyHidden:true
})
},inserver :function(e) {
},onnav:function(e) {
var index = e.currentTarget.dataset.id
that.setData({
nav:index
})
that.clearCache();
that.getlist(0);
}
})