Search_sign_number.js 6.6 KB

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