examination.vue 9.1 KB

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