detail.vue 20 KB

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