examination.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <view class="pages">
  3. <u-empty mode="search" v-if="!formData.paperId&&hasload==true" :text="emptyText" marginTop="20vh"></u-empty>
  4. <view class="info" v-if="!start">
  5. <view class="page-wrap">
  6. <view class="paper-name">{{info.paperName}}</view>
  7. <view class="info-item">
  8. <view class="til"></view>
  9. <view class="con">
  10. 本套试卷共{{info.singleCount}}个单选题,共{{info.singleCredit}}积分,
  11. {{info.multipleCount}}个多选题,共{{info.multipleCredit}}积分,
  12. {{info.judgeCount}}个判断题,共{{info.judgeCredit}}积分。根据题干要求作答。请先作答,然后再校对答案。
  13. </view>
  14. </view>
  15. <view class="info-item" v-if="info.paperAttention">
  16. <view class="til">注意事项</view>
  17. <view class="con">{{info.paperAttention}}</view>
  18. </view>
  19. <view class="info-item" v-if="info.remark">
  20. <view class="til">备注信息</view>
  21. <view class="con">{{info.remark}}</view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="" v-else>
  26. <view class="swiper-wrap">
  27. <swiper class="swiper"
  28. :circular="false"
  29. :indicator-dots="false"
  30. :autoplay="false"
  31. :interval="5000"
  32. :current="current"
  33. @change="swiperChange"
  34. :duration="500">
  35. <swiper-item v-for="item in topicList" :key="item.id">
  36. <view class="swiper-item">
  37. <!-- 题目类型: 1-单选题 2-多选题 3-判断题 -->
  38. <view class="type-1" v-if="item.topicType==1||item.topicType==3">
  39. <text class="topic-type">{{item.topicType|filterTopicType}}</text>
  40. <view class="question">{{item.content}}</view>
  41. <view class="choice u-flex" :class="formData.answerList[current].answer == choice.split(':')[0] ? 'selected':''"
  42. @click="choiceAnswer(choice)"
  43. v-for="(choice,index) in item.choiceList" :key="index">
  44. <view class="sort">
  45. {{choice.split(":")[0]}}
  46. </view>
  47. <view class="answer">
  48. {{choice.split(":")[1]}}
  49. </view>
  50. <view class="status"></view>
  51. </view>
  52. </view>
  53. <view class="type-2" v-else-if="item.topicType==2">
  54. <text class="topic-type">{{item.topicType|filterTopicType}}</text>
  55. <view class="question">{{item.content}}</view>
  56. <view class="choice u-flex" :class="formData.answerList[current].answer.includes(choice.split(':')[0]) ? 'selected':''"
  57. @click="multipleChoice(choice)"
  58. v-for="(choice,index) in item.choiceList" :key="index">
  59. <view class="sort">
  60. {{choice.split(":")[0]}}
  61. </view>
  62. <view class="answer">
  63. {{choice.split(":")[1]}}
  64. </view>
  65. <view class="status"></view>
  66. </view>
  67. </view>
  68. <!-- <view class="type-3" v-else-if="item.topicType==3">
  69. </view> -->
  70. </view>
  71. </swiper-item>
  72. </swiper>
  73. </view>
  74. </view>
  75. <view class="bottom-btn-static">
  76. <view class="bottom-btn-fixed">
  77. <view class="btn" v-if="!start&&formData.paperId" @click="startAnswering">开始答题</view>
  78. <view class="btns u-flex" v-else>
  79. <view class="btn" @click="preQuestion" v-if="current>0">上一题</view>
  80. <view class="btn yellow" @click="nextQuestion" v-if="current<topicList.length-1">下一题</view>
  81. <view class="btn yellow" v-else-if="current==topicList.length-1" @click="submit">提交试卷</view>
  82. </view>
  83. </view>
  84. </view>
  85. <u-modal
  86. :show="submitShow"
  87. :title="submitShowTitle"
  88. @confirm="paperSubmit"
  89. @cancel="submitShow=false"
  90. :showCancelButton="true"
  91. :content='submitShowContent'>
  92. <view class="slot-content" style="text-align: center;">
  93. <img src="../static/img/icon-warning.png" alt="">
  94. <view class="" style="text-align: left;font-size: 28rpx;color: #999;margin-top: 20rpx;">
  95. {{submitShowContent}}
  96. </view>
  97. </view>
  98. </u-modal>
  99. </view>
  100. </template>
  101. <script>
  102. export default {
  103. data() {
  104. return {
  105. id:'',
  106. start:false,
  107. info:{},
  108. topicList:[],
  109. current:0,
  110. formData:{
  111. paperId:'',
  112. timeUsed:'',
  113. startTime:'',
  114. endTime:'',
  115. answerList:[]
  116. },
  117. submitShow:false,
  118. submitShowTitle:'提示',
  119. submitShowContent:'确认提交?',
  120. hasload:false,
  121. emptyText:'没有可用的试卷,请联系管理员'
  122. }
  123. },
  124. onShow() {
  125. },
  126. onLoad(page) {
  127. this.id = page.id;
  128. this.findPager();
  129. },
  130. computed: {
  131. totalAnswer() {
  132. let that = this;
  133. return this.formData.answerList.reduce((total, item) => {
  134. if(item.answer){
  135. total += 1;
  136. }
  137. return total;
  138. }, 0);
  139. }
  140. },
  141. methods: {
  142. findPager(){
  143. this.$u.api.findPager({classifyId:this.id}).then(res=>{
  144. this.info = res.data;
  145. this.formData.paperId = res.data.id;
  146. this.findPagerTopic(this.formData.paperId);
  147. // console.log('findPager',res);
  148. }).catch(err=>{
  149. this.hasload = true;
  150. this.emptyText = err.msg
  151. console.log('findPager',err);
  152. })
  153. },
  154. findPagerTopic(id){
  155. this.$u.api.findPagerTopic({paperId:id}).then(res=>{
  156. this.topicList = res.data.topicsList;
  157. for (let i=0;i<this.topicList.length;i++) {
  158. let data = {
  159. paperTopicId:this.topicList[i].id,
  160. topicLibId:this.topicList[i].topicLibId,
  161. answer:''
  162. }
  163. this.formData.answerList.push(data)
  164. }
  165. console.log('answerList',this.formData.answerList);
  166. // console.log('findPagerTopic',res);
  167. }).catch(err=>{
  168. console.log('findPagerTopic',err);
  169. })
  170. },
  171. startAnswering(){
  172. this.start = true;
  173. const now = new Date();
  174. this.formData.startTime = uni.$u.timeFormat(now, 'yyyy-mm-dd hh:MM:ss');
  175. uni.setNavigationBarTitle({
  176. title: `${this.current+1}/${this.topicList.length}`
  177. });
  178. },
  179. choiceAnswer(choice){
  180. // console.log('choiceAnswer',choice.split(":")[0]);
  181. this.formData.answerList[this.current].answer = choice.split(":")[0];
  182. // console.log('answerList',this.formData.answerList);
  183. },
  184. multipleChoice(choice){
  185. if (this.formData.answerList[this.current].answer.includes(choice.split(":")[0])) {
  186. this.formData.answerList[this.current].answer = this.formData.answerList[this.current].answer.replace(choice.split(":")[0], "");
  187. } else {
  188. this.formData.answerList[this.current].answer = this.formData.answerList[this.current].answer.concat(choice.split(":")[0]).split("").sort().join("");
  189. }
  190. // console.log('answerList-',this.formData.answerList);
  191. },
  192. swiperChange(e){
  193. this.current = e.detail.current;
  194. uni.setNavigationBarTitle({
  195. title: `${this.current+1}/${this.topicList.length}`
  196. });
  197. },
  198. nextQuestion(){
  199. this.current++
  200. },
  201. preQuestion(){
  202. this.current--
  203. },
  204. submit(){
  205. let that = this;
  206. if(this.totalAnswer<this.topicList.length){
  207. this.submitShowContent = `本套试卷共${this.topicList.length}题,您已完成${this.totalAnswer}题,还剩${this.topicList.length - this.totalAnswer}题,确认提交吗?`
  208. }else{
  209. this.submitShowContent = '确认提交?'
  210. }
  211. this.submitShow = true;
  212. },
  213. paperSubmit(){
  214. const now = new Date();
  215. this.formData.endTime = uni.$u.timeFormat(now, 'yyyy-mm-dd hh:MM:ss');
  216. let t1 = new Date(this.formData.startTime.replace(/-/g, '/')).getTime();
  217. let t2 = new Date(this.formData.endTime.replace(/-/g, '/')).getTime();
  218. this.formData.timeUsed = t2 - t1;
  219. // this.formData.timeUsed = new Date(this.formData.endTime).getTime() - new Date(this.formData.startTime).getTime();
  220. // console.log('formData',this.formData);
  221. // return
  222. this.$u.api.paperSubmit(this.formData).then(res=>{
  223. let queryParams = uni.$u.queryParams({result:JSON.stringify(res.data)});
  224. uni.reLaunch({url: '/examination/report'+queryParams});
  225. // console.log('paperSubmit',res.data);
  226. }).catch(err=>{
  227. console.log('paperSubmit',err);
  228. })
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. .topic-type{
  235. background: rgba(0,154,239,0.2);
  236. border-radius: 8rpx;
  237. font-size: 26rpx;
  238. font-weight: 400;
  239. color: #009AEF;
  240. line-height: 36rpx;
  241. padding: 5rpx 14rpx;
  242. }
  243. .info{
  244. .paper-name{
  245. font-size: 34rpx;
  246. font-weight: 600;
  247. color: #333333;
  248. line-height: 48rpx;
  249. margin-bottom: 42rpx;
  250. }
  251. .info-item{
  252. margin-bottom: 24rpx;
  253. .til{
  254. font-size: 32rpx;
  255. font-weight: 600;
  256. color: #333333;
  257. line-height: 44rpx;
  258. margin-bottom: 12rpx;
  259. }
  260. .con{
  261. font-size: 30rpx;
  262. font-weight: 400;
  263. color: #999999;
  264. line-height: 42rpx;
  265. }
  266. }
  267. }
  268. .bottom-btn-static{
  269. height: 98rpx;
  270. .bottom-btn-fixed{
  271. position: fixed;
  272. left: 0;
  273. right: 0;
  274. bottom: 0;
  275. .btn{
  276. text-align: center;
  277. height: 98rpx;
  278. line-height: 98rpx;
  279. background-color: $uni-color-primary;
  280. color: #fff;
  281. &.yellow{
  282. background-color: $uni-color-warning;
  283. }
  284. }
  285. .btns{
  286. .btn{
  287. flex: 1;
  288. }
  289. }
  290. }
  291. }
  292. .swiper-wrap{
  293. .swiper{
  294. min-height: calc( 100vh - 44px - 98rpx) ;
  295. background-color: #F5F9FC;
  296. .swiper-item{
  297. padding: 30rpx;
  298. font-size: 32rpx;
  299. font-weight: 400;
  300. color: #333333;
  301. line-height: 44rpx;
  302. }
  303. .question{
  304. font-size: 34rpx;
  305. font-weight: 600;
  306. line-height: 48rpx;
  307. margin-bottom: 40rpx;
  308. margin-top: 20rpx;
  309. }
  310. .choice{
  311. padding: 36rpx 40rpx;
  312. background-color: #fff;
  313. border-radius: 24rpx;
  314. margin-bottom: 20rpx;
  315. .sort{
  316. text-transform: uppercase;
  317. font-weight: 600;
  318. }
  319. .answer{
  320. padding-left: 18rpx;
  321. margin-left: 20rpx;
  322. border-left: 1px solid #ccc;
  323. flex: 1;
  324. }
  325. .status{
  326. width: 32rpx;
  327. height: 32rpx;
  328. background: #F5F9FC;
  329. border-radius: 50%;
  330. }
  331. &.selected{
  332. .status{
  333. background-color: #009AEF;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. </style>