// pages/createDocumentList/createDocumentList.js
const networkUtil = require('../../utils/network_util.js')
const api = require('../../utils/apiFile.js')
var page = 1
// 是否有更多
var hasMore
var isRefresh
Page({
/**
* 页面的初始数据
*/
data: {
selectArr: [{ title: '预约建档', index: 0 }, { title: '预约成功', index: 1 }],
sucList: [],
buildList:[],
currentIndex:0,
hasMore:false,
cDate:''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
hasMore = true
isRefresh = false
var date = new Date()
this.data.cDate = { year:date.getFullYear(), month: date.getMonth() + 1}
this.requestBuildList()
},
clickBar(e){
this.setData({
currentIndex: e.target.dataset.index
})
if (e.target.dataset.index == 1 && this.data.sucList.length == 0){
isRefresh = false
this.requestSuccessList()
}
},
// 加载更多
loadMore: function (e) {
if (isRefresh == true) {
return
}
this.loadData(this.data.currentIndex)
},
myScroll: function (e) {
if (e.detail.scrollTop >= e.detail.scrollHeight - wx.getSystemInfoSync().windowHeight - 3) {
this.loadMore()
}
},
loadData(index){
if (index == 0) {
if (!hasMore) {
return
}
page++
this.requestBuildList()
} else {
this.data.cDate.month = this.data.cDate.month - 1
if (this.data.cDate.month == 0) {
this.data.cDate.year = this.data.cDate.year - 1
this.data.cDate.month = 12
}
console.log('当前时间', this.data.cDate)
this.requestSuccessList()
}
},
tapmore(){
this.loadData(this.data.currentIndex)
},
// ------------------网络请求------------------
requestSuccessList(){
networkUtil.showLoading()
var self = this
isRefresh = true
networkUtil._get(api.ArchiveSuccessList, { hospitalId: getApp().globalData.openInfo.hospitalId, month: this.data.cDate.year + '-' + this.data.cDate.month + ''}, function (res) {
console.log(res)
isRefresh = false
var arr = self.data.sucList
var temp = {}
temp['date'] = self.data.cDate.year + '年' + self.data.cDate.month + '月'
temp['data'] = res.data.data
console.log('temp', temp)
arr.push(temp)
self.setData({
sucList: arr
})
}, function (res) {
isRefresh = false
networkUtil.showErrorToast(res.errormsg)
})
},
requestBuildList() {
var self = this
networkUtil.showLoading()
networkUtil._get(api.ArchiveBuildList, { hospitalId: getApp().globalData.openInfo.hospitalId,page:page,limit:15}, function (res) {
console.log(res)
isRefresh = false
var arr = []
if (page > 0) {// 加载更多模式
arr = self.data.buildList
}
if (res.data.data.length < 15) {
hasMore = false
}
arr = arr.concat(res.data.data)
self.setData({
buildList: arr,
hasMore: hasMore
})
}, function (res) {
networkUtil.showErrorToast(res.errormsg)
})
},
toDetail(e){
wx.navigateTo({
url:'../personDetail/personDetail'
})
}
})