index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. define([
  2. 'require',
  3. 'api/topic',
  4. 'text!./index.html',
  5. 'css!./index.css'
  6. ], function (require, topicApi, html) {
  7. return {
  8. props: {
  9. activeName: {
  10. type: String,
  11. default: ''
  12. }
  13. },
  14. data: function () {
  15. return {
  16. page: 1,
  17. limit: 16,
  18. is_master: '',
  19. total: 0,
  20. questionList: [],
  21. finished: false,
  22. question: {},
  23. idList: [],
  24. visible: false,
  25. tabName: '0',
  26. };
  27. },
  28. computed: {
  29. index: function () {
  30. console.log(this.question);
  31. if (!this.question.id) {
  32. return -1;
  33. }
  34. return this.idList.indexOf(this.question.id);
  35. }
  36. },
  37. watch: {
  38. activeName: function (value) {
  39. if (value === 'wrong') {
  40. this.getQuestionList();
  41. }
  42. },
  43. is_master: function () {
  44. this.page = 1;
  45. this.total = 0;
  46. this.finished = false;
  47. this.getQuestionList();
  48. },
  49. tabName: function (value) {
  50. switch (value) {
  51. case '0':
  52. this.is_master = '';
  53. break;
  54. case '1':
  55. this.is_master = 0;
  56. break;
  57. case '2':
  58. this.is_master = 1;
  59. break;
  60. }
  61. },
  62. },
  63. methods: {
  64. getQuestionList: function () {
  65. var vm = this;
  66. topicApi.userWrongBank({
  67. page: this.page,
  68. limit: this.limit,
  69. is_master: this.is_master
  70. }).then(function (res) {
  71. var questionList = res.data.data;
  72. questionList.forEach(function (question) {
  73. switch (question.question_type) {
  74. case 1:
  75. question.questionType = '单选题';
  76. break;
  77. case 2:
  78. question.questionType = '多选题';
  79. break;
  80. case 3:
  81. question.questionType = '判断题';
  82. break;
  83. }
  84. });
  85. vm.questionList = questionList;
  86. vm.total = res.data.count;
  87. vm.finished = vm.limit > vm.questionList.length;
  88. });
  89. },
  90. handleCurrentChange: function () {
  91. this.getQuestionList();
  92. },
  93. lookQuestion: function (id) {
  94. var vm = this;
  95. this.nodeId = id;
  96. vm.idList.push(id)
  97. vm.getQuestion(id);
  98. vm.getIdList(1);
  99. vm.getIdList();
  100. },
  101. getQuestion: function (id) {
  102. var vm = this;
  103. topicApi.oneWrongBank({
  104. id: id
  105. }).then(function (res) {
  106. var question = res.data;
  107. var options = {};
  108. question.option = JSON.parse(question.option);
  109. if (Array.isArray(question.option)) {
  110. question.option.forEach(function (option, index) {
  111. options[String.fromCharCode(index + 65)] = option;
  112. });
  113. question.option = options;
  114. }
  115. switch (question.question_type) {
  116. case 1:
  117. question.questionType = '单选题';
  118. break;
  119. case 2:
  120. question.questionType = '多选题';
  121. break;
  122. case 1:
  123. question.questionType = '判断题';
  124. break;
  125. }
  126. vm.question = question;
  127. vm.visible = true;
  128. });
  129. },
  130. getIdList: function (order) {
  131. var vm = this;
  132. topicApi.userWrongBankIdArr({
  133. id: this.nodeId,
  134. is_master: this.is_master,
  135. order: order || 0
  136. }).then(function (res) {
  137. vm.idList = vm.idList.concat(res.data).sort(function (a, b) {
  138. return b - a;
  139. });
  140. });
  141. },
  142. masterQuestion: function (question) {
  143. var vm = this;
  144. topicApi.submitWrongBank({
  145. wrong_id: question.id,
  146. questions_id: question.questions_id,
  147. is_master: question.is_master ? 0 : 1
  148. }).then(function (res) {
  149. question.is_master = question.is_master ? 0 : 1;
  150. if (!vm.visible && vm.tabName !== '0') {
  151. if (vm.questionList.length === 1) {
  152. if (vm.page === 1) {
  153. vm.getQuestionList();
  154. } else {
  155. vm.page = vm.page - 1;
  156. vm.getQuestionList();
  157. }
  158. } else {
  159. vm.getQuestionList();
  160. }
  161. }
  162. });
  163. },
  164. deleteQuestion: function () {
  165. var vm = this;
  166. topicApi.delWrongBank({
  167. id: this.question.id
  168. }).then(function (res) {
  169. vm.$message.success('删除成功');
  170. if (vm.idList.length === 1) {
  171. vm.visible = false;
  172. } else if (vm.index === vm.idList.length - 1) {
  173. vm.getQuestion(vm.idList[vm.idList.length - 2]);
  174. vm.idList.splice(vm.index, 1);
  175. } else {
  176. vm.getQuestion(vm.idList[vm.index + 1]);
  177. vm.idList.splice(vm.index, 1);
  178. }
  179. });
  180. },
  181. changeQuestion: function (value) {
  182. var id = this.idList[this.index + value];
  183. this.getQuestion(id);
  184. if (this.index === this.idList.length - 2 && value === 1) {
  185. this.nodeId = this.idList[this.idList.length - 1];
  186. this.getIdList(1);
  187. } else if (this.index === 1 && value === -1) {
  188. this.nodeId = this.idList[0];
  189. this.getIdList();
  190. }
  191. },
  192. dialogClose: function () {
  193. this.getQuestionList();
  194. }
  195. },
  196. template: html
  197. };
  198. });