index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. login.getOpenidSessionKey(res => {
  44. //隐藏弹框
  45. this.setData({
  46. flag: !this.data.flag
  47. })
  48. APIClient.getMySchedule({
  49. uid: res.data.data.uid
  50. }).success(res => {
  51. console.log(res)
  52. this.setData({
  53. data: res.data.data,
  54. grade: util.gradeUpper(res.data.data.users.grade),
  55. test:util.day(),
  56. time: util.day(res.data.data.timeSpend),
  57. studyLog: util.studyTime(res.data.data.studyLog)
  58. })
  59. if(res.data.data.studyLog.length > 10) {
  60. this.setData({
  61. height: '670'
  62. })
  63. }
  64. })
  65. //获取排名
  66. APIClient.getFriendSchedule('wx/friendsRank/user', {
  67. uid: res.data.data.uid
  68. }).success(res => {
  69. console.log(res)
  70. this.setData({
  71. rankData: res.data.data,
  72. })
  73. })
  74. }, function() {
  75. wx.showModal({
  76. title: '提示',
  77. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  78. showCancel: false,
  79. success: function (res) {
  80. if (res.confirm) {
  81. console.log('用户点击确定')
  82. } else if (res.cancel) {
  83. console.log('用户点击取消')
  84. }
  85. }
  86. })
  87. });
  88. /* 分享 */
  89. const columnId = util.column('6').columnId;
  90. this.distinction(2, columnId, 1, 2, res => {
  91. if(res.data.success) {
  92. console.log(res.data.data)
  93. this.setData({
  94. productionData: res.data.data
  95. })
  96. if(res.data.data) {
  97. if(res.data.data.totalSize > 2) {
  98. this.setData({
  99. productionMore: true
  100. })
  101. }
  102. }
  103. }
  104. });
  105. },
  106. /*点击获取canvas高度*/
  107. onGetHeight: function (e) {
  108. const canvasHeight = this.selectComponent("#chat").data.canvasHeight;
  109. this.setData({
  110. canvasHeight,
  111. })
  112. },
  113. /*更改年级*/
  114. setgrade: function (e) {
  115. this.setGrade.showPopup()
  116. },
  117. onLoad: function (options) {
  118. //获取更改年级组件
  119. this.setGrade = this.selectComponent("#set-grade");
  120. console.log(this.setGrade)
  121. //获取分享过来的值跳转页面
  122. const ind = options.ind;
  123. const postsId = options.postId || '';
  124. //判断ind的值移动到到艺术
  125. if(ind) {
  126. this.setData({
  127. navBtnSelectIdx: ind
  128. })
  129. //移动nav
  130. if (ind <= 2) {
  131. this.setData({ left: 0 });
  132. }
  133. if(ind > 2){
  134. this.setData({left: 200 });
  135. }
  136. }
  137. /* 分享 */
  138. const columnId = util.column('6').columnId;
  139. this.distinction(2, columnId, 1, 2, res => {
  140. if(res.data.success) {
  141. console.log(res.data.data)
  142. this.setData({
  143. productionData: res.data.data
  144. })
  145. if(res.data.data) {
  146. if(res.data.data.totalSize > 2) {
  147. this.setData({
  148. productionMore: true
  149. })
  150. }
  151. }
  152. }
  153. });
  154. },
  155. onShow: function () {
  156. //登录页信息
  157. login.getOpenidSessionKey(res => {
  158. APIClient.getMySchedule({
  159. uid: res.data.data.uid
  160. }).success(res => {
  161. console.log(res)
  162. this.setData({
  163. data: res.data.data,
  164. grade: util.gradeUpper(res.data.data.users.grade),
  165. test:util.day(),
  166. time: util.day(res.data.data.timeSpend),
  167. studyLog: util.studyTime(res.data.data.studyLog)
  168. })
  169. if(res.data.data.studyLog.length > 10) {
  170. this.setData({
  171. height: '680'
  172. })
  173. }
  174. })
  175. //获取排名
  176. APIClient.getFriendSchedule('wx/friendsRank/user', {
  177. uid: res.data.data.uid
  178. }).success(res => {
  179. console.log(res)
  180. this.setData({
  181. rankData: res.data.data,
  182. })
  183. })
  184. }, () => {
  185. this.setData({
  186. flag: !this.data.flag
  187. })
  188. });
  189. },
  190. /* 区分答疑和分享 */
  191. distinction: function(type, columnId, pageNo, pageSize, success) {
  192. login.getOpenidSessionKey(function(res) {
  193. //console.log(res.data.data.uid);
  194. APIClient.getProductionSchedule({
  195. uid: res.data.data.uid
  196. }, {
  197. "type": type,
  198. "category": columnId,
  199. "pageNo": pageNo,
  200. "pageSize": pageSize
  201. }).success(success)
  202. }, function() {
  203. });
  204. },
  205. /*点击加载更多*/
  206. onMyEvent: function(e){
  207. const columnId = util.column('6').columnId;
  208. this.data.num2++
  209. this.setData({
  210. num: this.data.num2
  211. })
  212. this.distinction(2, columnId, 1, 5*this.data.num2, res => {
  213. if(res.data.success) {
  214. console.log(res.data.data)
  215. this.setData({
  216. productionData: res.data.data,
  217. })
  218. if(5*this.data.num2 > res.data.data.totalSize) {
  219. this.setData({
  220. productionMore: ''
  221. })
  222. }
  223. }
  224. });
  225. },
  226. /* 转发*/
  227. onShareAppMessage: function (ops) {
  228. if (ops.from === 'button') {
  229. // 来自页面内转发按钮
  230. console.log(ops.target)
  231. }
  232. debugger;
  233. const postId = ops.target.dataset.postid;
  234. return {
  235. title: '小学王者班',
  236. path: `pages/transmit/transmit?ind=7&postId=${postId}`,
  237. success: function (res) {
  238. // 转发成功
  239. console.log("转发成功:" + JSON.stringify(res));
  240. },
  241. fail: function (res) {
  242. // 转发失败
  243. console.log("转发失败:" + JSON.stringify(res));
  244. }
  245. }
  246. }
  247. })