createDocumentList.js 3.13 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
// 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'
})
}
})