index.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. <template>
  2. <!-- 章节练习答题页-->
  3. <view :class="{'yejian': if_theme_dark}">
  4. <!--#ifdef APP-PLUS-->
  5. <view class="lz-status_bar">
  6. <view class="lz-top_view"></view>
  7. </view>
  8. <!--#endif-->
  9. <view class="kaoshi-head">
  10. <view class="kaoshi-head-top">
  11. <view class="kaoshi-head-left" @tap="$navigateBack">
  12. <view class="iconfont icon-zuojiantou"></view>
  13. </view>
  14. <view class="kaoshi-head-m">
  15. <view :class="{ 'moshi-active': !show_beiti, moshi: show_beiti }" @tap="show_beiti_click(false)">
  16. 答题模式
  17. </view>
  18. <view :class="{ 'moshi-active': show_beiti, moshi: !show_beiti }" @tap="show_beiti_click(true)">背题模式
  19. </view>
  20. </view>
  21. <view class="kaoshi-head-right">
  22. <view class="iconfont icon-shezhi1" @tap="show_change_moshi=true"></view>
  23. </view>
  24. </view>
  25. </view>
  26. <view scroll-y style="height: 100%;">
  27. <view style="height: 10px;"></view>
  28. <view class="questionBankAnswer" v-if="current_timu && current_timu.id">
  29. <question-type :current_timu="current_timu" :timu_order="timu_order" :total_num="total_num">
  30. </question-type>
  31. </view>
  32. <view class="questionBankAnswer-content" v-if="current_timu && current_timu.question_name">
  33. <question-title :node="current_timu.question_name"></question-title>
  34. <block v-for="(item, index) in current_timu.answers" :key="index">
  35. <!-- {{item.answer}} -->
  36. <question-option :ref="'questionOption_' + index" :type="type" :item="item" :index="index"
  37. :show_beiti="show_beiti" :current_timu="current_timu" :copy_user_answer="copy_user_answer"
  38. :timu_index="timu_order - 1" :copy_post_status="copy_post_status"
  39. @post_answer_req="post_answer_req" @set_copy_user_answer="set_copy_user_answer"
  40. @set_sub_button_style="set_sub_button_style"></question-option>
  41. </block>
  42. <template v-if="current_timu.type == 4">
  43. <question-tiankong :current_timu="current_timu" :is_tiankong_sub="is_tiankong_sub"
  44. :show_beiti="show_beiti" @set_current_timu="set_current_timu" @post_answer_req="post_answer_req"
  45. @set_sub_button_style="set_sub_button_style"></question-tiankong>
  46. </template>
  47. <template v-else-if="current_timu.type == 5">
  48. <question-jianda :current_timu="current_timu" :is_jianda_sub="is_jianda_sub"
  49. :show_beiti="show_beiti" @set_current_timu="set_current_timu" @post_answer_req="post_answer_req"
  50. @set_sub_button_style="set_sub_button_style"></question-jianda>
  51. </template>
  52. <view v-if="current_timu.answers && (current_timu.type == 2) && !show_beiti">
  53. <button :class="is_duoxuan_sub ? 'duoxuan_checked' : 'duoxuan' " type=" "
  54. @tap="post_answer_req">{{is_duoxuan_sub ? '提交成功' : '确认答案'}}
  55. </button>
  56. </view>
  57. <question-pre-next v-if="timu_list.length > 0" :total_num="total_num" :timu_order="timu_order"
  58. :timu_list="timu_list" @choice_timu_by_id="choice_timu_by_id" @tap_handler="tap_handler"
  59. class="questionBankAnswer-contentbtnbox"></question-pre-next>
  60. </view>
  61. <view v-if="current_timu.type == 5" class="jdttishi">温馨提示:简答题不记入错题,默认为正确</view>
  62. <question-answer ref="questionAnswer" v-if="current_timu && current_timu.answers && show_beiti || copy_post_status[current_timu.id]"
  63. :timu_order="timu_order" :show_beiti="show_beiti" :current_timu="current_timu"
  64. :copy_post_answer_right="copy_post_answer_right" :timu_list="timu_list"></question-answer>
  65. <view style="height: 50px;"></view>
  66. </view>
  67. <view class="order-pay">
  68. <question-fav class="questionBankAnswer-bottom-flex" :current_timu="current_timu" @collect_opt="collect_opt"
  69. :type="type"></question-fav>
  70. <question-note class="questionBankAnswer-bottom-flex" :current_timu="current_timu"></question-note>
  71. <question-jiucuo class="questionBankAnswer-bottom-flex" :current_timu="current_timu"></question-jiucuo>
  72. <question-answer-sheet class="questionBankAnswer-bottom-flex"
  73. @show_choice_timu_list="show_choice_timu_list = true"></question-answer-sheet>
  74. </view>
  75. <question-answer-sheet-1 v-if="show_choice_timu_list" @show_choice_timu_list="show_choice_timu_list = false"
  76. :timu_order="timu_order" :timu_list="timu_list" :my_res="my_res" :total_num="total_num"
  77. @choice_timu_by_id="choice_timu_by_id"></question-answer-sheet-1>
  78. <question-set :show_change_moshi="show_change_moshi" :if_theme_dark="if_theme_dark" @emptyLog="emptyLog"
  79. :show_empty="true" @set_if_theme_dark="set_if_theme_dark" @hide_change_moshi="show_change_moshi = false">
  80. </question-set>
  81. <overtimu v-if="show_over_dati" :timuinfo="over_dati_info" @tap_handler="tap_handler"></overtimu>
  82. <ifcontinue v-if="show_continue_answer" :timuorder="timu_order" @tap_handler="tap_handler"></ifcontinue>
  83. </view>
  84. </template>
  85. <script>
  86. // 退出答题组件
  87. import overtimu from '@/components/overtimu/index';
  88. import {
  89. mapState
  90. } from 'vuex';
  91. import ifcontinue from "@/components/if-continue/index"
  92. export default {
  93. data() {
  94. return {
  95. type: '', //from_type 1:章节练习 2:历年真题
  96. copy_post_answer_right: {},
  97. //区分多选题是否点击提交按钮
  98. is_duoxuan_sub: false,
  99. is_tiankong_sub: false,
  100. is_jianda_sub: false,
  101. //是否显示继续答题弹框
  102. show_continue_answer: false,
  103. //是否显示新用户左右滑动切换题目的提示
  104. guide: false,
  105. // 答题、背题模式
  106. show_beiti: false,
  107. // 上一题
  108. last_timu: {},
  109. // 当前题目
  110. current_timu: {},
  111. // 下一题
  112. next_timu: {},
  113. total_num: 0, //全部题目数
  114. // 用户输入的答案
  115. copy_user_answer: {},
  116. copy_right_answer_code: {},
  117. copy_post_status: {},
  118. // 是否显示退出答题弹框
  119. show_over_dati: false,
  120. over_dati_info: {},
  121. // 答题开始时间
  122. start_time: 0,
  123. // 显示答题卡
  124. show_choice_timu_list: false,
  125. // 答题卡
  126. timu_list: [],
  127. // 模式
  128. show_change_moshi: false,
  129. if_theme_dark: false, // 黑夜模式
  130. // 上次答到第几题
  131. timu_order: -1,
  132. current_tika_index: 0,
  133. my_res: {
  134. right_num: 0,
  135. error_num: 0
  136. }
  137. };
  138. },
  139. components: {
  140. overtimu,
  141. ifcontinue,
  142. },
  143. computed: {
  144. ...mapState(['subject', 'userinfo']),
  145. static_media() {
  146. return {
  147. img01: this.$myConfig.localMedia + '/static/img/dui.png',
  148. }
  149. },
  150. },
  151. onBackPress() {
  152. this.over_dati();
  153. return true;
  154. },
  155. onLoad(opts) {
  156. this.id = opts.id
  157. this.type = opts.from_type
  158. if (this.userinfo.user_id !== undefined) {
  159. this.init();
  160. }
  161. // 答题开始时间
  162. this.start_time = new Date().getTime();
  163. },
  164. onReady() {
  165. uni.setNavigationBarTitle({
  166. title: this.type == 1 ? '章节练习' : '历年真题'
  167. });
  168. },
  169. methods: {
  170. async init() {
  171. const info = await this.$myUserLogin.getUnitVipInfo(this.type,this.id);
  172. if(info.is_vip == 0 || info.owned_vip == 1){
  173. this.get_timu_list();
  174. }else{
  175. //需要vip但还不是vip
  176. uni.showToast({
  177. title: '暂无权限',
  178. icon: 'none'
  179. })
  180. setTimeout(() => {
  181. uni.reLaunch({
  182. url: '/pages/index/index'
  183. })
  184. }, 1500)
  185. }
  186. },
  187. set_sub_button_style(type, value) {
  188. this[type] = value
  189. },
  190. set_current_timu(data) {
  191. this.current_timu = JSON.parse(JSON.stringify(data))
  192. let copy_user_answer_this = this.copy_user_answer;
  193. if (copy_user_answer_this[this.current_timu.id]) {
  194. copy_user_answer_this[this.current_timu.id] = this.current_timu.my_answer_arr
  195. }
  196. },
  197. set_copy_user_answer(data) {
  198. this.copy_user_answer = JSON.parse(JSON.stringify(data))
  199. this.setAnswerStyle(this.current_timu);
  200. this.setMyAnswer();
  201. },
  202. // 提交答案
  203. async post_answer_req() {
  204. let noanswer = false
  205. let answerlist = this.copy_user_answer[this.current_timu.id]
  206. if (this.current_timu.type == 2) {
  207. for (var i = 0; i < answerlist.length; i++) {
  208. if (answerlist[i].active) {
  209. noanswer = true
  210. }
  211. }
  212. } else if (this.current_timu.type == 4 || this.current_timu.type == 5) {
  213. if (answerlist.length != 0) {
  214. noanswer = true
  215. for (var i = 0; i < answerlist.length; i++) {
  216. if (!answerlist[i] || answerlist[i] == '') {
  217. noanswer = false
  218. }
  219. }
  220. }
  221. } else {
  222. noanswer = true
  223. }
  224. if (!noanswer) {
  225. uni.showToast({
  226. title: '您还未答题',
  227. icon: 'none'
  228. })
  229. return
  230. }
  231. let timu_index = this.timu_order - 1;
  232. this.copy_post_status = Object.assign({}, this.copy_post_status, {
  233. [this.current_timu.id]: true
  234. });
  235. let answer = '';
  236. if (this.current_timu.type <= 3) {
  237. this.is_duoxuan_sub = true
  238. let answers = this.copy_user_answer[this.current_timu.id];
  239. for (let i = 0, leng = answers.length; i < leng; i++) {
  240. if (answers[i].active) {
  241. answer += answers[i].answer_code
  242. }
  243. }
  244. if (this.current_timu.right_answer.toString().toLowerCase().replace(/\s/g, '') === answer
  245. .toString().toLowerCase().replace(/\s/g, '')) {
  246. this.copy_post_answer_right = Object.assign({}, this.copy_post_answer_right, {
  247. [this.current_timu.id]: true
  248. });
  249. if (timu_index !== -1) {
  250. // if_que 答题状态:1是错2是对3是未答过此题
  251. this.setTimuState(timu_index, 2)
  252. }
  253. } else {
  254. if (timu_index !== -1) {
  255. this.setTimuState(timu_index, 1)
  256. }
  257. }
  258. } else {
  259. if (this.current_timu.type == 4) {
  260. this.is_tiankong_sub = true
  261. if (this.current_timu.my_answer == this.current_timu.right_answer) {
  262. if (timu_index !== -1) {
  263. // if_que 答题状态:1是错2是对3是未答过此题
  264. this.setTimuState(timu_index, 2)
  265. }
  266. } else {
  267. if (timu_index !== -1) {
  268. // if_que 答题状态:1是错2是对3是未答过此题
  269. this.setTimuState(timu_index, 1)
  270. }
  271. }
  272. } else {
  273. this.is_jianda_sub = true
  274. if (this.current_timu.my_answer == this.current_timu.right_answer) {
  275. if (timu_index !== -1) {
  276. // if_que 答题状态:1是错2是对3是未答过此题
  277. this.timu_list.splice(timu_index, 1, {
  278. ...this.timu_list[timu_index],
  279. state: 2
  280. })
  281. }
  282. } else {
  283. if (timu_index !== -1) {
  284. // if_que 答题状态:1是错2是对3是未答过此题
  285. this.timu_list.splice(timu_index, 1, {
  286. ...this.timu_list[timu_index],
  287. state: 1
  288. })
  289. }
  290. }
  291. }
  292. this.is_jianda_sub = true
  293. }
  294. let url = ''
  295. // 1:章节练习 2:历年真题
  296. if (this.type == 1) {
  297. // 1:章节练习
  298. url = this.$myHttp.urlMap.unitansqueedit
  299. } else if (this.type == 2) {
  300. // 2:历年真题
  301. url = this.$myHttp.urlMap.zhentiansqueedit
  302. }
  303. let that = this;
  304. let res = await this.$myHttp.post({
  305. url: url,
  306. data: {
  307. id: this.current_timu.id,
  308. answer: this.current_timu.type <= 3 ? answer : this.current_timu.my_answer
  309. },
  310. needLogin: true
  311. });
  312. if (res.code == 1) {
  313. //0:错,1:对
  314. that.$set(this.current_timu, 'post_status', 1)
  315. this.setAnswerStyle(this.current_timu);
  316. this.setMyAnswer();
  317. }
  318. },
  319. //答题完成后,设置答题卡颜色
  320. setTimuState(timu_index, state) {
  321. this.timu_list.splice(timu_index, 1, {
  322. ...this.timu_list[timu_index],
  323. state: state
  324. })
  325. this.get_my_res();
  326. //TODO 答题对错这里,需要进一步 优化
  327. },
  328. collect_opt(type) {
  329. this.$set(this.current_timu, 'is_fav', type)
  330. },
  331. // 获取答题卡
  332. async get_timu_list() {
  333. let data = {}
  334. let url = ''
  335. // 1:章节练习 2:历年真题
  336. if (this.type == 1) {
  337. // 1:章节练习
  338. data = {
  339. unit_id: this.id
  340. };
  341. url = this.$myHttp.urlMap.unitCard
  342. } else if (this.type == 2) {
  343. // 2:历年真题
  344. data = {
  345. library_id: this.id
  346. };
  347. url = this.$myHttp.urlMap.zhentiCard
  348. }
  349. let res = await this.$myHttp.post({
  350. url: url,
  351. data: data,
  352. needLogin: true
  353. });
  354. if (res.code == 1) {
  355. this.timu_list = res.data.card;
  356. this.total_num = this.timu_list.length;
  357. this.timu_order = res.data.position
  358. this.isChangeTimu = false
  359. if (res.data.curr_question != []) {
  360. let timu = this.set_right_flg(res.data.curr_question);
  361. this.current_timu = timu;
  362. this.save_user_answer(this.current_timu);
  363. this.is_duoxuan_sub = false
  364. this.is_tiankong_sub = false
  365. this.is_jianda_sub = false
  366. } else {
  367. this.current_timu = null;
  368. }
  369. // this.get_timu_order();
  370. this.get_my_res();
  371. }
  372. },
  373. get_my_res() {
  374. let error_num = 0,
  375. right_num = 0;
  376. for (let i = 0, leng = this.timu_list.length; i < leng; i++) {
  377. //if_que 答题状态:1是错2是对3是未答过此题
  378. if (this.timu_list[i].state == 1) {
  379. error_num++
  380. } else if (this.timu_list[i].state == 2) {
  381. right_num++
  382. }
  383. }
  384. this.$set(this.my_res, 'right_num', right_num)
  385. this.$set(this.my_res, 'error_num', error_num)
  386. },
  387. // 获取用户答到第几题
  388. // async get_timu_order() {
  389. // let data = {}
  390. // let url = ''
  391. // // 1:章节练习 2:历年真题
  392. // if (this.type == 1) {
  393. // // 1:章节练习
  394. // data = {
  395. // unit_id: this.id
  396. // };
  397. // url = this.$myHttp.urlMap.unit_postion
  398. // } else if (this.type == 2) {
  399. // // 2:历年真题
  400. // data = {
  401. // library_id: this.id
  402. // };
  403. // url = this.$myHttp.urlMap.zhenti_postion
  404. // }
  405. // let res = await this.$myHttp.post({
  406. // url: url,
  407. // data: data,
  408. // needLogin: true
  409. // });
  410. // if (res.code == 1) {
  411. // this.timu_order = res.data
  412. // this.get_timu_info();
  413. // }
  414. // },
  415. // 根据答题卡获取题目
  416. choice_timu_by_id(index) {
  417. this.timu_order = index + 1
  418. this.isChangeTimu = true
  419. this.get_timu_info()
  420. uni.pageScrollTo({
  421. scrollTop: 0,
  422. duration: 200
  423. });
  424. },
  425. // 获取当前题目
  426. async get_timu_info() {
  427. let id = this.timu_list[this.timu_order - 1].id;
  428. let res = await this.$myHttp.post({
  429. url: this.$myHttp.urlMap.timu_details,
  430. data: {
  431. id: id
  432. },
  433. needLogin: true
  434. });
  435. if (res.code == 1) {
  436. this.isChangeTimu = false
  437. if (res.data != []) {
  438. let timu = this.set_right_flg(res.data);
  439. this.current_timu = timu;
  440. this.save_user_answer(this.current_timu);
  441. this.is_duoxuan_sub = false
  442. this.is_tiankong_sub = false
  443. this.is_jianda_sub = false
  444. } else {
  445. this.current_timu = null;
  446. }
  447. } else {
  448. this.isChangeTimu = false
  449. }
  450. },
  451. // 设置正确答案的标记
  452. set_right_flg(timu) {
  453. if (timu.type <=3) {
  454. timu.post_status = 0;
  455. if (timu.answers) {
  456. for (let i = 0, leng = timu.answers.length; i < leng; i++) {
  457. if (timu.right_answer.toString().toLowerCase().replace(/\s/g, '').indexOf(timu.answers[i]
  458. .answer_code.toString().toLowerCase().replace(/\s/g, '')) !== -1) {
  459. timu.answers[i]['right_flg'] = true
  460. }
  461. }
  462. }
  463. }
  464. return timu
  465. },
  466. // 本地存储用户答案
  467. save_user_answer(timu) {
  468. if (timu.type <= 3) {
  469. if (timu && timu.answers) {
  470. //copy_user_answer 用户输入的答案,
  471. if (!(this.copy_user_answer[timu.id])) {
  472. //本题用户的答案
  473. this.copy_user_answer = Object.assign({}, this.copy_user_answer, {
  474. [timu.id]: []
  475. });
  476. //copy_right_answer_code 本题的正确答案
  477. this.copy_right_answer_code = Object.assign({}, this.copy_right_answer_code, {
  478. [timu.id]: timu.right_answer
  479. });
  480. //copy_post_status 本题答没答过
  481. this.copy_post_status = Object.assign({}, this.copy_post_status, {
  482. [timu.id]: false
  483. });
  484. //copy_post_answer_right 本题答的是对是错
  485. this.copy_post_answer_right = Object.assign({}, this.copy_post_answer_right, {
  486. [timu.id]: false
  487. });
  488. for (let i = 0, leng = timu.answers.length; i < leng; i++) {
  489. this.copy_user_answer[timu.id].push({
  490. answer_code: timu.answers[i].answer_code,
  491. error_flg: false,
  492. active: false
  493. })
  494. }
  495. if (timu.my_answer !== '' && timu.my_answer !== null) {
  496. this.setUserAnswer(timu)
  497. } else {
  498. this.setAnswerStyle(timu);
  499. }
  500. } else {
  501. this.setAnswerStyle(timu);
  502. }
  503. }
  504. } else {
  505. let right_answer_arr = timu.right_answer.split('|');
  506. this.$set(timu, 'right_answer_arr', right_answer_arr)
  507. this.$set(timu, 'show_right_answer', false)
  508. if (!(this.copy_user_answer[timu.id]) || this.copy_user_answer[timu.id].length == 0) {
  509. //本地没有记录呢,如果my_answer有值,写进去
  510. this.copy_user_answer = Object.assign({}, this.copy_user_answer, {
  511. [timu.id]: []
  512. });
  513. this.copy_post_status = Object.assign({}, this.copy_post_status, {
  514. [timu.id]: false
  515. });
  516. if (timu.my_answer == '' || timu.my_answer == null) {
  517. //之前没有答过题
  518. let arr = [];
  519. arr.length = right_answer_arr.length;
  520. this.$set(timu, 'my_answer_arr', arr)
  521. this.$set(timu, 'my_answer', '')
  522. this.setAnswerStyle(timu);
  523. } else {
  524. //之前答过题了
  525. this.setUserAnswer(timu)
  526. }
  527. } else {
  528. //之前答过题了
  529. this.setUserAnswer(timu)
  530. }
  531. }
  532. },
  533. //获取题目信息后,如果答过题了,设置到本地
  534. setUserAnswer(timu) {
  535. //timu.my_answer !== '' && timu.my_answer !== null 说明这道题已经回答过了
  536. this.copy_post_status = Object.assign({}, this.copy_post_status, {
  537. [timu.id]: true
  538. });
  539. // 如果是判断和单选。执行以下处理
  540. if (timu.type == 1 || timu.type == 3) {
  541. let index = timu.answers.findIndex(item => item.answer_code == timu.my_answer)
  542. // this.$nextTick(() => {
  543. if (this.copy_user_answer[timu.id]) {
  544. for (let i = 0, leng = this.copy_user_answer[timu.id].length; i <
  545. leng; i++) {
  546. this.copy_user_answer[timu.id].splice(i, 1, {
  547. ...this.copy_user_answer[timu.id][i],
  548. active: false,
  549. error_flg: false
  550. })
  551. }
  552. if (timu.right_answer.toString().toLowerCase().replace(/\s/g, '').indexOf(
  553. timu.my_answer.toString().toLowerCase().replace(/\s/g, '')) === -1) {
  554. this.copy_user_answer[timu.id].splice(index, 1, {
  555. ...this.copy_user_answer[timu.id][index],
  556. active: true,
  557. error_flg: true
  558. })
  559. } else {
  560. this.copy_user_answer[timu.id].splice(index, 1, {
  561. ...this.copy_user_answer[timu.id][index],
  562. active: true,
  563. error_flg: false
  564. })
  565. }
  566. }
  567. // });
  568. } else if (timu.type == 2) {
  569. // 如果是多选。执行以下处理
  570. if (this.copy_user_answer[timu.id]) {
  571. if (this.is_duoxuan_sub = true) {
  572. this.is_duoxuan_sub = false
  573. }
  574. for (let key of timu.my_answer) {
  575. let index = timu.answers.findIndex(item => item.answer_code == key)
  576. if (this.copy_user_answer[timu.id][index]) {
  577. if (this.copy_user_answer[timu.id][index].active) {
  578. if (timu.right_answer.toString().toLowerCase().replace(/\s/g, '').indexOf(key
  579. .toString().toLowerCase().replace(/\s/g, '')) === -1) {
  580. this.copy_user_answer[timu.id].splice(index, 1, {
  581. ...this.copy_user_answer[timu.id][index],
  582. active: false,
  583. error_flg: true
  584. })
  585. } else {
  586. this.copy_user_answer[timu.id].splice(index, 1, {
  587. ...this.copy_user_answer[timu.id][index],
  588. active: false,
  589. error_flg: false
  590. })
  591. }
  592. } else {
  593. if (timu.right_answer.toString().toLowerCase().replace(/\s/g, '').indexOf(key
  594. .toString().toLowerCase().replace(/\s/g, '')) === -1) {
  595. this.copy_user_answer[timu.id].splice(index, 1, {
  596. ...this.copy_user_answer[timu.id][index],
  597. active: true,
  598. error_flg: true
  599. })
  600. } else {
  601. this.copy_user_answer[timu.id].splice(index, 1, {
  602. ...this.copy_user_answer[timu.id][index],
  603. active: true,
  604. error_flg: false
  605. })
  606. }
  607. }
  608. }
  609. }
  610. }
  611. } else {
  612. // 如果是填空,简答
  613. this.$set(timu, 'my_answer_arr', timu.my_answer.split('|'))
  614. this.$set(timu, 'my_answer', timu.my_answer)
  615. this.$set(timu, 'show_right_answer', true)
  616. this.copy_user_answer = Object.assign({}, this.copy_user_answer, {
  617. [timu.id]: []
  618. });
  619. this.copy_user_answer[timu.id].push(...timu.my_answer_arr)
  620. }
  621. this.setAnswerStyle(timu);
  622. },
  623. //单选多选判断,选项正确错误
  624. setAnswerStyle(timu) {
  625. this.$nextTick(() => {
  626. timu.answers.forEach((item, index) => {
  627. this.$refs['questionOption_' + index][0].setAnswerStyle(this.copy_user_answer);
  628. })
  629. this.setMyAnswer();
  630. })
  631. },
  632. setMyAnswer() {
  633. if (this.show_beiti || this.copy_post_status[this.current_timu.id]) {
  634. // this.$nextTick(() => {
  635. this.$refs.questionAnswer.my_answer(this.copy_user_answer)
  636. // })
  637. }
  638. },
  639. //设置夜间模式
  640. set_if_theme_dark(data) {
  641. this.if_theme_dark = data
  642. },
  643. //清空答题卡记录
  644. emptyLog() {
  645. let that = this
  646. uni.showModal({
  647. title: "警告",
  648. content: "清除记录后错题记录也会清除,请谨慎操作",
  649. confirmText: "确认清除",
  650. confirmColor: '#3c7bfc',
  651. success: function success(res) {
  652. if (res.confirm) {
  653. that.emptyTestLog();
  654. } else if (res.cancel) {
  655. // console.log("用户点击取消");
  656. }
  657. }
  658. });
  659. },
  660. async emptyTestLog() {
  661. let data = {}
  662. let url = ""
  663. if (this.type == 1) {
  664. // 1:章节练习
  665. data = {
  666. unit_id: this.id
  667. };
  668. url = this.$myHttp.urlMap.emptyTestLog
  669. } else if (this.type == 2) {
  670. // 2:历年真题
  671. data = {
  672. library_id: this.id
  673. };
  674. url = this.$myHttp.urlMap.emptyLibraryLog
  675. }
  676. let res = await this.$myHttp.post({
  677. url: url,
  678. data: data,
  679. needLogin: true
  680. });
  681. if (res.code == 1) {
  682. this.get_timu_list();
  683. // this.get_timu_order();
  684. this.show_change_moshi = false;
  685. this.copy_user_answer = {}
  686. }
  687. },
  688. // 中途退出
  689. over_dati() {
  690. this.over_dati_info = {
  691. total_num: this.total_num,
  692. zhengquelv: (100 * (this.my_res.right_num / ((this.my_res.right_num + this.my_res.error_num == 0) ?
  693. 1 : (this.my_res.right_num + this.my_res.error_num)))).toFixed(2),
  694. right_num: this.my_res.right_num,
  695. error_num: this.my_res.error_num,
  696. yida_num: this.my_res.right_num + this.my_res.error_num
  697. };
  698. // console.log(this.over_dati_info)
  699. this.$nextTick(() => {
  700. // 显示弹窗
  701. this.show_over_dati = true;
  702. });
  703. },
  704. tap_handler(type) {
  705. if (type == 0) {
  706. this.show_over_dati = false;
  707. } else if (type == 1) {
  708. this.$redirectTo(
  709. '/pages/questionBank/questionOver/index?id=' +
  710. this.id +
  711. '&from_type=' +
  712. this.type +
  713. '&end_time=' +
  714. this.endtime() +
  715. '&right_num=' +
  716. this.my_res.right_num +
  717. '&start_time=' +
  718. this.start_time +
  719. '&zhengquelv=' +
  720. 100 * (this.my_res.right_num / ((this.my_res.right_num + this.my_res.error_num == 0) ? 1 : (
  721. this.my_res.right_num + this.my_res.error_num))).toFixed(2) +
  722. '&total_num=' +
  723. (this.my_res.right_num + this.my_res.error_num) || 0
  724. )
  725. } else if (type == 3) {
  726. this.show_continue_answer = false;
  727. this.choice_timu_by_id({
  728. id: this.timu_order
  729. })
  730. } else if (type == 4) {
  731. this.show_continue_answer = false;
  732. this.get_timu_info();
  733. }
  734. },
  735. show_beiti_click(type) {
  736. this.show_beiti = type;
  737. this.setAnswerStyle(this.current_timu);
  738. },
  739. endtime() {
  740. let yy = new Date().getFullYear();
  741. let mm = new Date().getMonth() < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
  742. let dd = new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate();
  743. let hh = new Date().getHours();
  744. let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
  745. let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
  746. return yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
  747. }
  748. }
  749. };
  750. </script>
  751. <style>
  752. @import "~@/static/css/tiku.css";
  753. </style>