search_books_new.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. // president/pages/home/home.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetBooksTab, GoodBooksSearch, CallOutBooks, CallInBooks, DeleteBooks} 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. title: '',
  16. pageSize: 10,
  17. pageNo: 1,
  18. isAll: 0,
  19. isResult:false,
  20. isDown:false,
  21. GrangeList: ['学前段', '低年段', '中年段', '高年段'],
  22. bookList: [
  23. {
  24. name: '在馆书籍',
  25. amount: '',
  26. unit: '本'
  27. },
  28. {
  29. name: '服务期会员',
  30. amount: '',
  31. unit: '人'
  32. },
  33. {
  34. name: '在借书籍',
  35. amount: '',
  36. unit: '本'
  37. },
  38. ],
  39. isShow: 0,
  40. itemIndex: 0,
  41. items: ['根据入馆时间排序', '根据书籍借阅量排序', '根据馆藏稀缺度排序'],
  42. list: [
  43. ],
  44. footerData: {
  45. actIndex: 0,
  46. list: [
  47. {
  48. text: '在馆书籍',
  49. icon: '../../../assets/zai_guan_shu_ji_gray.png',
  50. actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
  51. url: 'president/pages/home/home',
  52. zindex: 3
  53. },
  54. {
  55. text: '好书推荐',
  56. icon: '../../../assets/wish_gray.png',
  57. actIcon: '../../../assets/wish_blue.png',
  58. url: 'president/pages/good_books_new/good_books_new',
  59. zindex: 3
  60. },
  61. {
  62. text: '调书清单',
  63. icon: '../../../assets/diao_shu_qing_dan_gray.png',
  64. actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
  65. url: 'president/pages/book_inventory/book_inventory',
  66. zindex: 3
  67. }
  68. ]
  69. },
  70. nodataArray: {
  71. text: "暂时还没有这本书,可以申请哦~"
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面加载
  76. */
  77. onLoad: function (options) {
  78. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  79. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  80. this.setData(options)
  81. this.getData(res => {
  82. this.setData({ isLoaded: 1 })
  83. })
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  90. for (const i in obj) {
  91. this[i] = obj[i]
  92. }
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. // this.setData({ pageNo: 1 })
  114. // this.getData(res => {
  115. // wx.stopPullDownRefresh()
  116. // })
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function () {
  122. const { isAll, isDown } = this.data
  123. if (isAll) {
  124. this.setData({ isDown: true })
  125. return
  126. } else {
  127. this.setData({ isLoad: true, isDown: false })
  128. this.getData(() => {
  129. this.setData({ isLoad: false })
  130. })
  131. }
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage: function () {
  137. if (isFn(sharePage)) return sharePage()
  138. },
  139. /**
  140. * 展示选择框
  141. */
  142. showItemCtl: function () {
  143. const { isShow } = this.data
  144. this.setData({ isShow: !isShow })
  145. },
  146. /**
  147. * 展示选择框
  148. */
  149. selectItemCtl: function (e) {
  150. const { index } = e.currentTarget.dataset
  151. const { itemIndex, items } = this.data
  152. if (index == itemIndex) return
  153. this.setData({ itemIndex: index, isShow: 0, pageNo: 1 })
  154. this.getData()
  155. },
  156. /**
  157. * 获取书籍数据
  158. */
  159. getData: function (cb) {
  160. const continuousFn = { fn: this.getData, param: { ...arguments } }
  161. const { content, options, pageNo, pageSize, itemIndex, title } = this.data
  162. const { libId } = this.data;
  163. GoodBooksSearch({ data: { title, pageNo, pageSize }, continuousFn }).then(res => {
  164. const { list } = res.data
  165. let listTemp = []
  166. if (pageNo == 1) {
  167. listTemp = [].concat(list)
  168. } else {
  169. listTemp = [].concat(this.data.list, list)
  170. }
  171. const correctListTemp = (res => {
  172. console.log(res)
  173. var d = []
  174. for (let i in res) {
  175. res[i].number = 0
  176. }
  177. return res
  178. })(listTemp)
  179. this.setData({ list: correctListTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  180. cb && cb(res)
  181. }).catch(res => {
  182. cb && cb(res)
  183. })
  184. },
  185. /**
  186. * 调出书籍
  187. */
  188. getBooksCtl: function (e) {
  189. const { index } = e.currentTarget.dataset;
  190. const continuousFn = { fn: this.getBooksCtl, param: { ...arguments } }
  191. const { list, libId } = this.data
  192. const { book_info_id, book_detail_id, isbn13 } = list[index]
  193. CallOutBooks({ data: { libId, bookInfoId: book_info_id, bookDetailId: book_detail_id, isbn13 }, continuousFn }).then(res => {
  194. wx.showToast({
  195. title: `已加入调出列表`
  196. })
  197. this.getData()
  198. })
  199. },
  200. /**
  201. * 输入搜索值
  202. */
  203. inputSearchCtl: function (e) {
  204. const { value } = e.detail
  205. const { title } = this.data
  206. if (title == value) return
  207. const temp = {}
  208. temp[`title`] = value
  209. this.setData(temp)
  210. },
  211. /**
  212. * 清除搜索值
  213. */
  214. clearSearchCtl: function () {
  215. const temp = {}
  216. temp[`title`] = ''
  217. this.setData(temp)
  218. },
  219. /**
  220. * 提交搜索值
  221. */
  222. submitSearchCtl: function () {
  223. const {title}=this.data;
  224. if (!title){
  225. wx.showToast({
  226. title: `搜索内容不能为空`,
  227. icon: 'none'
  228. })
  229. return
  230. }
  231. const temp = {}
  232. temp[`pageNo`] = 1
  233. this.setData(temp)
  234. this.getData(res=>{
  235. this.setData({ isResult:true})
  236. })
  237. },
  238. /**
  239. * 调入
  240. */
  241. addBook: function (e) {
  242. const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
  243. const continuousFn = { fn: this.addBook, param: { ...arguments } }
  244. const { libId, list } = this.data
  245. var numbers = number;
  246. var temp = {};
  247. if (numbers < size) {
  248. numbers = numbers + 1;
  249. this.setData({ number: numbers })
  250. temp[`list[${index}].number`] = numbers
  251. this.setData(temp)
  252. CallInBooks({ data: { libId, bookInfoId: infoid, isbn13 }, continuousFn }).then(res => {
  253. wx.showToast({
  254. title: `已加入调入清单`,
  255. icon: 'none'
  256. })
  257. // this.getData()
  258. })
  259. } else {
  260. if (size == 1) {
  261. wx.showToast({
  262. title: `该书籍库存只有一本了,无法再添加了`,
  263. icon: 'none'
  264. })
  265. } else {
  266. wx.showToast({
  267. title: `已达上限`,
  268. icon: 'none'
  269. })
  270. }
  271. return
  272. }
  273. },
  274. /**
  275. * 删除
  276. */
  277. subtractionBook: function (e) {
  278. const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
  279. const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
  280. const { list, libId } = this.data
  281. let ids = [];
  282. ids.push(
  283. infoid
  284. )
  285. var numbers = number;
  286. var temp = {};
  287. console.log(number, index)
  288. if (numbers > 0) {
  289. numbers = numbers - 1;
  290. this.setData({ number: numbers })
  291. temp[`list[${index}].number`] = numbers
  292. this.setData(temp)
  293. DeleteBooks({ data: { ids, libId }, continuousFn }).then(res => {
  294. wx.showToast({
  295. title: `删除成功`,
  296. icon: 'none'
  297. })
  298. // this.getData()
  299. })
  300. } else {
  301. wx.showToast({
  302. title: `已经删除`,
  303. icon: 'none'
  304. })
  305. return
  306. }
  307. }
  308. })