index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. let app = getApp()
  2. Page({
  3. data: {
  4. tabs: [{
  5. name: '未完成'
  6. }, {
  7. name: '合格'
  8. }, {
  9. name: '不合格'
  10. }, {
  11. name: '缺考'
  12. }],
  13. currentTab: 0,
  14. phone: '',
  15. answerList: [],
  16. qualifiedList: [],
  17. unqualifiedList: [],
  18. missedList: [],
  19. record: [],//答题结果
  20. recordindex: 0
  21. },
  22. onShareAppMessage(){},
  23. onLoad() {
  24. let that = this;
  25. dd.getStorage({
  26. key: 'userInf',
  27. success: function (res) {
  28. that.setData({
  29. phone: res.data.phone
  30. })
  31. let params = {
  32. phone: res.data.phone
  33. // phone: '17611172370'
  34. }
  35. that.getUndoneExam(params)
  36. },
  37. fail: function (res) {
  38. dd.alert({ content: res.errorMessage });
  39. }
  40. });
  41. },
  42. onShow() {
  43. let that = this
  44. dd.getStorage({
  45. key: 'record',
  46. success: function (res) {
  47. that.setData({
  48. record: res
  49. })
  50. },
  51. fail: function (res) {
  52. dd.alert({ content: res.errorMessage });
  53. }
  54. });
  55. },
  56. // tab切换逻辑
  57. swichNav(e) {
  58. if (this.data.currentTab === e.target.dataset.current) {
  59. return false;
  60. } else {
  61. this.setData({
  62. currentTab: e.target.dataset.current
  63. })
  64. this.getCurrentTab()
  65. }
  66. },
  67. goAnswer(e) {
  68. let exam_id = e.target.dataset.examid
  69. let result_id = e.target.dataset.resultid
  70. let duration = e.target.dataset.duration
  71. let result_status = e.target.dataset.resultstatus
  72. if (e.target.dataset.resultstatus == 1) {
  73. dd.confirm({
  74. title: '温馨提示',
  75. content: '是否继续考试',
  76. confirmButtonText: '是',
  77. cancelButtonText: '否',
  78. success: (result) => {
  79. if (result.confirm) {
  80. dd.navigateTo({
  81. url: '../answer/answer?exam_id=' + exam_id + '&result_id=' + result_id + '&duration=' + duration + '&result_status=' + result_status
  82. })
  83. }
  84. },
  85. });
  86. return
  87. } else {
  88. dd.confirm({
  89. title: '温馨提示',
  90. content: '是否开始考试',
  91. confirmButtonText: '是',
  92. cancelButtonText: '否',
  93. success: (result) => {
  94. if (result.confirm) {
  95. this.goStartExam(exam_id, result_id, duration, result_status)
  96. }
  97. },
  98. });
  99. }
  100. },
  101. goStartExam(exam_id, result_id, duration, result_status) {
  102. let params = {
  103. result_id: result_id
  104. }
  105. app.https('POST', app.globaldata.apiUrl.startExam, JSON.stringify(params), {
  106. type: false
  107. }).then(res => {
  108. dd.reLaunch({
  109. url: '../answer/answer?exam_id=' + exam_id + '&result_id=' + result_id + '&duration=' + duration + '&result_status=' + result_status
  110. })
  111. })
  112. },
  113. goretakeExam(e) {
  114. console.log(e)
  115. dd.setStorage({
  116. key: 'answerid',
  117. data: {
  118. exam_id:e.target.dataset.examid,
  119. result_id: e.target.dataset.resultid
  120. }
  121. });
  122. dd.reLaunch({
  123. url: "../result/result?scores=" + e.target.dataset.scores + "&qualified=" + 0
  124. })
  125. },
  126. swiperChange(e) {
  127. this.setData({ currentTab: e.detail.current });
  128. this.getCurrentTab()
  129. },
  130. getCurrentTab() {
  131. let currentTab = this.data.currentTab
  132. console.log(currentTab)
  133. let params = {
  134. phone: this.data.phone
  135. }
  136. if (currentTab == 0) {
  137. this.getUndoneExam(params);
  138. } else if (currentTab == 1) {
  139. this.getQualifiedExam(params);
  140. } else if (currentTab == 2) {
  141. this.getUnqualifiedExam(params);
  142. } else {
  143. this.getMissedExam(params);
  144. }
  145. },
  146. // 未完成
  147. getUndoneExam(params) {
  148. let that = this
  149. app.https('POST', app.globaldata.apiUrl.getUndoneExam, JSON.stringify(params), {
  150. type: false
  151. }).then(res => {
  152. that.setData({
  153. answerList: res.data.data
  154. })
  155. let record = this.data.record.data
  156. if (record && record != []) {
  157. that.getnum(record)
  158. }
  159. })
  160. },
  161. getnum(record) {
  162. let that = this
  163. let counter = 0;
  164. for (let i = 0; i < record.length; i++) {
  165. if (record[i]) counter++;
  166. }
  167. let percent = (counter / (record.length)) * 100
  168. dd.getStorage({
  169. key: 'answerid',
  170. success: function (res) {
  171. let answerLists = that.data.answerList.map((item) => {
  172. if (item.exam_id == res.data.exam_id) {
  173. return {
  174. ...item,
  175. percent: percent ? percent : 0
  176. }
  177. } else {
  178. return {
  179. ...item
  180. }
  181. }
  182. })
  183. that.setData({
  184. answerList: answerLists
  185. })
  186. console.log(that.data.answerList)
  187. }
  188. });
  189. },
  190. getQualifiedExam(params) {
  191. app.https('POST', app.globaldata.apiUrl.getQualifiedExam, JSON.stringify(params), {
  192. type: false
  193. }).then(res => {
  194. this.setData({
  195. qualifiedList: res.data.data
  196. })
  197. })
  198. },
  199. getUnqualifiedExam(params) {
  200. app.https('POST', app.globaldata.apiUrl.getUnqualifiedExam, JSON.stringify(params), {
  201. type: false
  202. }).then(res => {
  203. this.setData({
  204. unqualifiedList: res.data.data
  205. })
  206. })
  207. },
  208. getMissedExam(params) {
  209. app.https('POST', app.globaldata.apiUrl.getMissedExam, JSON.stringify(params), {
  210. type: false
  211. }).then(res => {
  212. this.setData({
  213. missedList: res.data.data
  214. })
  215. })
  216. }
  217. });