index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. flag: true,
  22. productionData: {},
  23. num2: 0,
  24. productionMore: ''
  25. },
  26. lower: function (e) {
  27. //console.log(e);
  28. //console.log(e.detail.scrollTop)
  29. // if (320 <= e.detail.scrollTop && e.detail.scrollTop <= 1000){
  30. // this.setData({ questionsPreviewing: true, questionsShare: false});
  31. // }else {
  32. // this.setData({ questionsPreviewing: false });
  33. // }
  34. // if (1090 <= e.detail.scrollTop) {
  35. // this.setData({ questionsPreviewing: false, questionsShare: true});
  36. // } else {
  37. // this.setData({ questionsShare: false });
  38. // }
  39. },
  40. jurisdiction: function () {
  41. //登录页信息
  42. login.getOpenidSessionKey(res => {
  43. //隐藏弹框
  44. this.setData({
  45. flag: !this.data.flag
  46. })
  47. APIClient.getMySchedule({
  48. uid: res.data.data.uid
  49. }).success(res => {
  50. console.log(res)
  51. this.setData({
  52. data: res.data.data,
  53. grade: util.gradeUpper(res.data.data.users.grade),
  54. test:util.day(),
  55. time: util.day(res.data.data.timeSpend),
  56. studyLog: util.studyTime(res.data.data.studyLog)
  57. })
  58. if(res.data.data.studyLog.length > 10) {
  59. this.setData({
  60. height: '700'
  61. })
  62. }
  63. })
  64. //获取排名
  65. APIClient.getFriendSchedule('wx/friendsRank/user', {
  66. uid: res.data.data.uid
  67. }).success(res => {
  68. console.log(res)
  69. this.setData({
  70. rankData: res.data.data,
  71. })
  72. })
  73. }, function() {
  74. wx.showModal({
  75. title: '提示',
  76. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  77. showCancel: false,
  78. success: function (res) {
  79. if (res.confirm) {
  80. console.log('用户点击确定')
  81. } else if (res.cancel) {
  82. console.log('用户点击取消')
  83. }
  84. }
  85. })
  86. });
  87. },
  88. onLoad: function (options) {
  89. //获取更改年级组件
  90. this.setGrade = this.selectComponent("#set-grade");
  91. console.log(this.setGrade)
  92. //获取分享过来的值跳转页面
  93. const ind = options.ind;
  94. const postsId = options.postId || '';
  95. //判断ind的值移动到到艺术
  96. if(ind) {
  97. this.setData({
  98. navBtnSelectIdx: ind
  99. })
  100. //移动nav
  101. if (ind <= 2) {
  102. this.setData({ left: 0 });
  103. }
  104. if(ind > 2){
  105. this.setData({left: 200 });
  106. }
  107. }
  108. /* 分享 */
  109. const columnId = util.column('6').columnId;
  110. this.distinction(2, columnId, 1, 2, res => {
  111. if(res.data.success) {
  112. console.log(res.data.data)
  113. this.setData({
  114. productionData: res.data.data
  115. })
  116. if(res.data.data) {
  117. if(res.data.data.totalSize > 2) {
  118. this.setData({
  119. productionMore: true
  120. })
  121. }
  122. }
  123. }
  124. });
  125. },
  126. onShow: function () {
  127. //登录页信息
  128. login.getOpenidSessionKey(res => {
  129. APIClient.getMySchedule({
  130. uid: res.data.data.uid
  131. }).success(res => {
  132. console.log(res)
  133. this.setData({
  134. data: res.data.data,
  135. grade: util.gradeUpper(res.data.data.users.grade),
  136. test:util.day(),
  137. time: util.day(res.data.data.timeSpend),
  138. studyLog: util.studyTime(res.data.data.studyLog)
  139. })
  140. if(res.data.data.studyLog.length > 10) {
  141. this.setData({
  142. height: '680'
  143. })
  144. }
  145. })
  146. //获取排名
  147. APIClient.getFriendSchedule('wx/friendsRank/user', {
  148. uid: res.data.data.uid
  149. }).success(res => {
  150. console.log(res)
  151. this.setData({
  152. rankData: res.data.data,
  153. })
  154. })
  155. }, () => {
  156. this.setData({
  157. flag: !this.data.flag
  158. })
  159. });
  160. },
  161. /* 区分答疑和分享 */
  162. distinction: function(type, columnId, pageNo, pageSize, success) {
  163. login.getOpenidSessionKey(function(res) {
  164. //console.log(res.data.data.uid);
  165. APIClient.getProductionSchedule({
  166. uid: res.data.data.uid
  167. }, {
  168. "type": type,
  169. "category": columnId,
  170. "pageNo": pageNo,
  171. "pageSize": pageSize
  172. }).success(success)
  173. }, function() {
  174. // wx.showModal({
  175. // title: '提示',
  176. // content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  177. // showCancel: false,
  178. // success: function (res) {
  179. // if (res.confirm) {
  180. // console.log('用户点击确定')
  181. // } else if (res.cancel) {
  182. // console.log('用户点击取消')
  183. // }
  184. // }
  185. // })
  186. });
  187. },
  188. /*点击加载更多*/
  189. onMyEvent: function(e){
  190. const columnId = util.column('6').columnId;
  191. this.data.num2++
  192. this.setData({
  193. num: this.data.num2
  194. })
  195. this.distinction(2, columnId, 1, 5*this.data.num2, res => {
  196. if(res.data.success) {
  197. console.log(res.data.data)
  198. this.setData({
  199. productionData: res.data.data,
  200. })
  201. if(5*this.data.num2 > res.data.data.totalSize) {
  202. this.setData({
  203. productionMore: ''
  204. })
  205. }
  206. }
  207. });
  208. },
  209. })