teaching.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // pages/teaching/teaching.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  3. import { BookList} from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. pageNo:1,
  14. pageSize:10,
  15. isTeaching:false,
  16. list:[
  17. {
  18. subject:'语文',
  19. imgUrl:'../../assets/yuwen.png',
  20. bookList:[]
  21. },
  22. {
  23. subject: '数学',
  24. imgUrl: '../../assets/shuxue.png',
  25. bookList: []
  26. },
  27. {
  28. subject: '英语',
  29. imgUrl: '../../assets/yingyu.png',
  30. bookList: []
  31. }
  32. ],
  33. teachList: [
  34. // {
  35. // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb",
  36. // "bookName": "黄冈作业本1",
  37. // "subject": "语文",
  38. // "version": 1,
  39. // "versionName": "人教版"
  40. // },
  41. // {
  42. // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb",
  43. // "bookName": "黄冈作业本2",
  44. // "subject": "语文",
  45. // "version": 1,
  46. // "versionName": "人教版"
  47. // },
  48. // {
  49. // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb",
  50. // "bookName": "黄冈作业本3",
  51. // "subject": "语文",
  52. // "version": 1,
  53. // "versionName": "人教版"
  54. // },
  55. // {
  56. // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb",
  57. // "bookName": "黄冈作业本4",
  58. // "subject": "语文",
  59. // "version": 1,
  60. // "versionName": "人教版"
  61. // }
  62. ],
  63. bookId:'',
  64. subject:''
  65. },
  66. /**
  67. * 生命周期函数--监听页面加载
  68. */
  69. onLoad: function (options) {
  70. this.setData(options)
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () {
  76. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  77. for (const i in obj) {
  78. this[i] = obj[i]
  79. }
  80. },
  81. /**
  82. * 生命周期函数--监听页面显示
  83. */
  84. onShow: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh: function () {
  100. const { isTeaching } = this.data
  101. if (isTeaching) {
  102. this.setData({ pageNo: 1 })
  103. this.getTeachingList(res => {
  104. wx.stopPullDownRefresh()
  105. })
  106. }
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function () {
  112. const { isAll, isTeaching } = this.data
  113. if (isAll) {
  114. return
  115. }
  116. if (isTeaching) {
  117. this.getTeachingList()
  118. }
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage: function () {
  124. },
  125. /**
  126. * 跳转
  127. */
  128. navigateCtl: app.navigateCtl,
  129. /**
  130. * 底部导航跳转
  131. */
  132. redirectCtl: app.redirectCtl,
  133. /**
  134. * 查询书名
  135. */
  136. inputCtl: function (e) {
  137. const { value } = e.detail
  138. this.setData({
  139. bookName: value
  140. })
  141. this.getTeachingList()
  142. },
  143. /**
  144. * 选择教辅
  145. */
  146. selectTeach:function(e){
  147. const { grade, subject } = e.currentTarget.dataset.method
  148. this.setData({ isTeaching: true, grade, subject })
  149. this.getTeachingList()
  150. },
  151. /**
  152. * 获取教辅
  153. */
  154. getTeachingList: function () {
  155. const continuousFn = { fn: this.getTeachingList, param: { ...arguments } }
  156. let { pageNo, pageSize, grade, subject, list = [], bookName } = this.data
  157. BookList({ data: { grade, bookName, subject, pageNo, pageSize }, continuousFn }).then(res => {
  158. if (pageNo == 1) {
  159. list = res.data.list
  160. } else {
  161. list = list.concat(res.data.list)
  162. }
  163. this.setData({
  164. teachList:list,
  165. pageNo: list.length == pageSize * pageNo ? pageNo + 1 : pageNo,
  166. isAll: list.length < pageSize
  167. })
  168. if (isFn(cb)) cb()
  169. }).catch(res => {
  170. if (isFn(cb)) cb()
  171. })
  172. },
  173. /**
  174. * 获取教辅
  175. */
  176. getTeaching: function (e) {
  177. const { bookId, subject, bookName} = e.currentTarget.dataset.method
  178. let { list = [], teachList} = this.data
  179. var items = { bookId, subject, bookName };
  180. var temp = {};
  181. for (var i in list) {
  182. if (list[i].subject === subject) {
  183. list[i].bookList.push(items)
  184. }
  185. }
  186. wx.setStorageSync('list', list)
  187. this.setData({ list, isTeaching: false})
  188. },
  189. /**
  190. * 本地获取教辅
  191. */
  192. localTeaching:function(){
  193. const { isAdd}=this.data;
  194. var that=this;
  195. console.log(isAdd)
  196. if (isAdd=="true"){
  197. var list =wx.getStorageSync('list');
  198. wx.setStorageSync('list', list)
  199. that.setData({ list })
  200. }else{
  201. const { list } = that.data;
  202. wx.setStorageSync('list', list)
  203. that.setData({ list })
  204. }
  205. },
  206. /**
  207. * 删除
  208. */
  209. deleteBook:function(e){
  210. const { index, key } = e.currentTarget.dataset;
  211. const {list}=this.data;
  212. list[index].bookList.splice(key, 1)
  213. wx.setStorageSync('list', list)
  214. this.setData({list})
  215. }
  216. })