detail.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <view>
  3. <view class="head box" style="margin-bottom: 10px;">
  4. <view>
  5. <text class="iconfont icon-shijian" />
  6. <timer ref="timer" />
  7. </view>
  8. <text class="iconfont icon-tika" @click="openTopicCard = true">
  9. 题卡
  10. </text>
  11. </view>
  12. <My_listbox :pullDown="false">
  13. <swiper :style="{ height: tovw(swiperHeight), marginTop: 0 }" :current-item-id="currentItemId"
  14. @change="swiperChange">
  15. <swiper-item v-for="item in detail.testquestions" :key="item.sat_courseware_testitemsid"
  16. :item-id="item.rowindex + ''">
  17. <view class="box">
  18. <view class="typemxstr">
  19. {{ item.rowindex }} {{ item.typemxstr }}<text class="score">({{ item.score }})</text>
  20. </view>
  21. <image class="image" v-if="item.attinfos.length" :src="item.attinfos[0].src" mode="aspectFill"
  22. lazy-load="true" />
  23. <view class="content">
  24. <view class="title">{{ item.question }}</view>
  25. <view class="option" v-for="option in item.options" :key="option.sequence"
  26. @click="selectOption(item.rowindex, option.option)"
  27. :class="item.answer.includes(option.option) ? 'active' : ''">
  28. <image class="image" v-if="option.url.length" :src="option.url[0].url" mode="aspectFill"
  29. lazy-load="true" />
  30. <view class="text">
  31. {{ option.option }} {{ option.content }}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="box" v-if="detail.status == '已完成'">
  37. <view class="typemxstr">答案</view>
  38. <view class="row" style="padding-top: 10px;">
  39. 结果:<text class="res-f" v-if="item.result == 0">答错</text><text v-else class="res-t">答对</text>
  40. </view>
  41. <view class="row">
  42. 正确答案:<text style="font-weight: bold;color:#009270 ;">{{ item.answer_fact.join(",") }}</text>
  43. </view>
  44. <view class="row">
  45. 分数:<text class="score">{{ item.result == 1 ? item.score : 0 }}</text>
  46. </view>
  47. </view>
  48. </swiper-item>
  49. </swiper>
  50. <view :style="{ height: tovw(80) }" />
  51. </My_listbox>
  52. <view class="bottom">
  53. <view v-if="currentItemId != 1" class="but up" hover-class="navigator-hover" @click="changeQuestions('-')">
  54. 上一题
  55. </view>
  56. <view v-if="detail.testquestions.length != currentItemId" class="but down" hover-class="navigator-hover"
  57. @click="changeQuestions('+')">
  58. 下一题
  59. </view>
  60. <view v-if="detail.testquestions.length == currentItemId && detail.status != '已完成'" class="but submit"
  61. @click="loading ? '' : submit" hover-class="navigator-hover">
  62. <u-loading-icon v-if="loading" />
  63. <text v-else>
  64. 提交
  65. </text>
  66. </view>
  67. </view>
  68. <u-popup :show="openTopicCard" :safeAreaInsetBottom="false" round="8" @close="openTopicCard = false">
  69. <My_listbox :pullDown="false" :automatic="false" defaultHeight="500">
  70. <view class="topic-card">
  71. <view class="topic-card-title">选择题目</view>
  72. <view class="topic-card-content">
  73. <view class="topic-card-item"
  74. :class="[currentItemId == item.rowindex ? 'topic-card-active' : '', item.answer.length > 0 ? 'topic-card-filled' : '']"
  75. v-for="item in detail.testquestions " :key="item.sat_courseware_testitemsid"
  76. :data-currentItemId="item.rowindex + ''" @click="swiperChange">
  77. {{ item.rowindex }}
  78. <view class="res" v-if="detail.status == '已完成'"
  79. :style="{ background: item.result == 1 ? '#70D95D' : '#E3041F' }" />
  80. </view>
  81. </view>
  82. </view>
  83. </My_listbox>
  84. <view class="bottom" style="position: relative;">
  85. <view class="but down" hover-class="navigator-hover" @click="openTopicCard = false">
  86. 关 闭
  87. </view>
  88. </view>
  89. </u-popup>
  90. <u-popup :show="showFinish" mode="center" round="8" :safeAreaInsetBottom="false">
  91. <view class="finish">
  92. <image class="result" src="../../static//examination-result.png" mode="aspectFill" />
  93. <view class="shadow" />
  94. <view class="finish-title">考试结果</view>
  95. <view class="finish-result">
  96. <view class="finish-result-item">
  97. <view class="finish-result-item-data" style="color:#FF3B30;">
  98. {{ detail.score }}
  99. </view>
  100. 成绩(分)
  101. </view>
  102. <view class="finish-result-item">
  103. <view class="finish-result-item-data" style="color:#3874F6;">
  104. {{ detail.answercount + ' / ' + detail.num }}
  105. </view>
  106. 答题数
  107. </view>
  108. </view>
  109. <view class="tips">
  110. <view class="row">
  111. <view class="dot" style="background: #52C41A;" />
  112. 答对<text class="text">{{ detail.rightcount }}</text>题
  113. </view>
  114. <view class="row">
  115. <view class="dot" style="background: #FF3B30;" />
  116. 答错<text class="text">{{ detail.errcount }}</text>题
  117. </view>
  118. </view>
  119. <view class="but but-res" @click="showFinish = false">
  120. 查看答案
  121. </view>
  122. <view class="but" @click="returnList">
  123. 返回
  124. </view>
  125. </view>
  126. </u-popup>
  127. <view class="quere-height">
  128. <view :id="'Item' + item.rowindex" v-for=" item in detail.testquestions "
  129. :key="item.sat_courseware_testitemsid" :item-id="item.rowindex + ''">
  130. <view class="box">
  131. <view class="typemxstr">
  132. {{ item.rowindex }} {{ item.typemxstr }}<text class="score">({{ item.score }})</text>
  133. </view>
  134. <image class="image" v-if="item.attinfos.length" :src="item.attinfos[0].src" mode="aspectFill"
  135. lazy-load="true" />
  136. <view class="content">
  137. <view class="title">{{ item.question }}</view>
  138. <view class="option" v-for=" option in item.options " :key="option.sequence"
  139. @click="selectOption(item.rowindex, option.option)"
  140. :class="item.answer.includes(option.option) ? 'active' : ''">
  141. <image class="image" v-if="option.url.length" :src="option.url[0].url" mode="aspectFill"
  142. lazy-load="true" />
  143. <view class="text">
  144. {{ option.option }} {{ option.content }}
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. <view class="box" v-if="detail.status == '已完成'">
  150. <view class="typemxstr">答案</view>
  151. <view class="row" style="padding-top: 10px;">
  152. 结果:<text class="res-f">答错</text><text class="res-t">答对</text>
  153. </view>
  154. <view class="row">
  155. 正确答案:<text style="font-weight: bold;color:#009270 ;">{{ item.answer_fact }}</text>
  156. </view>
  157. <view class="row">
  158. 分数:<text class="score">{{ item.result == 1 ? item.score : 0 }}</text>
  159. </view>
  160. </view>
  161. </view>
  162. </view>
  163. </view>
  164. </template>
  165. <script>
  166. import timer from "./modules/timer.vue"
  167. export default {
  168. components: { timer },
  169. data() {
  170. return {
  171. sat_courseware_testheadid: 0,
  172. currentItemId: '1',
  173. detail: {
  174. testquestions: []
  175. },
  176. swiperHeight: 10,
  177. openTopicCard: false,
  178. showFinish: false,
  179. loading: false,
  180. }
  181. },
  182. onLoad(options) {
  183. this.sat_courseware_testheadid = options.id || 0;
  184. this.getDetail();
  185. },
  186. methods: {
  187. getDetail() {
  188. this.$Http.basic({
  189. "id": 20240325102202,
  190. "content": {
  191. "sat_courseware_testheadid": this.sat_courseware_testheadid
  192. }
  193. }).then(res => {
  194. console.log("生成试卷并获取详情", res)
  195. if (this.cutoff(res.msg)) return;
  196. this.detail = res.data;
  197. if (this.detail.status != '已完成') {
  198. this.$refs.timer.startCounting()
  199. } else {
  200. this.$refs.timer.showTime = res.data.countdown;
  201. this.showFinish = true;
  202. }
  203. uni.setNavigationBarTitle({
  204. title: res.data.title,
  205. })
  206. this.$nextTick(() => { this.setSwiperHeight() })
  207. })
  208. },
  209. selectOption(rowindex, option) {
  210. if (this.detail.status == '已完成') return;
  211. let item = this.detail.testquestions[rowindex - 1],
  212. answer = item.answer;
  213. switch (item.typemxstr) {
  214. case '单选':
  215. answer = [option]
  216. break;
  217. case '多选':
  218. answer.some(v => v == option) ? answer = answer.filter(v => v != option) : answer.push(option)
  219. break;
  220. }
  221. this.$set(item, 'answer', answer)
  222. },
  223. swiperChange(e) {
  224. this.currentItemId = e.target.currentItemId || e.currentTarget.dataset.currentitemid;
  225. this.$nextTick(() => { this.setSwiperHeight() })
  226. },
  227. changeQuestions(e) {
  228. if (e == '+') {
  229. this.currentItemId = String(this.currentItemId - 0 + 1);
  230. } else {
  231. this.currentItemId = String(this.currentItemId - 1);
  232. }
  233. },
  234. setSwiperHeight() {
  235. let that = this;
  236. const element = `#Item${this.currentItemId}`;
  237. const query = uni.createSelectorQuery().in(that);
  238. setTimeout(() => {
  239. query.select(element).boundingClientRect();
  240. query.exec(res => {
  241. if (res && res[0]) that.swiperHeight = res[0].height - 10;
  242. });
  243. }, 100)
  244. },
  245. submit() {
  246. let content = {
  247. "sat_courseware_testid": this.detail.sat_courseware_testid,
  248. "answers": this.detail.testquestions.map(v => {
  249. return {
  250. sat_courseware_testitemsid: v.sat_courseware_testitemsid,
  251. answer: v.answer,
  252. rowindex: v.rowindex
  253. }
  254. })
  255. },
  256. notFilleds = content.answers.filter(v => v.answer.length == 0).map(v => v.rowindex),
  257. tips = "是否确定提交",
  258. that = this;
  259. if (notFilleds.length) tips = `题号“${notFilleds.join(',')}”还未完成!是否继续提交?`;
  260. content.countdown = that.$refs.timer.getTime();
  261. uni.showModal({
  262. title: '提示',
  263. content: tips,
  264. success: ({ confirm }) => {
  265. if (confirm) {
  266. that.loading = true;
  267. that.$Http.basic({
  268. "id": 20240326145902,
  269. content
  270. }).then(res => {
  271. console.log('提交试卷', res)
  272. that.loading = false;
  273. if (this.cutoff(res.msg, '', true)) return that.$refs.timer.startCounting();
  274. that.$refs.timer.endTiming();
  275. that.getDetail();
  276. })
  277. }
  278. },
  279. })
  280. },
  281. returnList() {
  282. uni.navigateBack();
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. body,
  289. page {
  290. height: 100vh;
  291. overflow: hidden;
  292. }
  293. .box {
  294. width: 355px;
  295. background: #FFFFFF;
  296. border-radius: 8px;
  297. margin: 10px auto 0;
  298. box-sizing: border-box;
  299. .row {
  300. padding: 5px 10px;
  301. .score {
  302. font-weight: bold;
  303. color: #095DE0;
  304. }
  305. .res-t,
  306. .res-f {
  307. font-family: Source Han Sans SC, Source Han Sans SC;
  308. font-weight: bold;
  309. font-size: 14px;
  310. }
  311. .res-t {
  312. color: #009270;
  313. }
  314. .res-f {
  315. color: #E3041F;
  316. }
  317. }
  318. .row:last-child {
  319. padding-bottom: 10px;
  320. }
  321. }
  322. .image {
  323. width: 163px;
  324. height: 100px;
  325. border-radius: 8px;
  326. }
  327. .head {
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. padding: 0 10px;
  332. height: 50px;
  333. /deep/ .time,
  334. .iconfont {
  335. font-family: Source Han Sans SC, Source Han Sans SC;
  336. font-size: 14px;
  337. color: #333333;
  338. }
  339. .icon-tika:before,
  340. .icon-shijian:before {
  341. color: #999999;
  342. margin-right: 5px;
  343. }
  344. }
  345. .quere-height {
  346. position: fixed;
  347. z-index: -9999;
  348. top: -99999999999999999;
  349. opacity: 0;
  350. }
  351. .typemxstr {
  352. width: 100%;
  353. height: 50px;
  354. padding: 15px 10px;
  355. border-bottom: 1px solid #DDDDDD;
  356. box-sizing: border-box;
  357. .score {
  358. color: #999999;
  359. margin-left: 5px;
  360. }
  361. }
  362. .content {
  363. padding: 10px;
  364. padding-bottom: 20px;
  365. .title {
  366. font-family: Source Han Sans SC, Source Han Sans SC;
  367. font-size: 14px;
  368. color: #333333;
  369. }
  370. .option {
  371. border-radius: 8px;
  372. border: 1px solid #CCCCCC;
  373. padding: 10px;
  374. margin-top: 10px;
  375. .text {
  376. font-family: PingFang SC, PingFang SC;
  377. }
  378. }
  379. .active {
  380. border: 1px solid #095DE0 !important;
  381. .text {
  382. color: #095DE0 !important;
  383. }
  384. }
  385. }
  386. .bottom {
  387. display: flex;
  388. position: fixed;
  389. bottom: 0;
  390. width: 375px;
  391. height: 64px;
  392. background: #FFFFFF;
  393. box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
  394. padding-right: 10px;
  395. box-sizing: border-box;
  396. .but {
  397. display: flex;
  398. align-items: center;
  399. justify-content: center;
  400. flex: 1;
  401. margin-left: 10px;
  402. width: 168px;
  403. height: 45px;
  404. border-radius: 5px;
  405. margin-top: 4px;
  406. box-sizing: border-box;
  407. }
  408. .up {
  409. background: #FFFFFF;
  410. border: 1px solid #999999;
  411. font-size: 16px;
  412. color: #666666;
  413. }
  414. .down,
  415. .submit {
  416. background: #095DE0;
  417. font-family: PingFang SC, PingFang SC;
  418. font-size: 16px;
  419. color: #FFFFFF;
  420. }
  421. .submit {
  422. background: #C30D23;
  423. }
  424. }
  425. .topic-card {
  426. .topic-card-title {
  427. font-family: PingFang SC, PingFang SC;
  428. font-weight: bold;
  429. font-size: 16px;
  430. color: #333333;
  431. margin: 20px;
  432. text-align: center;
  433. }
  434. .topic-card-content {
  435. display: flex;
  436. flex-wrap: wrap;
  437. padding-left: 8px;
  438. .topic-card-item {
  439. position: relative;
  440. width: 35px;
  441. text-align: center;
  442. height: 50px;
  443. line-height: 50px;
  444. border-radius: 5px;
  445. border: 1px solid #999999;
  446. margin-right: 10px;
  447. margin-bottom: 10px;
  448. .res {
  449. position: absolute;
  450. width: 4px;
  451. height: 4px;
  452. border-radius: 2px;
  453. bottom: 6px;
  454. left: 16px;
  455. background: red;
  456. }
  457. }
  458. .topic-card-active {
  459. border: 1px solid #095DE0;
  460. color: #095DE0;
  461. }
  462. .topic-card-filled {
  463. background: #F4F5F7 !important;
  464. }
  465. .topic-card-item:nth-child(8n) {
  466. margin-right: 0;
  467. }
  468. }
  469. }
  470. .finish {
  471. position: relative;
  472. width: 240px;
  473. background: #FFFFFF;
  474. box-shadow: 0px 2px 10px 1px rgba(98, 98, 241, 0.12);
  475. border-radius: 8px;
  476. padding-bottom: 20px;
  477. .result {
  478. position: absolute;
  479. width: 88px;
  480. height: 88px;
  481. top: -20px;
  482. left: 76px;
  483. }
  484. .shadow {
  485. position: absolute;
  486. top: 65px;
  487. left: 76px;
  488. width: 88px;
  489. height: 11px;
  490. background: rgba(227, 4, 31, 0.15);
  491. filter: blur(7.4338297843933105px);
  492. }
  493. &-title {
  494. font-family: Source Han Sans SC, Source Han Sans SC;
  495. font-size: 14px;
  496. color: #222222;
  497. text-align: center;
  498. padding-top: 96px;
  499. }
  500. &-result {
  501. display: flex;
  502. justify-content: space-around;
  503. height: 67px;
  504. width: 180px;
  505. margin: 18px auto 0;
  506. border-bottom: 1px solid #DDDDDD;
  507. &-item {
  508. text-align: center;
  509. font-family: PingFang HK, PingFang HK;
  510. font-size: 13px;
  511. color: #666666;
  512. &-data {
  513. height: 24px;
  514. line-height: 24px;
  515. font-family: Source Han Sans SC, Source Han Sans SC;
  516. font-weight: bold;
  517. font-size: 16px;
  518. margin-bottom: 5px;
  519. }
  520. }
  521. }
  522. .tips {
  523. display: flex;
  524. flex-direction: column;
  525. align-items: center;
  526. margin-top: 8px;
  527. .row {
  528. display: flex;
  529. align-items: center;
  530. margin-top: 10px;
  531. .dot {
  532. width: 6px;
  533. height: 6px;
  534. border-radius: 3px;
  535. margin-right: 10px;
  536. }
  537. .text {
  538. color: #3874F6;
  539. font-size: 16px;
  540. font-weight: bold;
  541. padding: 0 4px;
  542. }
  543. }
  544. }
  545. .but {
  546. width: 160px;
  547. height: 45px;
  548. text-align: center;
  549. line-height: 45px;
  550. background: #C30D23;
  551. border-radius: 22.5px;
  552. margin: 0 auto;
  553. font-family: PingFang SC, PingFang SC;
  554. font-weight: bold;
  555. font-size: 14px;
  556. color: #FFFFFF;
  557. margin-top: 10px;
  558. }
  559. .but-res {
  560. background: #FFFFFF;
  561. border: 1px solid #CCCCCC;
  562. margin-top: 25px;
  563. font-family: PingFang SC, PingFang SC;
  564. font-weight: bold;
  565. font-size: 14px;
  566. color: #333333;
  567. }
  568. }
  569. </style>