homework_list.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // pages/home/home.js
  2. const app = getApp();
  3. const { formatDate, formatTime2, getDateDiff, formatDateZyb} = require('../../utils/util.js')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. baseImgUrl: app.globalData.baseImgUrl,
  10. thumbnail: app.globalData.thumbnail,
  11. maxCreateTime: formatTime2(new Date()),
  12. isOne:false,
  13. hiddenModel:false,
  14. parentalConcern: [
  15. "知识点掌握情况",
  16. "学习习惯养成"
  17. ],
  18. subjectTaskList: [],
  19. pageNo:1,
  20. pageSize:10,
  21. list:[],
  22. isTimes:false,
  23. isOutTime:false,
  24. isAll: false,
  25. footerData: {
  26. actIndex: 0,
  27. list: [
  28. {
  29. text: '首页',
  30. url: '../../image/shou_ye_hui.png',
  31. actUrl: '../../image/shou_ye.png',
  32. src: 'homework_list',
  33. id: 'homework_list'
  34. },
  35. {
  36. text: '学习成长报告',
  37. url: '../../image/xue_qing_hui.png',
  38. actUrl: '../../image/xue_qing.png',
  39. src: 'learning_report',
  40. id: 'learning_report'
  41. },
  42. {
  43. text: '我的',
  44. url: '../../image/wo_de_hui.png',
  45. actUrl: '../../image/wo_de.png',
  46. src: 'me',
  47. id: 'me'
  48. }
  49. ],
  50. },
  51. headerData: {
  52. actIndex: 0,
  53. list: [
  54. {
  55. text: '作业',
  56. src: 'homework_list',
  57. id: 'homework_list'
  58. },
  59. {
  60. text: '难题',
  61. src: 'problem_list',
  62. id: 'problem_list'
  63. },
  64. // {
  65. // text: '辅导课',
  66. // src: 'one_to_one',
  67. // id: 'one_to_one'
  68. // },
  69. ],
  70. }
  71. },
  72. /**
  73. * 生命周期函数--监听页面加载
  74. */
  75. onLoad: function (options) {
  76. app.getWxloginCode(code => {
  77. this.setData({ code })
  78. })
  79. options.vipId = app.getGlobalAttributeValue(`parentVipId-${app.getGlobalAttributeValue(`userId`)}`)
  80. this.setData({ options})
  81. console.log(options)
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面显示
  90. */
  91. onShow: function () {
  92. app.getVipList()
  93. const userInfo = wx.getStorageSync('userInfo')
  94. const { vipId } = this.data.options
  95. if (!userInfo) {
  96. this.setData({ isOne: true })
  97. } else if (vipId){
  98. this.getMyInfo();
  99. this.getHomeworkList();
  100. }
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. this.setData({pageNo:1})
  117. this.getHomeworkList(res => {
  118. wx.stopPullDownRefresh()
  119. })
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function () {
  125. const { isAll} = this.data
  126. if (isAll) {
  127. return
  128. }
  129. this.getHomeworkList()
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. },
  136. /**
  137. * 底部导航跳转
  138. */
  139. redirectCtl: app.redirectCtl,
  140. /**
  141. * 路由跳转
  142. */
  143. navigateCtl: app.navigateCtl,
  144. /**
  145. * 我的信息
  146. */
  147. getMyInfo: function () {
  148. const { isTimes}=this.data;
  149. const userId = app.globalData.userId || wx.getStorageSync('userId');
  150. const postData = { fn: this.getChildInfo, param: { ...arguments } }
  151. app.post('/api/parents/parents/V2/getMyInfo', {}, 0, postData).then(res => {
  152. const { childList, phone } = res.data;
  153. if (!phone) {
  154. this.redirectCtl({ url: 'phone', method: {} }, true)
  155. }
  156. if (userId) {
  157. const parentInfo = app.globalData.parentInfo || wx.getStorageSync(`parentInfo-${userId}`)
  158. const parentVipList = childList
  159. const parentVipLiIdx = app.globalData.parentVipLiIdx || wx.getStorageSync(`parentVipLiIdx-${userId}`) || 0;
  160. if (parentVipList.length>0) {
  161. var times = parentVipList[parentVipLiIdx].zybEndDate;
  162. var messageTime = formatDateZyb(times, 'Y-M-D');
  163. var nowTime = new Date().getTime();
  164. var today = formatDateZyb(nowTime/1000, 'Y-M-D');
  165. var day1 = new Date(today);
  166. var day2 = new Date(messageTime);
  167. var differDay = (day2 - day1) / (1000 * 60 * 60 * 24);
  168. // console.log(differDay)
  169. if (0 <=differDay && differDay<=6){
  170. this.setData({ isTimes: true, messageTime, times})
  171. } else if (differDay<0){
  172. this.setData({ isOutTime: true, times})
  173. } else if (differDay > 6) {
  174. this.setData({ isOutTime: false, isTimes:false })
  175. }
  176. }
  177. this.setData({ userId, parentInfo, parentVipLiIdx, parentVipList})
  178. }
  179. })
  180. },
  181. // 获取作业列表
  182. getHomeworkList:function(){
  183. const postData = { fn: this.getHomeworkList, param: { ...arguments } }
  184. const { vipId } = this.data.options
  185. const { pageNo, pageSize, maxCreateTime, list = []} = this.data;
  186. wx.showLoading({
  187. title: '加载中',
  188. })
  189. app.post('/api/parents/parents/V2/homeworkTask', { vipId, pageNo, pageSize, maxCreateTime}, 0, postData).then(res => {
  190. wx.hideLoading();
  191. const listTemp = res.data.list;
  192. const {todayTask}=res.data;
  193. let arr = []
  194. if (pageNo == 1) {
  195. arr = [...listTemp]
  196. } else {
  197. arr = [...list, ...listTemp]
  198. }
  199. this.setData({
  200. todayTask,
  201. list: arr,
  202. pageNo: listTemp.length == pageSize ? pageNo + 1 : pageNo,
  203. isAll: listTemp.length < pageSize
  204. })
  205. })
  206. },
  207. /**
  208. * 微信授权
  209. */
  210. bindGetUserInfo: function (e) {
  211. const { isSelect, code } = this.data;
  212. if (e.detail.userInfo) {
  213. app.saveUserInfo(e.detail, code)
  214. } else {
  215. wx.showToast({
  216. title: '微信授权失败',
  217. icon: 'none'
  218. })
  219. }
  220. }
  221. })