index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. canvasHeight: ''
  26. },
  27. lower: function (e) {
  28. //console.log(e);
  29. //console.log(e.detail.scrollTop)
  30. // if (320 <= e.detail.scrollTop && e.detail.scrollTop <= 1000){
  31. // this.setData({ questionsPreviewing: true, questionsShare: false});
  32. // }else {
  33. // this.setData({ questionsPreviewing: false });
  34. // }
  35. // if (1090 <= e.detail.scrollTop) {
  36. // this.setData({ questionsPreviewing: false, questionsShare: true});
  37. // } else {
  38. // this.setData({ questionsShare: false });
  39. // }
  40. },
  41. jurisdiction: function () {
  42. //隐藏弹框
  43. this.setData({
  44. flag: !this.data.flag
  45. })
  46. //登录页信息
  47. this.onShow();
  48. },
  49. /*点击获取canvas高度*/
  50. onGetHeight: function (e) {
  51. const canvasHeight = this.selectComponent("#chat").data.canvasHeight;
  52. this.setData({
  53. canvasHeight,
  54. })
  55. },
  56. /*更改年级*/
  57. setgrade: function (e) {
  58. this.setGrade.showPopup()
  59. },
  60. onLoad: function (options) {
  61. //获取更改年级组件
  62. this.setGrade = this.selectComponent("#set-grade");
  63. console.log(this.setGrade)
  64. //获取分享过来的值跳转页面
  65. const ind = options.ind;
  66. const postsId = options.postId || '';
  67. //判断ind的值移动到到艺术
  68. if(ind) {
  69. this.setData({
  70. navBtnSelectIdx: ind
  71. })
  72. //移动nav
  73. if (ind <= 2) {
  74. this.setData({ left: 0 });
  75. }
  76. if(ind > 2){
  77. this.setData({left: 200 });
  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: '680'
  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. }, () => {
  111. this.setData({
  112. flag: !this.data.flag
  113. })
  114. });
  115. /* 分享 */
  116. const columnId = util.column('6').columnId;
  117. this.distinction(2, columnId, 1, 2, res => {
  118. if(res.data.success) {
  119. console.log(res.data.data)
  120. this.setData({
  121. productionData: res.data.data
  122. })
  123. if(res.data.data) {
  124. if(res.data.data.totalSize > 2) {
  125. this.setData({
  126. productionMore: true
  127. })
  128. }
  129. }
  130. }
  131. });
  132. },
  133. /* 区分答疑和分享 */
  134. distinction: function(type, columnId, pageNo, pageSize, success) {
  135. login.getOpenidSessionKey(function(res) {
  136. //console.log(res.data.data.uid);
  137. APIClient.getProductionSchedule({
  138. uid: res.data.data.uid
  139. }, {
  140. "type": type,
  141. "pageNo": pageNo,
  142. "pageSize": pageSize
  143. }).success(success)
  144. }, function() {
  145. });
  146. },
  147. /*点击加载更多*/
  148. onMyEvent: function(e){
  149. const columnId = util.column('6').columnId;
  150. this.data.num2++
  151. this.setData({
  152. num: this.data.num2
  153. })
  154. this.distinction(2, columnId, 1, 5*this.data.num2, res => {
  155. if(res.data.success) {
  156. console.log(res.data.data)
  157. this.setData({
  158. productionData: res.data.data,
  159. })
  160. if(5*this.data.num2 > res.data.data.totalSize) {
  161. this.setData({
  162. productionMore: ''
  163. })
  164. }
  165. }
  166. });
  167. },
  168. /* 转发*/
  169. onShareAppMessage: function (ops) {
  170. if (ops.from === 'button') {
  171. // 来自页面内转发按钮
  172. console.log(ops.target)
  173. }
  174. const postId = ops.target.dataset.postid;
  175. const imageUrl= ops.target.dataset.imageurl[0];
  176. return {
  177. title: '小学王者班',
  178. path: `pages/transmit/transmit?ind=7&postId=${postId}`,
  179. imageUrl,
  180. success: function (res) {
  181. // 转发成功
  182. console.log("转发成功:" + JSON.stringify(res));
  183. },
  184. fail: function (res) {
  185. // 转发失败
  186. console.log("转发失败:" + JSON.stringify(res));
  187. }
  188. }
  189. }
  190. })