teaching.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // pages/teaching/teaching.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list:[
  9. {
  10. subject:'语文',
  11. imgUrl:'../../image/yuwen.png',
  12. bookList:[]
  13. },
  14. {
  15. subject: '数学',
  16. imgUrl: '../../image/shuxue.png',
  17. bookList: []
  18. },
  19. {
  20. subject: '英语',
  21. imgUrl: '../../image/yingyu.png',
  22. bookList: []
  23. }
  24. ],
  25. bookId:'',
  26. subject:''
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. this.setData(options)
  33. },
  34. /**
  35. * 生命周期函数--监听页面初次渲染完成
  36. */
  37. onReady: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面显示
  41. */
  42. onShow: function () {
  43. this.getInformation()
  44. const { subject, isAddChild, isSelect}=this.data;
  45. if (!subject && isAddChild!=1){
  46. this.getTeaching();
  47. }
  48. if (isAddChild == 1){
  49. this.localTeaching();
  50. }
  51. var list = wx.getStorageSync('list');
  52. if (subject) {
  53. this.packaging(list)
  54. }
  55. this.setData({ list })
  56. console.log(list)
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload: function () {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {
  72. },
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom: function () {
  77. },
  78. /**
  79. * 用户点击右上角分享
  80. */
  81. onShareAppMessage: function () {
  82. },
  83. /**
  84. * 跳转
  85. */
  86. navigateCtl: app.navigateCtl,
  87. /**
  88. * 底部导航跳转
  89. */
  90. redirectCtl: app.redirectCtl,
  91. /**
  92. * 获取教辅
  93. */
  94. getTeaching: function () {
  95. const postData = { fn: this.getTeaching, param: { ...arguments } }
  96. let { list = [], vipId} = this.data
  97. app.post('/api/parents/parents/V2/childBookList', {vipId}, 0, postData).then(res => {
  98. const {list}=res.data;
  99. const correctListTemp = (res => {
  100. const list = res
  101. const listTemp = []
  102. for (let i in res) {
  103. if (list[i].subject == '语文') {
  104. list[i].imgUrl= '../../image/yuwen.png';
  105. } else if (list[i].subject == '数学'){
  106. list[i].imgUrl = '../../image/shuxue.png';
  107. } else if (list[i].subject == '英语') {
  108. list[i].imgUrl = '../../image/yingyu.png';
  109. }
  110. }
  111. return res
  112. })(list)
  113. wx.setStorageSync('list', list)
  114. this.setData({list})
  115. })
  116. },
  117. /**
  118. * 本地获取教辅
  119. */
  120. localTeaching:function(){
  121. const { isAdd}=this.data;
  122. var that=this;
  123. console.log(isAdd)
  124. if (isAdd=="true"){
  125. var list =wx.getStorageSync('list');
  126. wx.setStorageSync('list', list)
  127. that.setData({ list })
  128. console.log('1==='+list)
  129. }else{
  130. const { list } = that.data;
  131. wx.setStorageSync('list', list)
  132. that.setData({ list })
  133. console.log('2---'+list)
  134. }
  135. },
  136. /**
  137. * 封装
  138. */
  139. packaging:function(res){
  140. const {bookId, subject, bookName}=this.data;
  141. var items= { bookId, subject, bookName};
  142. var temp={};
  143. for(var i in res){
  144. if (res[i].subject===subject){
  145. console.log(res[i])
  146. // temp[`list[${i}].bookList`] = items;
  147. res[i].bookList.push(items)
  148. }
  149. }
  150. wx.setStorageSync('list', res)
  151. this.setData({list:res})
  152. },
  153. /**
  154. * 删除
  155. */
  156. deleteBook:function(e){
  157. const { index, key } = e.currentTarget.dataset;
  158. const {list}=this.data;
  159. list[index].bookList.splice(key, 1)
  160. wx.setStorageSync('list', list)
  161. this.setData({list})
  162. console.log(list)
  163. },
  164. /**
  165. * 获取个人信息
  166. */
  167. getInformation: function (e) {
  168. const postData = { fn: this.getInformation, param: { ...arguments } }
  169. const { vipId} = this.data
  170. app.post('/api/parents/parents/V2/getMyChildInfo', { vipId }, 0, postData).then(res => {
  171. const { grade}=res.data
  172. this.setData({grade})
  173. })
  174. },
  175. /**
  176. * 保存
  177. */
  178. save:function(){
  179. const postData = { fn: this.saveInfo, param: { ...arguments } }
  180. const { list, vipId,obj}=this.data
  181. var arr=[];
  182. for(var i in list){
  183. arr = arr.concat(list[i].bookList)
  184. }
  185. var bookList=[];
  186. for(var i in arr){
  187. bookList.push({ bookId: arr[i].bookId, subject: arr[i].subject, bookName: arr[i].bookName,})
  188. }
  189. if(obj){
  190. var newObj = JSON.parse(obj);
  191. }else{
  192. var newObj = { vipId}
  193. }
  194. newObj['bookList'] = bookList
  195. console.log(newObj)
  196. app.post('/api/parents/parents/V2/upMyChildInfo', newObj, 0, postData).then(res => {
  197. wx.showToast({
  198. title: '保存成功',
  199. icon: 'none',
  200. duration: 1000
  201. })
  202. wx.removeStorageSync('list')
  203. })
  204. }
  205. })