sign_leave_in.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // dispatcher/pages/sweeped_books/sweeped_books.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { SignList, SignSubmit } 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. selectAll: 0,
  16. isManage: 0,
  17. isDown:false,
  18. isLoad: false,
  19. totalNum: 0,
  20. ids: [],
  21. pageNo: 1,
  22. pageSize: 10,
  23. childName:"",
  24. type:1,
  25. isAll: 0,
  26. totalNumbers: 0,
  27. isSignin:1,
  28. list: [],
  29. nodataArray: {
  30. text: "会员列表为空",
  31. image: '../../../assets/Nosign.png',
  32. margin: '400rpx auto'
  33. }
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. this.setData({
  40. isSignin: options.isSignin
  41. });
  42. if (options.isSignin ==1){
  43. this.setData({ type: 1 })
  44. wx.setNavigationBarTitle({
  45. title: `签到`,
  46. })
  47. }
  48. if (options.isSignin == 0) {
  49. this.setData({ type: 2 })
  50. wx.setNavigationBarTitle({
  51. title: `签离`,
  52. })
  53. }
  54. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  55. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  56. this.setData(options)
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady: function () {
  62. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  63. for (const i in obj) {
  64. this[i] = obj[i]
  65. }
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. this.getData(res => {
  72. this.setData({ isLoaded: 1 })
  73. })
  74. },
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function () {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function () {
  89. this.setData({ pageNo: 1 })
  90. this.getData(res => {
  91. wx.stopPullDownRefresh()
  92. })
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom: function () {
  98. const { isAll, isDown } = this.data
  99. if (isAll) {
  100. this.setData({ isDown: true })
  101. return
  102. } else {
  103. this.setData({ isLoad: true, isDown: false })
  104. this.getData(() => {
  105. this.setData({ isLoad: false })
  106. })
  107. }
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. if (isFn(sharePage)) return sharePage()
  114. },
  115. /**
  116. * 获取数据
  117. */
  118. /**
  119. * 在馆书籍
  120. */
  121. getData: function (cb) {
  122. const continuousFn = { fn: this.getData, param: { ...arguments } }
  123. const { pageNo, pageSize, list, libId, type, options, selectAll, childName } = this.data
  124. SignList({ data: { type, libId, pageNo, pageSize, childName }, continuousFn }).then(res => {
  125. const { pages } = res.data
  126. const newList = ((list, isCheck) => {
  127. for (let i in list) {
  128. list[i].isCheck = isCheck
  129. }
  130. return list
  131. })(res.data.list, selectAll)
  132. let tempList = []
  133. if (pageNo == 1) {
  134. tempList = newList
  135. } else {
  136. tempList = [...list, ...newList]
  137. }
  138. const temp = {}
  139. temp[`list`] = tempList
  140. temp['pageNo'] = newList.length == pageSize ? ~~pageNo + 1 : pageNo
  141. temp['isAll'] = newList.length < pageSize
  142. this.setData(temp)
  143. this.setData({ totalNumbers: pages })
  144. this.caclulateBook()
  145. if (isFn(cb)) cb()
  146. }).catch(res => {
  147. if (isFn(cb)) cb()
  148. })
  149. },
  150. /**
  151. * 切换管理和取消按钮
  152. */
  153. toggleManageCtl: function () {
  154. const { isManage = false } = this.data
  155. this.setData({ isManage: !isManage })
  156. },
  157. /**
  158. * 选择图书
  159. */
  160. toggleSelectLiCtl: function (e) {
  161. const { index = -1 } = e.currentTarget.dataset
  162. const { list = [] } = this.data
  163. const { isCheck } = list[index]
  164. list[index].isCheck = isCheck != 1 ? 1 : 2
  165. this.setData({ list })
  166. this.caclulateBook()
  167. },
  168. /**
  169. * 选择全部图书
  170. */
  171. checkAllCtl: function () {
  172. const { selectAll, list = [] } = this.data
  173. for (let i in list) {
  174. list[i]['isCheck'] = selectAll != 1 ? 1 : 2
  175. }
  176. this.setData({ list })
  177. this.caclulateBook()
  178. },
  179. /**
  180. * 计算书籍
  181. */
  182. caclulateBook: function () {
  183. const { list } = this.data
  184. let num = 0
  185. let ids = []
  186. for (let v of list) {
  187. if (v['isCheck'] == 1) {
  188. num++
  189. ids.push(v['id'])
  190. }
  191. }
  192. this.setData({ totalNum: num, ids, selectAll: ids.length == list.length?1:2 })
  193. },
  194. /**
  195. * 签到签离
  196. */
  197. SignSubmit: function () {
  198. const continuousFn = { fn: this.delCtl, param: { ...arguments } }
  199. const { ids = [], options = {}, selectAll, libId = '', type = 0, childName } = this.data
  200. if (!ids.length) {
  201. wx.showToast({
  202. title: '请先选中要签到的学生',
  203. icon: 'none'
  204. })
  205. return
  206. }
  207. SignSubmit({ data: { ids, libId, type, selectAll, childName }, continuousFn }).then(res => {
  208. this.setData({ pageNo: 1 })
  209. this.getData()
  210. wx.hideLoading()
  211. wx.showToast({
  212. title: res.msg
  213. })
  214. })
  215. },
  216. /**
  217. * 到达提交
  218. */
  219. submitCtl: function () {
  220. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  221. const { options = {} } = this.data
  222. const { libId = '', type = 0 } = options
  223. if (!libId) {
  224. wx.showToast({
  225. title: '请先选择馆',
  226. icon: 'none'
  227. })
  228. return
  229. }
  230. const titles = ['', '离馆成功', '到达成功']
  231. const fn = [null, ConfirmToZb, ConfirmToLib]
  232. if (isFn(fn[type])) {
  233. wx.showLoading({
  234. title: '提交中...',
  235. })
  236. fn[type]({ data: { libId }, continuousFn }).then(res => {
  237. wx.hideLoading()
  238. wx.showToast({
  239. title: titles[type]
  240. })
  241. setTimeout(() => {
  242. navigateBack()
  243. }, 2000)
  244. }).catch(() => {
  245. wx.hideLoading()
  246. })
  247. }
  248. }
  249. })