book_inventory.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // president/pages/book_inventory/book_inventory.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { CallOutList, CallInList, DeleteBooks, SaveLocking, CallInBooks } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. thumbnail,
  14. isLoaded: 0,
  15. bookList: [
  16. {
  17. bookExchangeNum: '',
  18. bookInNum: ''
  19. }
  20. ],
  21. isDown:false,
  22. navIndex: 0,
  23. pageSize: 10,
  24. pageNo: 1,
  25. navList: [
  26. {
  27. text: '批量删减',
  28. list: [],
  29. pageSize: 10,
  30. pageNo: 1,
  31. isAll: 0,
  32. isSend: 0,
  33. num: 0
  34. },
  35. {
  36. text: '确定调入',
  37. list: [],
  38. pageSize: 10,
  39. pageNo: 1,
  40. isAll: 0,
  41. isSend: 0,
  42. num: 0
  43. },
  44. ],
  45. footerData: {
  46. actIndex: 2,
  47. list: [
  48. {
  49. text: '在馆书籍',
  50. icon: '../../../assets/zai_guan_shu_ji_gray.png',
  51. actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
  52. url: 'president/pages/library_books/library_books',
  53. zindex: 3
  54. },
  55. {
  56. text: '好书推荐',
  57. icon: '../../../assets/wish_gray.png',
  58. actIcon: '../../../assets/wish_blue.png',
  59. url: 'president/pages/good_books_new/good_books_new',
  60. zindex: 3
  61. },
  62. {
  63. text: '调书清单',
  64. icon: '../../../assets/diao_shu_qing_dan_gray.png',
  65. actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
  66. url: 'president/pages/book_inventory/book_inventory',
  67. zindex: 3
  68. }
  69. ]
  70. },
  71. nodataArray: {
  72. text: "调书清单空空的,快去选书吧"
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面加载
  77. */
  78. onLoad: function (options) {
  79. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  80. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  81. this.setData(options)
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  88. for (const i in obj) {
  89. this[i] = obj[i]
  90. }
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow: function () {
  96. // debugger
  97. const show = wx.getStorageSync('hiddenGetallModel')
  98. this.setData({ hiddenGetallModel: show })
  99. this.getData(() => {
  100. this.setData({ pageNo:1})
  101. })
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload: function () {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh: function () {
  117. const temp = {}
  118. temp[`navList[${navIndex}].pageNo`] = 1
  119. this.setData(temp)
  120. this.getData(() => {
  121. wx.stopPullDownRefresh()
  122. })
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. const { isAll, isDown } = this.data
  129. if (isAll) {
  130. this.setData({ isDown: true })
  131. return
  132. } else {
  133. this.setData({ isLoad: true, isDown: false })
  134. this.getData(() => {
  135. this.setData({ isLoad: false })
  136. })
  137. }
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. if (isFn(sharePage)) return sharePage()
  144. },
  145. /**
  146. * 选择导航栏
  147. */
  148. selectNavCtl: function (e) {
  149. const { index } = e.currentTarget.dataset
  150. const { navIndex, navList } = this.data
  151. // if (navIndex == index) return
  152. if (index == 0) {
  153. navigateTo({
  154. url: 'president/pages/book_delete_list/book_delete_list',
  155. })
  156. }
  157. if (index == 1) {
  158. wx.showToast({
  159. title: '请准备需要调走的图书,等待“送书侠”上门领走哦',
  160. icon: 'none',
  161. duration: 3000
  162. })
  163. this.saveLocking()
  164. }
  165. // this.setData({ navIndex: index })
  166. // const { list } = navList[index]
  167. // if (list.length > 0) return
  168. // this.getData()
  169. },
  170. /**
  171. * 提示框隐藏
  172. */
  173. allShowModel: function () {
  174. wx.setStorageSync('hiddenGetallModel', false)
  175. this.setData({ hiddenGetallModel: false })
  176. },
  177. /**
  178. * 申请书单
  179. */
  180. applybookLists: function () {
  181. navigateTo({
  182. url: 'president/pages/apply_bookLists/apply_booklists',
  183. })
  184. },
  185. /**
  186. * 调入与调出
  187. */
  188. getData: function (cb) {
  189. const continuousFn = { fn: this.getData, param: { ...arguments } }
  190. const { pageNo, pageSize, libId } = this.data
  191. CallInList({ data: { libId, pageNo, pageSize, callType:1 }, continuousFn}).then(res => {
  192. const { readNum = 0, bookExchangeNum = 0, booksSize = 0,bookInNum = 0, isSend = false } = res.data
  193. const { list } = res.data
  194. const correctListTemp = (res => {
  195. // console.log(res)
  196. var d = []
  197. for (let i in res) {
  198. res[i].number = res[i].select_size
  199. }
  200. return res
  201. })(list)
  202. let listTemp = []
  203. if (pageNo == 1) {
  204. listTemp = [].concat(correctListTemp)
  205. } else {
  206. listTemp = [].concat(this.data.list, correctListTemp)
  207. }
  208. // console.log(listTemp)
  209. this.setData({
  210. bookExchangeNum,
  211. bookInNum,
  212. list: listTemp,
  213. pageNo: list.length == pageSize ? pageNo + 1 : pageNo,
  214. isAll: list.length < pageSize,
  215. isLoaded: true
  216. })
  217. if (isFn(cb)) cb()
  218. }).catch(res => {
  219. this.setData({ isLoaded: true })
  220. if (isFn(cb)) cb()
  221. })
  222. },
  223. /**
  224. * 调入
  225. */
  226. addBook: function (e) {
  227. const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
  228. const continuousFn = { fn: this.addBook, param: { ...arguments } }
  229. const { libId, list } = this.data
  230. var that=this;
  231. var numbers = number;
  232. var temp = {};
  233. if (numbers < size) {
  234. numbers = numbers + 1;
  235. this.setData({ number: numbers })
  236. temp[`list[${index}].number`] = numbers
  237. this.setData(temp)
  238. CallInBooks({ data: { libId, bookInfoId: infoid, isbn13 }, continuousFn }).then(res => {
  239. wx.showToast({
  240. title: `已加入调入清单`,
  241. icon: 'none'
  242. })
  243. that.getData(() => {
  244. that.setData({ pageNo:1})
  245. })
  246. })
  247. } else {
  248. if(size==1){
  249. wx.showToast({
  250. title: `该书籍库存只有一本了,无法再添加了`,
  251. icon: 'none'
  252. })
  253. }else{
  254. wx.showToast({
  255. title: `已达上限`,
  256. icon: 'none'
  257. })
  258. }
  259. return
  260. }
  261. },
  262. /**
  263. * 删除
  264. */
  265. subtractionBook: function (e) {
  266. const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
  267. const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
  268. const { list, libId } = this.data
  269. var that = this;
  270. let ids = [];
  271. ids.push(
  272. infoid
  273. )
  274. var numbers = number;
  275. var temp = {};
  276. // console.log(number, index)
  277. if (numbers > 0) {
  278. numbers = numbers - 1;
  279. this.setData({ number: numbers })
  280. temp[`list[${index}].number`] = numbers
  281. this.setData(temp)
  282. DeleteBooks({ data: { ids, libId }, continuousFn }).then(res => {
  283. wx.showToast({
  284. title: `删除成功`,
  285. icon: 'none'
  286. })
  287. that.getData(() => {
  288. that.setData({ pageNo: 1 })
  289. })
  290. })
  291. } else {
  292. this.setData({ number: 0 })
  293. }
  294. },
  295. /**
  296. * 馆长提交锁定库存
  297. */
  298. saveLocking: function () {
  299. const continuousFn = { fn: this.saveLocking, param: { ...arguments } }
  300. const { libId } = this.data;
  301. SaveLocking({ data: { libId }, continuousFn }).then(res => {
  302. wx.showToast({
  303. title: res.msg || '调度员已确认你馆调书申请,请等待调度员与你联系!',
  304. icon: 'none',
  305. duration: 5000
  306. })
  307. this.getData()
  308. }).catch(res => {
  309. // wx.showToast({
  310. // title: res.data.msg || '你馆阅读会员数量还不足35名,请继续加油达到目标哦~',
  311. // icon: 'none',
  312. // duration: 5000
  313. // })
  314. })
  315. }
  316. })