demandCourses.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. lbArr: [],
  6. showNull: false,
  7. sfmArr: [],
  8. currentId: null,
  9. currentName: ""
  10. },
  11. // 点击按跳转
  12. goIn(e) {
  13. let id = e.currentTarget.dataset.item.id
  14. if (this.data.currentId != null) {
  15. // 没学或者没学完
  16. if (e.currentTarget.dataset.item.isDone == 0) {
  17. if (id == this.data.currentId) {
  18. wx.navigateTo({
  19. url: '../dbDetails/dbDetails?id=' + id
  20. })
  21. } else {
  22. // 有未完成的但不是我 就不能跳转
  23. wx.showModal({
  24. showCancel: false,
  25. content: "您的" + this.data.currentName + "课还未学完,快去学习吧"
  26. })
  27. }
  28. } else {
  29. // 我看完了这个视频 还能看
  30. wx.navigateTo({
  31. url: '../dbDetails/dbDetails?id=' + id
  32. })
  33. }
  34. } else {
  35. wx.navigateTo({
  36. url: '../dbDetails/dbDetails?id=' + id
  37. })
  38. }
  39. },
  40. // 录播列表
  41. getArr(sessionKey) {
  42. wx.request({
  43. url: app.globalData.publicUrl + '/wx/course/selectRecordBySessionKey',
  44. method: "post",
  45. data: {
  46. sessionKey
  47. },
  48. success: (res) => {
  49. if (res.data.code == 0) {
  50. this.setData({
  51. lbArr: res.data.list,
  52. currentName: "",
  53. currentId: null
  54. })
  55. for (let i = 0; i < res.data.list.length; i++) {
  56. // 这个节课未全部完成
  57. if (res.data.list[i].isDone == 0) {
  58. // 这个视频已经进行了 看一半或者看完了
  59. if (res.data.list[i].isStudyDone == 0 || res.data.list[i].isStudyDone == 1) {
  60. this.setData({
  61. currentName: res.data.list[i].courseName,
  62. currentId: res.data.list[i].id
  63. })
  64. }
  65. }
  66. }
  67. let result = [];
  68. for (let i = 0; i < res.data.list.length; i++) {
  69. result.push({
  70. courseTime: res.data.list[i].courseTime
  71. });
  72. }
  73. const timesArr = result.map((item) => {
  74. return item.courseTime;
  75. });
  76. let sfmArr = [];
  77. for (let i = 0; i < timesArr.length; i++) {
  78. let value = timesArr[i];
  79. const resultValue = this.handler(value);
  80. sfmArr.push({
  81. courseTime: resultValue
  82. })
  83. this.setData({
  84. sfmArr: sfmArr
  85. })
  86. }
  87. if (this.data.lbArr.length == 0) {
  88. this.setData({
  89. showNull: true
  90. })
  91. }
  92. } else {
  93. if (this.data.lbArr.length == 0) {
  94. this.setData({
  95. showNull: true
  96. })
  97. }
  98. }
  99. },
  100. fail: () => {
  101. if (this.data.lbArr.length == 0) {
  102. this.setData({
  103. showNull: true
  104. })
  105. }
  106. }
  107. })
  108. },
  109. // 时间处理
  110. handler(value) {
  111. const second = Math.floor(value / 1000); //判断是否够1秒
  112. if (second < 1) {
  113. return "0秒";
  114. }
  115. const secondValue = second % 60; // 秒
  116. const minutes = Math.floor(second / 60); //判断是否够1分钟
  117. if (minutes < 1) {
  118. return `${secondValue}秒`;
  119. }
  120. const minutesValue = minutes % 60; //分
  121. const hours = Math.floor(minutes / 60); //判断是否够1小时
  122. if (hours < 1) {
  123. return `${minutesValue}分${secondValue}秒`;
  124. }
  125. const hoursValue = hours % 60; //小时
  126. return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  127. },
  128. async onShow() {
  129. const sessionKey = await tools.checkSessionAndLogin();
  130. this.getArr(sessionKey)
  131. }
  132. })