index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. const util = require('../../utils/util.js');
  5. const APIClient = require('../../utils/APIClient.js');
  6. const login = require('../../utils/loginSchedule.js');
  7. Page({
  8. data: {
  9. motto: ['我的','本周推荐','语文','数学','中文','英语','科学','艺术'],
  10. navBtnSelectIdx: 0,
  11. left: 0,
  12. //questionsPreviewing: false,
  13. //questionsShare: false,
  14. data: {},
  15. grade: "",
  16. time: "",
  17. rankData: {},
  18. share: false,
  19. studyLog: [],
  20. height: '',
  21. productionData: {},
  22. num2: 0,
  23. productionMore: ''
  24. },
  25. lower: function (e) {
  26. //console.log(e);
  27. //console.log(e.detail.scrollTop)
  28. // if (320 <= e.detail.scrollTop && e.detail.scrollTop <= 1000){
  29. // this.setData({ questionsPreviewing: true, questionsShare: false});
  30. // }else {
  31. // this.setData({ questionsPreviewing: false });
  32. // }
  33. // if (1090 <= e.detail.scrollTop) {
  34. // this.setData({ questionsPreviewing: false, questionsShare: true});
  35. // } else {
  36. // this.setData({ questionsShare: false });
  37. // }
  38. },
  39. setgrade: function (e) {
  40. //console.log(this.setGrade)
  41. this.setGrade.showPopup()
  42. },
  43. onLoad: function (options) {
  44. //获取更改年级组件
  45. this.setGrade = this.selectComponent("#set-grade");
  46. console.log(this.setGrade)
  47. //获取分享过来的值跳转页面
  48. const ind = options.ind;
  49. const postsId = options.postId || '';
  50. //判断ind的值移动到到艺术
  51. if(ind) {
  52. this.setData({
  53. navBtnSelectIdx: ind
  54. })
  55. //移动nav
  56. if (ind <= 2) {
  57. this.setData({ left: 0 });
  58. }
  59. if(ind > 2){
  60. this.setData({left: 200 });
  61. }
  62. }
  63. /* 分享 */
  64. const columnId = util.column('6').columnId;
  65. this.distinction(2, columnId, 1, 2, res => {
  66. if(res.data.success) {
  67. console.log(res.data.data)
  68. this.setData({
  69. productionData: res.data.data
  70. })
  71. if(res.data.data) {
  72. if(res.data.data.totalSize > 2) {
  73. this.setData({
  74. productionMore: true
  75. })
  76. }
  77. }
  78. }
  79. });
  80. },
  81. onShow: function () {
  82. //登录页信息
  83. login.getOpenidSessionKey(res => {
  84. APIClient.getMySchedule({
  85. uid: res.data.data.uid
  86. }).success(res => {
  87. console.log(res)
  88. this.setData({
  89. data: res.data.data,
  90. grade: util.gradeUpper(res.data.data.users.grade),
  91. test:util.day(),
  92. time: util.day(res.data.data.timeSpend),
  93. studyLog: util.studyTime(res.data.data.studyLog)
  94. })
  95. if(res.data.data.studyLog.length > 10) {
  96. this.setData({
  97. height: '700'
  98. })
  99. }
  100. })
  101. //获取排名
  102. APIClient.getFriendSchedule('wx/friendsRank/user', {
  103. uid: res.data.data.uid
  104. }).success(res => {
  105. console.log(res)
  106. this.setData({
  107. rankData: res.data.data,
  108. })
  109. })
  110. }, function() {
  111. wx.showModal({
  112. title: '提示',
  113. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  114. showCancel: false,
  115. success: function (res) {
  116. if (res.confirm) {
  117. console.log('用户点击确定')
  118. } else if (res.cancel) {
  119. console.log('用户点击取消')
  120. }
  121. }
  122. })
  123. });
  124. },
  125. /* 区分答疑和分享 */
  126. distinction: function(type, columnId, pageNo, pageSize, success) {
  127. login.getOpenidSessionKey(function(res) {
  128. //console.log(res.data.data.uid);
  129. APIClient.getProductionSchedule({
  130. uid: res.data.data.uid
  131. }, {
  132. "type": type,
  133. "category": columnId,
  134. "pageNo": pageNo,
  135. "pageSize": pageSize
  136. }).success(success)
  137. }, function() {
  138. wx.showModal({
  139. title: '提示',
  140. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  141. showCancel: false,
  142. success: function (res) {
  143. if (res.confirm) {
  144. console.log('用户点击确定')
  145. } else if (res.cancel) {
  146. console.log('用户点击取消')
  147. }
  148. }
  149. })
  150. });
  151. },
  152. /*点击加载更多*/
  153. onMyEvent: function(e){
  154. const columnId = util.column('6').columnId;
  155. this.data.num2++
  156. this.setData({
  157. num: this.data.num2
  158. })
  159. this.distinction(2, columnId, 1, 5*this.data.num2, res => {
  160. if(res.data.success) {
  161. console.log(res.data.data)
  162. this.setData({
  163. productionData: res.data.data,
  164. })
  165. if(5*this.data.num2 > res.data.data.totalSize) {
  166. this.setData({
  167. productionMore: ''
  168. })
  169. }
  170. }
  171. });
  172. },
  173. })