sweeped_books.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. // dispatcher/pages/sweeped_books/sweeped_books.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetSweepedBooks, DeleteSweepedBooks, DispatcherScanning, ConfirmToLib, ConfirmToZb } 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. ids: [],
  19. pageNo: 1,
  20. pageSize: 10,
  21. isAll: 0,
  22. totalNumbers: 0,
  23. list: [
  24. // {
  25. // "order_num": "1",
  26. // "username": "12154545",
  27. // "title": "福建师大雷锋精神连接方式精神连接方式垃圾精神连接方式垃圾精神连接接方式精神连接方式垃圾精神连接方式垃圾精神连接方式垃圾垃圾分方式垃圾垃圾分类是就发了是家乐福",
  28. // "reg_time": "1436864169",
  29. // parent_name: '地方就是到了封精神连接方式垃圾精神连接方式垃圾精神连接方式垃圾建士大夫的',
  30. // child_name: 'sdfsfsf',
  31. // color: '#ff5050',
  32. // "wish_num": "0",
  33. // },
  34. // {
  35. // "order_num": "1",
  36. // "username": "12154545",
  37. // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
  38. // "reg_time": "1436864169",
  39. // parent_name: '地方就是到了封建士大夫的',
  40. // child_name: 'sdfsfsf',
  41. // color: '#000',
  42. // "wish_num": "0",
  43. // },
  44. // {
  45. // "order_num": "1",
  46. // "username": "12154545",
  47. // "title": "福建师大乐福",
  48. // "reg_time": "1436864169",
  49. // parent_name: '地方就是到了封建士大夫的',
  50. // child_name: 'sdfsfsf',
  51. // "wish_num": "0",
  52. // },
  53. // {
  54. // "order_num": "1",
  55. // "username": "12154545",
  56. // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
  57. // "reg_time": "1436864169",
  58. // parent_name: '地方就是到了封建士大夫的',
  59. // child_name: 'sdfsfsf',
  60. // "wish_num": "0",
  61. // },
  62. // {
  63. // "order_num": "1",
  64. // "username": "12154545",
  65. // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
  66. // "reg_time": "1436864169",
  67. // parent_name: '地方就是到了封建士大夫的',
  68. // child_name: 'sdfsfsf',
  69. // "wish_num": "0",
  70. // },
  71. // {
  72. // "order_num": "1",
  73. // "username": "12154545",
  74. // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
  75. // "reg_time": "1436864169",
  76. // parent_name: '地方就是到了封建士大夫的',
  77. // child_name: 'sdfsfsf',
  78. // "wish_num": "0",
  79. // },
  80. ],
  81. nodataArray: {
  82. text: "暂无图书",
  83. image: '../../../assets/nodata_1.png',
  84. margin: '400rpx auto'
  85. }
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad: function (options) {
  91. const titles = ['', '带书离馆', '调配中', '待调配']
  92. const btnText = ['', '离馆', '送达', '']
  93. const { type = 0 } = options
  94. options.type = ~~type
  95. options.title = titles[type]
  96. options.btnText = btnText[type]
  97. options.userId = getGlobalVal('userId')
  98. options.libId = (options.libId ? options.libId : getGlobalVal(`dispatchLibId_${options.userId}`) ? getGlobalVal(`dispatchLibId_${options.userId}`) : '')
  99. this.setData({ options })
  100. this.getData(res => {
  101. this.setData({ isLoaded: true })
  102. })
  103. wx.setNavigationBarTitle({
  104. title: titles[type],
  105. })
  106. },
  107. /**
  108. * 生命周期函数--监听页面初次渲染完成
  109. */
  110. onReady: function () {
  111. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  112. for (const i in obj) {
  113. this[i] = obj[i]
  114. }
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {
  135. this.setData({ pageNo: 1 })
  136. this.getData(res => {
  137. wx.stopPullDownRefresh()
  138. })
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. const { isAll = false } = this.data
  145. if (isAll) return
  146. this.getData()
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. if (isFn(sharePage)) return sharePage()
  153. },
  154. /**
  155. * 获取数据
  156. */
  157. getData: function (cb) {
  158. const continuousFn = { fn: this.getData, param: { ...arguments } }
  159. const { list = [], pageNo = 1, pageSize = 10, options = {} } = this.data
  160. const { libId = '', type = 0 } = options
  161. if (!libId) {
  162. wx.showToast({
  163. title: '请先选择馆',
  164. icon: 'none'
  165. })
  166. cb && cb()
  167. return
  168. }
  169. if (!type) {
  170. wx.showToast({
  171. title: '出了点小问题',
  172. icon: 'none'
  173. })
  174. cb && cb()
  175. return
  176. }
  177. GetSweepedBooks({ data: { type, libId, pageNo, pageSize }, continuousFn }).then(res => {
  178. const newList = res.data.list
  179. const totalNumbers = res.data.pages || 0
  180. let listTemp = []
  181. if (pageNo == 1) {
  182. listTemp = [].concat(newList)
  183. } else {
  184. listTemp = [].concat(list, newList)
  185. }
  186. const temp = {}
  187. temp['list'] = listTemp
  188. temp['pageNo'] = newList.length == pageSize ? pageNo + 1 : pageNo
  189. temp['isAll'] = newList.length < pageSize
  190. temp['totalNumbers'] = totalNumbers
  191. this.setData(temp)
  192. this.caclulateBook()
  193. cb && cb(res)
  194. }).catch(res => {
  195. cb && cb(res)
  196. })
  197. },
  198. /**
  199. * 切换管理和取消按钮
  200. */
  201. toggleManageCtl: function () {
  202. const { isManage = false } = this.data
  203. this.setData({ isManage: !isManage })
  204. },
  205. /**
  206. * 选择图书
  207. */
  208. toggleSelectLiCtl: function (e) {
  209. const { index = -1 } = e.currentTarget.dataset
  210. const { list = [] } = this.data
  211. const { isCheck } = list[index]
  212. list[index].isCheck = isCheck != 1 ? 1 : 0
  213. this.setData({ list })
  214. this.caclulateBook()
  215. },
  216. /**
  217. * 选择全部图书
  218. */
  219. checkAllCtl: function () {
  220. const { isAllCheck, list = [] } = this.data
  221. for (let i in list) {
  222. list[i]['isCheck'] = isAllCheck != 1 ? 1 : 0
  223. }
  224. this.setData({ list })
  225. this.caclulateBook()
  226. },
  227. /**
  228. * 计算书籍
  229. */
  230. caclulateBook: function () {
  231. const { list } = this.data
  232. let num = 0
  233. let ids = []
  234. for (let v of list) {
  235. if (v['isCheck'] == 1) {
  236. num++
  237. ids.push(v['id'])
  238. }
  239. }
  240. this.setData({ totalNum: num, ids, isAllCheck: ids.length == list.length })
  241. },
  242. /**
  243. * 删除
  244. */
  245. delCtl: function () {
  246. const continuousFn = { fn: this.delCtl, param: { ...arguments } }
  247. const { ids = [], options = {} } = this.data
  248. const { libId = '', type = 0 } = options
  249. if (!ids.length) {
  250. wx.showToast({
  251. title: '请先选中要删除的图书',
  252. icon: 'none'
  253. })
  254. return
  255. }
  256. DeleteSweepedBooks({ data: { ids, libId, type }, continuousFn }).then(res => {
  257. this.setData({ pageNo: 1 })
  258. this.getData()
  259. })
  260. },
  261. /**
  262. * 到达提交
  263. */
  264. submitCtl: function () {
  265. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  266. const { options = {} } = this.data
  267. const { libId = '', type = 0 } = options
  268. if (!libId) {
  269. wx.showToast({
  270. title: '请先选择馆',
  271. icon: 'none'
  272. })
  273. return
  274. }
  275. const titles = ['', '离馆成功', '到达成功']
  276. const fn = [null, ConfirmToZb, ConfirmToLib]
  277. if (isFn(fn[type])) {
  278. wx.showLoading({
  279. title: '提交中...',
  280. })
  281. fn[type]({ data: { libId }, continuousFn }).then(res => {
  282. wx.hideLoading()
  283. wx.showToast({
  284. title: titles[type]
  285. })
  286. setTimeout(() => {
  287. navigateBack()
  288. }, 2000)
  289. }).catch(() => {
  290. wx.hideLoading()
  291. })
  292. }
  293. }
  294. })