aqyj/pages/mgt/index.js

195 lines
4.4 KiB
JavaScript
Raw Permalink 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.

Page({
/**
* 页面的初始数据
*/
data: {
page: 1,
serverUrl: getApp().globalData.serverUrl,
datalist: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
that.onPullDownRefresh();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
var that = this;
that.getDatalist(1);
wx.stopPullDownRefresh();
this.data.page = 1;
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
//上拉分页,将页码加1然后调用分页函数
this.data.page = this.data.page + 1;
this.getDatalist();
wx.stopPullDownRefresh();
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
getDatalist: function (page, search = '') {
var that = this;
if (page != 1) { page = that.data.page }
wx.showLoading({
title: '加载中',
}),
wx.request({
url: this.data.serverUrl + 'mgt/api?a=listall&rows=10&page=' + page + '&search=' + search,
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({
total: 0,
datalist: []
})
}
else {
wx.showModal({
content: "已经到底啦!",
showCancel: false,
confirmText: "确定",
})
}
} else {
let list
if (page == 1) {
list = res.data.rows
} else {
list = this.data.datalist.concat(res.data.rows)
}
this.setData({
total: res.data.total,
datalist: list
})
}
}
wx.hideLoading();
}
});
},
//搜索框文本内容显示
inputBind: function (event) {
this.setData({
inputValue: event.detail.value
})
},
query: function () {
this.page = 1
this.getDatalist(this.page, this.data.inputValue)
},
reset: function () {
this.page = 1
this.inputValue = ''
this.getDatalist(this.page)
},
openfj: function(e){
var that = this
let fileurl = getApp().globalData.serverUrl + e.currentTarget.dataset.operprocepath
wx.showLoading({
title: '正在下载...',
})
wx.request({
url: getApp().globalData.serverUrl + 'api/getprodata?a=readnum&id=' + e.currentTarget.dataset.id,
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
success: res => {
}
});
wx.downloadFile({
url: fileurl,
success(res) {
wx.showLoading({
title: '成功,正在打开...',
})
const filePath = res.tempFilePath
var filetype
if (fileurl.indexOf(".docx") != -1) {
filetype = 'docx'
}
else if (fileurl.indexOf(".doc") != -1) {
filetype = 'doc'
}
else if (fileurl.indexOf(".xlsx") != -1) {
filetype = 'xlsx'
}
else if (fileurl.indexOf(".xls") != -1) {
filetype = 'xls'
}
else if (fileurl.indexOf(".pptx") != -1) {
filetype = 'pptx'
}
else if (fileurl.indexOf(".ppt") != -1) {
filetype = 'ppt'
}
else if (fileurl.indexOf(".pdf") != -1) {
filetype = 'pdf'
} else {
wx.hideLoading()
return
}
wx.openDocument({
filePath,
fileType: filetype,
success(res) {
wx.hideLoading()
console.log('打开文档成功')
}, fail: function (e) {
console.log(e)
}
})
}
})
}
})