part_call_in.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. // president/pages/part_call_in/part_call_in.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetThemeAllBook, BatchCallInBooks, 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. isLoad:false,
  16. title: '',
  17. pageNo: 1,
  18. pageSize: 10,
  19. isAll: false,
  20. navIndex: 0,
  21. list: [],
  22. isAllCheck: 0,
  23. isBatch:false,
  24. isManage: 0,
  25. totalNum: 0,
  26. number:0
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  33. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  34. options.gradeList = JSON.parse(options.gradeList)
  35. wx.setNavigationBarTitle({
  36. title: `${options.theme}`,
  37. })
  38. this.setData(options)
  39. this.setData({isAllCheck: options.status == 1 })
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  46. for (const i in obj) {
  47. this[i] = obj[i]
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. this.getData(() => {
  55. this.setData({ isLoaded: true })
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload: function () {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {
  72. this.setData({ pageNo: 1 })
  73. this.getData(() => {
  74. wx.stopPullDownRefresh()
  75. })
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom: function () {
  81. const { isAll } = this.data
  82. if (isAll) return
  83. this.setData({ isLoad: true })
  84. this.getData(() => {
  85. this.setData({ isLoad: false })
  86. })
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage: function () {
  92. if (isFn(sharePage)) return sharePage()
  93. },
  94. /**
  95. * 调入
  96. */
  97. addBook: function (e) {
  98. const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
  99. const continuousFn = { fn: this.addBook, param: { ...arguments } }
  100. const { libId, list } = this.data
  101. var numbers = number;
  102. console.log(list)
  103. var temp = {};
  104. if (numbers < size) {
  105. numbers = numbers + 1;
  106. this.setData({ number: numbers })
  107. temp[`list[${index}].number`] = numbers
  108. this.setData(temp)
  109. CallInBooks({ data: { libId, bookInfoId: infoid, isbn13 }, continuousFn }).then(res => {
  110. wx.showToast({
  111. title: `已加入调入清单`,
  112. icon: 'none'
  113. })
  114. // this.getData()
  115. })
  116. } else {
  117. if (size == 1) {
  118. wx.showToast({
  119. title: `该书籍库存只有一本了,无法再添加了`,
  120. icon: 'none'
  121. })
  122. } else {
  123. wx.showToast({
  124. title: `已达上限`,
  125. icon: 'none'
  126. })
  127. }
  128. return
  129. }
  130. },
  131. /**
  132. * 删除
  133. */
  134. subtractionBook: function (e) {
  135. const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
  136. const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
  137. const { list, libId } = this.data
  138. let ids = [];
  139. ids.push(
  140. infoid
  141. )
  142. var numbers = number;
  143. var temp = {};
  144. console.log(number, index)
  145. if (numbers > 0) {
  146. numbers = numbers - 1;
  147. this.setData({ number: numbers })
  148. temp[`list[${index}].number`] = numbers
  149. this.setData(temp)
  150. DeleteBooks({ data: { ids, libId }, continuousFn }).then(res => {
  151. wx.showToast({
  152. title: `删除成功`,
  153. icon: 'none'
  154. })
  155. // this.getData()
  156. })
  157. } else {
  158. wx.showToast({
  159. title: `已经删除`,
  160. icon: 'none'
  161. })
  162. return
  163. }
  164. },
  165. /**
  166. * 批量选择
  167. */
  168. getBatch:function(){
  169. const { isBatch}=this.data
  170. this.setData({ isBatch: !isBatch})
  171. },
  172. /**
  173. * 归类书籍
  174. */
  175. getData: function (cb) {
  176. const continuousFn = { fn: this.getData, param: { ...arguments } }
  177. const { pageNo, pageSize, list, childTheme, status, isAllCheck, title, gradeList } = this.data
  178. GetThemeAllBook({ data: { childTheme, pageNo, pageSize, title, gradeList }, continuousFn }).then(res => {
  179. const newList = ((list, isCheck) => {
  180. for (let i in list) {
  181. list[i].isCheck = isCheck
  182. list[i].number = 0
  183. }
  184. return list
  185. })(res.data.list, isAllCheck)
  186. console.log(newList)
  187. let tempList = []
  188. if (pageNo == 1) {
  189. tempList = newList
  190. } else {
  191. tempList = [...list, ...newList]
  192. }
  193. const temp = {}
  194. temp[`list`] = tempList
  195. temp['pageNo'] = newList.length == pageSize ? ~~pageNo + 1 : pageNo
  196. temp['isAll'] = newList.length < pageSize
  197. this.setData(temp)
  198. this.caclulateBook()
  199. if (isFn(cb)) cb()
  200. }).catch(res => {
  201. if (isFn(cb)) cb()
  202. })
  203. },
  204. /**
  205. * 选择全部图书
  206. */
  207. checkAllCtl: function () {
  208. const { list, isAllCheck } = this.data
  209. const temp = {}
  210. for (let i in list) {
  211. temp[`list[${i}].isCheck`] = isAllCheck != 1 ? 1 : 0
  212. }
  213. this.setData(temp)
  214. this.caclulateBook()
  215. },
  216. /**
  217. * 选择图书
  218. */
  219. toggleSelectLiCtl: function (e) {
  220. const { index } = e.currentTarget.dataset
  221. const { list } = this.data
  222. const { isCheck = 0 } = list[index]
  223. const temp = {}
  224. temp[`list[${index}].isCheck`] = isCheck != 1 ? 1 : 0
  225. this.setData(temp)
  226. this.caclulateBook()
  227. },
  228. /**
  229. * 计算书籍
  230. */
  231. caclulateBook: function () {
  232. const { list } = this.data
  233. let num = 0
  234. const bookList = []
  235. for (const v of list) {
  236. const { book_detail_id, book_info_id, isbn13, isCheck } = v
  237. if (isCheck == 1) {
  238. num++
  239. bookList.push({
  240. bookInfoId: book_info_id,
  241. bookDetailId: book_detail_id,
  242. isbn13
  243. })
  244. }
  245. }
  246. this.setData({ totalNum: num, bookList, isAllCheck: bookList.length == list.length })
  247. },
  248. /**
  249. * 确认调入
  250. */
  251. getCallin: function () {
  252. const continuousFn = { fn: this.getCallin, param: { ...arguments } }
  253. const { bookList, vipId, libId } = this.data
  254. BatchCallInBooks({ data: { libId, bookList }, continuousFn }).then(res => {
  255. wx.showToast({
  256. title: `已加入调入列表`
  257. })
  258. this.getData()
  259. })
  260. },
  261. /**
  262. * 取消调入
  263. */
  264. cancelCallin: function () {
  265. this.setData({ isAllCheck: 1 })
  266. this.checkAllCtl()
  267. },
  268. /**
  269. * 输入搜索值
  270. */
  271. inputSearchCtl: function (e) {
  272. const { value } = e.detail
  273. const { title } = this.data
  274. if (title == value) return
  275. const temp = {}
  276. temp[`title`] = value
  277. this.setData(temp)
  278. },
  279. /**
  280. * 清除搜索值
  281. */
  282. clearSearchCtl: function () {
  283. const temp = {}
  284. temp[`title`] = ''
  285. this.setData(temp)
  286. },
  287. /**
  288. * 提交搜索值
  289. */
  290. submitSearchCtl: function () {
  291. const temp = {}
  292. temp[`pageNo`] = 1
  293. this.setData(temp)
  294. this.getData()
  295. },
  296. })