library_sign_num.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // dispatcher/pages/sweeped_books/sweeped_books.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { SignMonthList, DayInfoList } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. thumbnail,
  14. isLoaded: false,
  15. isAllCheck: 0,
  16. isManage: 0,
  17. totalNum: 0,
  18. month:'',
  19. Search_date:'',
  20. monthValue:'',
  21. dateL:'',
  22. ids: [],
  23. isMonthData:0,
  24. pageNo: 1,
  25. pageSize: 10,
  26. isAll: 0,
  27. isDown: false,
  28. totalNumbers: 0,
  29. list: [
  30. ],
  31. nodataMonthArray: {
  32. text: "本月无到馆会员数据",
  33. image: '../../../assets/Nosign.png',
  34. margin: '400rpx auto'
  35. },
  36. nodataArray: {
  37. text: "本日暂无数据统计",
  38. image: '../../../assets/Nosign.png',
  39. margin: '400rpx auto'
  40. }
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  47. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  48. this.setData(options)
  49. this.GetMonthDate()
  50. const Search_date = wx.getStorageSync("date")
  51. const monthValue = wx.getStorageSync("monthValue")
  52. this.setData({
  53. isMonthData: options.isMonthData,
  54. Search_date: Search_date,
  55. monthValue: monthValue
  56. });
  57. if (options.isMonthData == 1) {
  58. this.getDayData(res => {
  59. this.setData({ isLoaded: 1 })
  60. wx.setNavigationBarTitle({
  61. title: `日统计数据`,
  62. })
  63. })
  64. }
  65. if (options.isMonthData == 2) {
  66. this.getMonthData(res => {
  67. this.setData({ isLoaded: 1 })
  68. wx.setNavigationBarTitle({
  69. title: `本月到馆会员`,
  70. })
  71. })
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  79. for (const i in obj) {
  80. this[i] = obj[i]
  81. }
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. const { isAll, options, isMonthData } = this.data
  103. const { type = 1 } = options
  104. if (type == 1) return
  105. this.setData({ pageNo: 1 })
  106. if (isMonthData == 1) {
  107. this.getDayData(res => {
  108. wx.stopPullDownRefresh()
  109. })
  110. }
  111. if (isMonthData == 2) {
  112. this.getMonthData(res => {
  113. wx.stopPullDownRefresh()
  114. })
  115. }
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. const { isAll, isDown, isMonthData } = this.data
  122. if (isAll) {
  123. this.setData({ isDown: true })
  124. return
  125. } else {
  126. this.setData({ isLoad: true, isDown: false })
  127. if (isMonthData == 1) {
  128. this.getDayData(res => {
  129. this.setData({ isLoad: false })
  130. })
  131. }
  132. if (isMonthData == 2) {
  133. this.getMonthData(res => {
  134. this.setData({ isLoad: false })
  135. })
  136. }
  137. }
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. if (isFn(sharePage)) return sharePage()
  144. },
  145. GetMonthDate: function () {
  146. const now = new Date();
  147. const year = now.getFullYear();    //年
  148. const month = now.getMonth() + 1; //月
  149. const nowdate = year + '-' + month
  150. this.setData({ month: nowdate })
  151. },
  152. /**
  153. * 本月签到人数
  154. */
  155. getMonthData: function (cb) {
  156. const continuousFn = { fn: this.getMonthData, param: { ...arguments } }
  157. const { pageNo, pageSize, list, libId, monthValue } = this.data
  158. SignMonthList({ data: { month: monthValue, libId, pageNo, pageSize }, continuousFn }).then(res => {
  159. const { list, pages } = res.data
  160. let listTemp = []
  161. if (pageNo == 1) {
  162. listTemp = [].concat(list)
  163. } else {
  164. listTemp = [].concat(this.data.list, list)
  165. }
  166. const correctListTemp = (res => {
  167. console.log(res)
  168. var d = []
  169. for (let i in res) {
  170. res[i].number = 0
  171. }
  172. return res
  173. })(listTemp)
  174. this.setData({ list: correctListTemp, monthpages: pages, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  175. cb && cb(res)
  176. }).catch(res => {
  177. cb && cb(res)
  178. })
  179. },
  180. /**
  181. * 本日签到人数
  182. */
  183. getDayData: function (cb) {
  184. const continuousFn = { fn: this.getDayData, param: { ...arguments } }
  185. const { pageNo, pageSize, list, libId, Search_date } = this.data
  186. DayInfoList({ data: { date: Search_date, libId, pageNo, pageSize }, continuousFn }).then(res => {
  187. const { list } = res.data
  188. let listTemp = []
  189. if (pageNo == 1) {
  190. listTemp = [].concat(list)
  191. } else {
  192. listTemp = [].concat(this.data.list, list)
  193. }
  194. const correctListTemp = (res => {
  195. console.log(res)
  196. var d = []
  197. for (let i in res) {
  198. res[i].number = 0
  199. }
  200. return res
  201. })(listTemp)
  202. this.setData({ list: correctListTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  203. cb && cb(res)
  204. }).catch(res => {
  205. cb && cb(res)
  206. })
  207. },
  208. })