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. getExamList(sessionKey) {
  60. wx.request({
  61. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  62. method: "post",
  63. data: {
  64. sessionKey: sessionKey,
  65. questSub: '2',
  66. clasId: this.data.classInfo.id
  67. },
  68. success: (res) => {
  69. if (res.data.code == 0) {
  70. if (res.data.list.length == 0) {
  71. this.setData({
  72. showNull: true
  73. })
  74. } else {
  75. this.setData({
  76. dataArr: res.data.list
  77. })
  78. }
  79. }
  80. },
  81. fail: () => {
  82. this.setData({
  83. showNull: true
  84. })
  85. }
  86. })
  87. },
  88. // 查询我是否有班&&班级id
  89. isClass(sessionKey) {
  90. wx.request({
  91. url: app.globalData.publicUrl + '/wx/student/selMyClas',
  92. method: "post",
  93. data: {
  94. sessionKey: sessionKey
  95. },
  96. success: (res) => {
  97. if (res.data.code == 0) {
  98. this.setData({
  99. classInfo: res.data.data
  100. })
  101. this.getExamList(sessionKey);
  102. } else {
  103. wx.showModal({
  104. content: "您当前还没有开放的班级!",
  105. showCancel: false,
  106. success(res) {
  107. if (res.confirm) {
  108. wx.switchTab({
  109. url: '../index/index'
  110. })
  111. }
  112. }
  113. })
  114. return false;
  115. }
  116. }
  117. })
  118. },
  119. async onLoad() {
  120. const sessionKey = await tools.checkSessionAndLogin();
  121. this.setData({
  122. sessionKey: sessionKey
  123. })
  124. this.isClass(sessionKey);
  125. },
  126. })