random_books.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. // president//pages/random_books/random_books.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { RandomBook, GetBooksTab } 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. screenModel: false,
  13. submitModel:false,
  14. isCheck:0,
  15. title:'',
  16. classList:[],
  17. bookList:[],
  18. numList:[
  19. {
  20. text:'100',
  21. isCheck:''
  22. },
  23. {
  24. text: '120',
  25. isCheck: ''
  26. },
  27. {
  28. text: '150',
  29. isCheck: ''
  30. },
  31. {
  32. text: '',
  33. isCheck: ''
  34. },
  35. ]
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  42. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  43. this.setData(options)
  44. },
  45. /**
  46. * 生命周期函数--监听页面初次渲染完成
  47. */
  48. onReady: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. this.getBooksTab()
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload: function () {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh: function () {
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom: function () {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. },
  81. /**
  82. * 提示框隐藏
  83. */
  84. screenShowModel: function () {
  85. this.setData({ screenModel: false,submitModel:false })
  86. },
  87. /**
  88. * 筛选
  89. */
  90. getScreen: function () {
  91. this.setData({ screenModel: true })
  92. },
  93. /**
  94. * 筛选
  95. */
  96. getBooksTab: function () {
  97. const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
  98. const { libId } = this.data
  99. GetBooksTab({ data: { libId }, continuousFn }).then(res => {
  100. const { gradeList, themeList } = res.data;
  101. this.setData({ gradeList, themeList })
  102. })
  103. },
  104. /**
  105. * 随机调书
  106. */
  107. submitBook:function(){
  108. const { bookSize, bookList, classList } = this.data
  109. if (!bookSize) {
  110. wx.showToast({
  111. title: `请填写数量`,
  112. icon:'none'
  113. })
  114. return
  115. }
  116. // if (classList.length == 0) {
  117. // wx.showToast({
  118. // title: `请选择年级`,
  119. // icon: 'none'
  120. // })
  121. // return
  122. // }
  123. // if (bookList.length == 0) {
  124. // wx.showToast({
  125. // title: `请选择主题`,
  126. // icon: 'none'
  127. // })
  128. // return
  129. // }
  130. this.setData({ submitModel: true })
  131. },
  132. /**
  133. * 选择书本数量
  134. */
  135. selectNum:function(e){
  136. const { index } = e.currentTarget.dataset
  137. const { numList } = this.data
  138. const temp = {}
  139. for (var i in numList) {
  140. temp[`numList[${i}].isCheck`] = ''
  141. }
  142. temp[`numList[${index}].isCheck`] = numList[index].isCheck == "" ? "active" : ''
  143. this.setData(temp)
  144. for (var i in numList) {
  145. if (numList[i].isCheck == 'active') {
  146. this.setData({ bookSize: numList[i].text })
  147. }
  148. }
  149. },
  150. /**
  151. * 选择年级
  152. */
  153. selectGrade: function (e) {
  154. const { index } = e.currentTarget.dataset
  155. const { isCheck, gradeList, classList,title } = this.data
  156. const temp = {}
  157. temp[`gradeList[${index}].isCheck`] = gradeList[index].isCheck != 1 ? 1 : 0
  158. this.setData(temp)
  159. if (gradeList[index].isCheck == 1) {
  160. this.setData({ title: gradeList[index].grade + ',' + title + '' })
  161. classList.push({
  162. grade: gradeList[index].grade
  163. })
  164. } else if (gradeList[index].isCheck == 0) {
  165. for (var i in classList) {
  166. if (gradeList[index].grade == classList[i].grade) {
  167. classList.splice(i, 1)
  168. }
  169. }
  170. }
  171. this.setData({ classList })
  172. },
  173. /**
  174. * 选择主题
  175. */
  176. selectTheme: function (e) {
  177. const { index, key, type } = e.currentTarget.dataset
  178. const { isCheck, themeList, bookList = [], childList = [],title } = this.data
  179. const temp = {}
  180. if (type == 1) {
  181. temp[`themeList[${index}].isCheck`] = themeList[index].isCheck != 1 ? 1 : 0
  182. this.setData(temp)
  183. if (themeList[index].isCheck == 1) {
  184. this.setData({ title: title + '' + themeList[index].name + ',' })
  185. bookList.push({
  186. code: themeList[index].code,
  187. childList
  188. })
  189. } else if (themeList[index].isCheck == 0) {
  190. for (var i in bookList) {
  191. if (themeList[index].code == bookList[i].code) {
  192. bookList.splice(i, 1)
  193. }
  194. }
  195. }
  196. } else {
  197. temp[`themeList[${index}].childList[${key}].isCheck`] = themeList[index].childList[key].isCheck != 1 ? 1 : 0
  198. this.setData(temp)
  199. for (var i in themeList) {
  200. for (var j in themeList[i].childList) {
  201. if (themeList[i].childList[j].isCheck == 1) {
  202. if (themeList[i].code == themeList[index].code) {
  203. childList.push({
  204. code: themeList[i].childList[j].code
  205. })
  206. }
  207. bookList.push({
  208. code: themeList[i].code,
  209. childList
  210. })
  211. }
  212. }
  213. }
  214. }
  215. this.setData({ bookList })
  216. console.log(bookList)
  217. },
  218. /**
  219. * 重置
  220. */
  221. getReset: function () {
  222. const { themeList, gradeList } = this.data
  223. const temp = {}
  224. for (var i in gradeList) {
  225. temp[`gradeList[${i}].isCheck`] = 0
  226. }
  227. for (var i in themeList) {
  228. temp[`themeList[${i}].isCheck`] = 0
  229. for (var j in themeList[i].childList) {
  230. temp[`themeList[${i}].childList[${j}].isCheck`] = 0
  231. }
  232. }
  233. this.setData(temp)
  234. this.setData({ classList: [], bookList: [],title:'' })
  235. },
  236. /**
  237. * 提交
  238. */
  239. getSubmit: function () {
  240. const { themeList, gradeList} = this.data
  241. this.setData({screenModel: false })
  242. },
  243. /**
  244. * 输入搜索值
  245. */
  246. inputSearchCtl: function (e) {
  247. const { value } = e.detail
  248. if (value<151){
  249. this.setData({ bookSize: value })
  250. }else{
  251. wx.showToast({
  252. title: `调书数量不能大于150本`,
  253. icon:'none'
  254. })
  255. }
  256. console.log(value)
  257. },
  258. /**
  259. * 筛选
  260. */
  261. getRandomBook: function () {
  262. const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
  263. const { libId, bookSize, bookList, classList } = this.data
  264. console.log(libId, bookSize, bookList, classList)
  265. RandomBook({ data: { libId, bookSize, gradeList: classList, themeList: bookList }, continuousFn }).then(res => {
  266. this.setData({ submitModel: false, classList: [], bookList: [] })
  267. wx.showToast({
  268. title: `提交成功`
  269. })
  270. })
  271. },
  272. })