last.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const tools = require('../../utils/tools.js');
  2. const app = require('../../utils/util.js');
  3. Page({
  4. data: {
  5. showNull: false,
  6. dataArr: [],
  7. sessionKey: '',
  8. classInfo: {},
  9. },
  10. startAnswer(e) {
  11. let id = e.currentTarget.dataset.idx;
  12. let paperId = e.currentTarget.dataset.paperid;
  13. let answersId = e.currentTarget.dataset.answersid;
  14. if (answersId) {
  15. this.toPath(id, paperId, answersId);
  16. } else {
  17. this.beginKao(id, paperId, this.data.sessionKey);
  18. }
  19. },
  20. toPath(id, paperId, answersId) {
  21. wx.navigateTo({
  22. url: '/pages/lastdetail/lastdetail?id=' + id + '&paperId=' + paperId + '&answersId=' + answersId,
  23. })
  24. },
  25. beginKao(id, paperId, sessionKey) {
  26. wx.request({
  27. url: app.globalData.publicUrl + '/wx/exam/begin',
  28. method: "post",
  29. data: {
  30. sessionKey: sessionKey,
  31. id: id,
  32. paperId: paperId,
  33. },
  34. success: (res) => {
  35. if (res.data.code == 0) {
  36. this.toPath(id, paperId, res.data.answersId);
  37. }
  38. }
  39. })
  40. },
  41. lookAnswer(e) {
  42. let answersId = e.currentTarget.dataset.answersid;
  43. wx.request({
  44. url: app.globalData.publicUrl + '/wx/answer/detail',
  45. method: "post",
  46. data: {
  47. sessionKey: this.data.sessionKey,
  48. answersId: answersId
  49. },
  50. success: (res) => {
  51. if (res.data.code == 0) {
  52. wx.navigateTo({
  53. url: '/pages/lastdetailDetail/lastdetailDetail?answersId=' + answersId,
  54. })
  55. }
  56. }
  57. })
  58. },
  59. async onLoad() {
  60. const sessionKey = await tools.checkSessionAndLogin();
  61. this.setData({
  62. sessionKey: sessionKey
  63. })
  64. this.isClass(sessionKey);
  65. },
  66. getBanner(sessionKey) {
  67. wx.request({
  68. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  69. method: "post",
  70. data: {
  71. sessionKey: sessionKey,
  72. questSub: '2',
  73. clasId: this.data.classInfo.id
  74. },
  75. success: (res) => {
  76. if (res.data.code == 0) {
  77. if (res.data.list.length == 0) {
  78. this.setData({
  79. showNull: true
  80. })
  81. } else {
  82. this.setData({
  83. dataArr: res.data.list
  84. })
  85. }
  86. }
  87. },
  88. fail: () => {
  89. this.setData({
  90. showNull: true
  91. })
  92. }
  93. })
  94. },
  95. // 查询我是否有班&&班级名字
  96. isClass(sessionKey) {
  97. wx.request({
  98. url: app.globalData.publicUrl + '/wx/student/selMyClas',
  99. method: "post",
  100. data: {
  101. sessionKey: sessionKey
  102. },
  103. success: (res) => {
  104. if (res.data.code == 0) {
  105. this.setData({
  106. classInfo: res.data.data
  107. })
  108. this.getBanner(sessionKey);
  109. } else {
  110. wx.showModal({
  111. content: "您当前还没有开放的班级!",
  112. showCancel: false,
  113. success(res) {
  114. if (res.confirm) {
  115. wx.switchTab({
  116. url: '../index/index'
  117. })
  118. }
  119. }
  120. })
  121. return false;
  122. }
  123. }
  124. })
  125. },
  126. })