aqyj/pages/train/train.js

260 lines
6.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//var base64 = require("../images/base64");
var sliderWidth = 96;
var util = require('../../utils/util.js')
Page({
data: {
page: 1,
serverUrl: getApp().globalData.serverUrl,
allpxlist: [],
tabs: ["我发布的", "我参加的", "全部"],
activeIndex: 1,
sliderOffset: 0,
sliderLeft: 0
},
tabClick: function (e) {
var that = this
that.setData({
sliderOffset: e.currentTarget.offsetLeft,
activeIndex: e.currentTarget.id
});
if (that.data.activeIndex == 0) {
that.getfqpxlist(1)
that.data.fqpage = 1
}
else if (that.data.activeIndex == 1) {
that.getcjpxlist(1)
that.data.cjpage = 1
}
else if (that.data.activeIndex == 2) {
that.getallpxlist(1)
that.data.page = 1
}
},
getallpxlist: function (page) {
var that = this;
if (page != 1) { page = that.data.page }
wx.showLoading({
title: '加载中',
}),
wx.request({
url: this.data.serverUrl + 'pxhandle?a=listall&rows=10&page=' + page,
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
success: res => {
if (res.statusCode === 200) {
if (res.data.rows.length == 0) {
if (page == 1) {
this.setData({
alltotal: 0,
allpxlist: []
})
}
else {
wx.showModal({
content: "已经到底啦!",
showCancel: false,
confirmText: "确定",
})
}
} else {
let list
if (page == 1) {
list = res.data.rows
} else {
list = this.data.allpxlist.concat(res.data.rows)
}
this.setData({
alltotal: res.data.total,
allpxlist: list
})
}
}
wx.hideLoading();
}
});
},
getfqpxlist: function (page) {
var that = this;
if (page != 1) { page = that.data.fqpage }
wx.showLoading({
title: '加载中',
}),
wx.request({
url: this.data.serverUrl + 'pxhandle?a=listtodo&rows=10&page=' + page,
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
success: res => {
if (res.statusCode === 200) {
if (res.data.rows.length == 0) {
if (page == 1) {
this.setData({
fqtotal: 0,
fqpxlist: []
})
}
else {
wx.showModal({
content: "已经到底啦!",
showCancel: false,
confirmText: "确定",
})
}
} else {
let list
if (page == 1) {
list = res.data.rows
} else {
list = this.data.fqpxlist.concat(res.data.rows)
}
this.setData({
fqtotal: res.data.total,
fqpxlist: list
})
}
}
wx.hideLoading();
}
});
},
getcjpxlist: function (page) {
var that = this;
if (page != 1) { page = that.data.cjpage }
wx.showLoading({
title: '加载中',
}),
wx.request({
url: this.data.serverUrl + 'pxhandle?a=listcj&rows=10&page=' + page,
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
success: res => {
if (res.statusCode === 200 && res.data.rows) {
if (res.data.rows.length == 0) {
if (page == 1) {
this.setData({
cjtotal: 0,
cjpxlist: []
})
}
else {
wx.showModal({
content: "已经到底啦!",
showCancel: false,
confirmText: "确定",
})
}
} else {
let list
if (page == 1) {
list = res.data.rows
} else {
list = this.data.cjpxlist.concat(res.data.rows)
}
this.setData({
cjtotal: res.data.total,
cjpxlist: list
})
}
}
wx.hideLoading();
}
});
},
onLoad: function () {
// this.setData({
// icon: base64.icon20
// });
var that = this;
wx.getSystemInfo({
success: function (res) {
that.setData({
sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
});
}
});
},
onShow: function () {
var that = this;
that.onPullDownRefresh()
},
onPullDownRefresh: function () {
var that = this;
if (that.data.activeIndex == 0) {
that.getfqpxlist(1)
that.data.fqpage = 1
}
else if (that.data.activeIndex == 1) {
that.getcjpxlist(1)
that.data.cjpage = 1
}
else if (that.data.activeIndex == 2) {
that.getallpxlist(1)
that.data.page = 1
}
wx.stopPullDownRefresh();
},
onReachBottom: function () {
//上拉分页,将页码加1然后调用分页函数
var that = this;
if (that.data.activeIndex == 0) {
this.data.fqpage = this.data.fqpage + 1;
this.getfqpxlist();
}
else if (that.data.activeIndex == 1) {
this.data.cjpage = this.data.cjpage + 1;
this.getcjpxlist();
}
else if (that.data.activeIndex == 2) {
this.data.page = this.data.page + 1;
this.getallpxlist();
}
},
open: function () {
wx.navigateTo({
url: 'add',
})
},
check:function(){
wx.scanCode({
onlyFromCamera: true,
success(res) {
console.log(res)
if (res.result.indexOf("trainid") != -1) {
let pxid = util.getQueryString(res.result, 'trainid')
wx.navigateTo({
url: 'check?pxid=' + pxid,
})
} else {
wx.showModal({
title: "系统提示",
content: '请扫培训二维码!',
showCancel: false,
confirmText: "确定"
})
}
}
})
},
openQr: function(e){
wx.navigateTo({
url: 'qrcode?pxid='+e.currentTarget.dataset.id,
})
},
accessTrain: function(e){
wx.navigateTo({
url: 'access?pxid='+e.currentTarget.dataset.id+'&trainname='+e.currentTarget.dataset.trainname,
})
}
});