index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. const columnId = util.column('6').columnId;
  89. this.distinction(2, columnId, 1, 2, res => {
  90. if(res.data.success) {
  91. console.log(res.data.data)
  92. this.setData({
  93. productionData: res.data.data
  94. })
  95. if(res.data.data) {
  96. if(res.data.data.totalSize > 2) {
  97. this.setData({
  98. productionMore: true
  99. })
  100. }
  101. }
  102. }
  103. });
  104. },
  105. onLoad: function (options) {
  106. //获取更改年级组件
  107. this.setGrade = this.selectComponent("#set-grade");
  108. console.log(this.setGrade)
  109. //获取分享过来的值跳转页面
  110. const ind = options.ind;
  111. const postsId = options.postId || '';
  112. //判断ind的值移动到到艺术
  113. if(ind) {
  114. this.setData({
  115. navBtnSelectIdx: ind
  116. })
  117. //移动nav
  118. if (ind <= 2) {
  119. this.setData({ left: 0 });
  120. }
  121. if(ind > 2){
  122. this.setData({left: 200 });
  123. }
  124. }
  125. /* 分享 */
  126. const columnId = util.column('6').columnId;
  127. this.distinction(2, columnId, 1, 2, res => {
  128. if(res.data.success) {
  129. console.log(res.data.data)
  130. this.setData({
  131. productionData: res.data.data
  132. })
  133. if(res.data.data) {
  134. if(res.data.data.totalSize > 2) {
  135. this.setData({
  136. productionMore: true
  137. })
  138. }
  139. }
  140. }
  141. });
  142. },
  143. onShow: function () {
  144. //登录页信息
  145. login.getOpenidSessionKey(res => {
  146. APIClient.getMySchedule({
  147. uid: res.data.data.uid
  148. }).success(res => {
  149. console.log(res)
  150. this.setData({
  151. data: res.data.data,
  152. grade: util.gradeUpper(res.data.data.users.grade),
  153. test:util.day(),
  154. time: util.day(res.data.data.timeSpend),
  155. studyLog: util.studyTime(res.data.data.studyLog)
  156. })
  157. if(res.data.data.studyLog.length > 10) {
  158. this.setData({
  159. height: '680'
  160. })
  161. }
  162. })
  163. //获取排名
  164. APIClient.getFriendSchedule('wx/friendsRank/user', {
  165. uid: res.data.data.uid
  166. }).success(res => {
  167. console.log(res)
  168. this.setData({
  169. rankData: res.data.data,
  170. })
  171. })
  172. }, () => {
  173. this.setData({
  174. flag: !this.data.flag
  175. })
  176. });
  177. },
  178. /* 区分答疑和分享 */
  179. distinction: function(type, columnId, pageNo, pageSize, success) {
  180. login.getOpenidSessionKey(function(res) {
  181. //console.log(res.data.data.uid);
  182. APIClient.getProductionSchedule({
  183. uid: res.data.data.uid
  184. }, {
  185. "type": type,
  186. "category": columnId,
  187. "pageNo": pageNo,
  188. "pageSize": pageSize
  189. }).success(success)
  190. }, function() {
  191. });
  192. },
  193. /*点击加载更多*/
  194. onMyEvent: function(e){
  195. const columnId = util.column('6').columnId;
  196. this.data.num2++
  197. this.setData({
  198. num: this.data.num2
  199. })
  200. this.distinction(2, columnId, 1, 5*this.data.num2, res => {
  201. if(res.data.success) {
  202. console.log(res.data.data)
  203. this.setData({
  204. productionData: res.data.data,
  205. })
  206. if(5*this.data.num2 > res.data.data.totalSize) {
  207. this.setData({
  208. productionMore: ''
  209. })
  210. }
  211. }
  212. });
  213. },
  214. })