questionBank.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  1. <template>
  2. <view id="questionBank">
  3. <swiper class="swiper" :current="current" @change="swiperChange" :interval="interval">
  4. <swiper-item v-for="(bank,bankIndex) in questionList" :key="bankIndex">
  5. <view class="pageContent">
  6. <view class="pad_8 titBox" >
  7. <view class="firstLetter">
  8. <view class="leftLetters">
  9. <view class="btnType">
  10. <text v-if="bank.type==1">单选</text>
  11. <text v-if="bank.type==2">多选</text>
  12. <text v-if="bank.type==3">判断</text>
  13. <text v-if="bank.type==4">案例题</text>
  14. <text v-if="bank.type==5">简答题</text>
  15. </view>
  16. <text>{{bankIndex+1}}/{{questionList.length}}</text>
  17. </view>
  18. <view style="color: #666;font-size: 28rpx;">{{countdown(lastTime)}}</view>
  19. <view class="leftLetters"></view>
  20. </view>
  21. <view class="titles">
  22. <rich-text :nodes="bank.content"></rich-text>
  23. </view>
  24. </view>
  25. <view class="pad_8 titBox">
  26. <template v-if="bank.type == 1">
  27. <view v-if="!bank.ques">
  28. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty" @click="radioSelect(item.optionsId,bankIndex)">
  29. <view class="activeTI">{{ ast[index] }}</view>
  30. {{ item.content }}
  31. </view>
  32. </view>
  33. <view v-if="bank.ques">
  34. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty">
  35. <text :class="{right:(item.optionsId == bank.ques) || (item.optionsId == bank.ans),wrong:(item.optionsId == bank.ques) && (bank.ques != bank.ans)}" class="activeTI">{{ ast[index] }}</text>
  36. {{ item.content }}
  37. </view>
  38. </view>
  39. <view v-if="bank.ques">
  40. <view class="pad_8 answer">
  41. <view>正确答案:{{ast[bank.ans-1]}}</view>
  42. <view>我的答案:{{ast[bank.ques-1]}}</view>
  43. </view>
  44. <view class="pad_8 answerInfos">
  45. <view class="answerTitle">答案解析</view>
  46. <view class="answerContent">
  47. <rich-text :nodes="bank.analysisContent"></rich-text>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <template v-if="bank.type == 2">
  53. <view v-if="!bank.ques">
  54. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty" @click="checkboxSelect(item.optionsId,bankIndex,index)">
  55. <view :class="{checked:item.checked}" class="activeTI">{{ ast[index] }}</view>
  56. {{ item.content }}
  57. </view>
  58. </view>
  59. <view v-if="!bank.ques" class="submit_checkbox" @click="checkboxSubmit(bankIndex)">
  60. 确认答案
  61. </view>
  62. <view v-if="bank.ques">
  63. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty">
  64. <text :class="{right:(bank.ques.indexOf(item.optionsId) != -1 ) || (bank.ans.indexOf(item.optionsId) != -1),wrong:(bank.ques.indexOf(item.optionsId) != -1 ) && (bank.ans.indexOf(item.optionsId) == -1)}" class="activeTI">{{ ast[index] }}</text>
  65. {{ item.content }}
  66. </view>
  67. </view>
  68. <view v-if="bank.ques">
  69. <view class="pad_8 answer">
  70. <view>正确答案:
  71. <text v-for="ansItem in bank.ans">{{ast[ansItem-1]}}</text>
  72. </view>
  73. <view>我的答案:
  74. <text v-for="quesItem in bank.ques">{{ast[quesItem-1]}}</text>
  75. </view>
  76. </view>
  77. <view class="pad_8 answerInfos">
  78. <view class="answerTitle">答案解析</view>
  79. <view class="answerContent">
  80. <rich-text :nodes="bank.analysisContent"></rich-text>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <template v-if="bank.type == 3">
  86. <view v-if="!bank.ques">
  87. <view v-for="(item, index) in judge" :key="index" class="lisSty" @click="judgeSelect(index,bankIndex)">
  88. <view class="activeTI">{{ ast[index] }}</view>
  89. {{ item }}
  90. </view>
  91. </view>
  92. <view v-if="bank.ques">
  93. <view v-for="(item, index) in judge" :key="index" class="lisSty">
  94. <text :class="{right:(index == bank.ques) || (index == bank.ans),wrong:(index == bank.ques) && (bank.ques != bank.ans)}" class="activeTI">{{ ast[index] }}</text>
  95. {{ item }}
  96. </view>
  97. </view>
  98. <view v-if="bank.ques">
  99. <view class="pad_8 answer">
  100. <view>正确答案:{{ast[bank.ans]}}</view>
  101. <view>我的答案:{{ast[bank.ques]}}</view>
  102. </view>
  103. <view class="pad_8 answerInfos">
  104. <view class="answerTitle">答案解析</view>
  105. <view class="answerContent">
  106. <rich-text :nodes="bank.analysisContent"></rich-text>
  107. </view>
  108. </view>
  109. </view>
  110. </template>
  111. <!-- 简答题 -->
  112. <template v-if="bank.type == 5">
  113. <view class="ans">
  114. <view class="ans_input" v-if="!bank.ques">
  115. <view class="top flex">
  116. <image :data-index="bankIndex" class="icon" @click="chooseImg(bankIndex)" src="/static/08-10_032.jpg" mode=""></image>
  117. <view class="progress">0/4</view>
  118. <view class="submit" @click="submitAns(bankIndex)" >确认答案</view>
  119. </view>
  120. <view class="textarea">
  121. <textarea v-model="bank.ansText.text" placeholder="在此输入答案"></textarea>
  122. </view>
  123. <view class="imgs">
  124. <view class="img" v-for="(img,imgIndex) in bank.ansText.imageList" >
  125. <text @click="deleteImg(imgIndex,bankIndex)">x</text>
  126. <image :src="$method.splitImgHost(img, true)"></image>
  127. </view>
  128. </view>
  129. </view>
  130. <view class="ans_submit answerInfos" v-if="bank.ques">
  131. <view class="answerTitle">答案我的</view>
  132. {{bank.ques.text}}
  133. <view class="imgs">
  134. <image class="img" v-for="ques in bank.ques.imageList" :src="ques"></image>
  135. </view>
  136. </view>
  137. </view>
  138. <view v-if="bank.ques">
  139. <view class="pad_8 answerInfos">
  140. <view class="answerTitle">答案解析</view>
  141. <view class="answerContent">
  142. <rich-text :nodes="bank.analysisContent"></rich-text>
  143. </view>
  144. </view>
  145. </view>
  146. </template>
  147. <!-- 案例题 -->
  148. <template v-if="bank.type == 4">
  149. <view class="tabs">
  150. <view class="tab" :class="{current:tabIndex == bank.current}" :key="tabIndex" v-for="(tab,tabIndex) in bank.jsonStr" @click="tabSelect(tabIndex,bankIndex)">问题{{tabIndex}}</view>
  151. </view>
  152. <view v-for="(ansItem,ansIndex) in bank.jsonStr" v-if="bank.current == ansIndex" :key="ansIndex">
  153. <view class="titles">
  154. <rich-text :nodes="ansItem.content"></rich-text>
  155. </view>
  156. <template v-if="ansItem.type == 1">
  157. <view v-if="!bank.ques[ansIndex]">
  158. <view v-for="(option, childIndex) in ansItem.optionsList" :key="childIndex" class="lisSty" @click="radioSelectChild(option.optionsId,ansIndex,bankIndex)">
  159. <view class="activeTI">{{ ast[childIndex] }}</view>
  160. <rich-text class="textChild" :nodes="option.content"></rich-text>
  161. </view>
  162. </view>
  163. <view v-if="bank.ques[ansIndex]">
  164. <view v-for="(option, childIndex) in ansItem.optionsList" :key="index" class="lisSty">
  165. <text :class="{right:(option.optionsId == bank.ques[ansIndex]) || (option.optionsId == bank.ans[ansIndex]),wrong:(option.optionsId == bank.ques[ansIndex]) && (bank.ques[ansIndex] != bank.ans[ansIndex])}" class="activeTI">{{ ast[childIndex] }}</text>
  166. <rich-text :nodes="option.content"></rich-text>
  167. </view>
  168. </view>
  169. <view v-if="bank.ques[ansIndex]">
  170. <view class="pad_8 answer">
  171. <view>正确答案:{{ast[bank.ans[ansIndex]-1]}}</view>
  172. <view>我的答案:{{ast[bank.ques[ansIndex]-1]}}</view>
  173. </view>
  174. <view class="pad_8 answerInfos">
  175. <view class="answerTitle">答案解析</view>
  176. <view class="answerContent">
  177. <rich-text :nodes="option.analysisContent"></rich-text>
  178. </view>
  179. </view>
  180. </view>
  181. </template>
  182. <template v-if="ansItem.type == 2">
  183. <view v-if="!bank.ques[ansIndex]">
  184. <view v-for="(option, childindex) in ansItem.optionsList" :key="childindex" class="lisSty" @click="checkboxSelectChild(bankIndex,ansIndex,childindex)">
  185. <view :class="{checked:option.checked}" class="activeTI">{{ ast[childindex] }}</view>
  186. <rich-text :nodes="option.content"></rich-text>
  187. </view>
  188. </view>
  189. <view v-if="!bank.ques[ansIndex]" class="submit_checkbox" @click="checkboxSubmitChild(bankIndex,ansIndex)">
  190. 确认答案
  191. </view>
  192. <view v-if="bank.ques && bank.ques[ansIndex]">
  193. <view v-for="(option, childindex) in ansItem.optionsList" :key="childindex" class="lisSty">
  194. <text :class="{right:right(bankIndex,ansIndex,option),wrong:wrong(bankIndex,ansIndex,option)}" class="activeTI">{{ ast[childindex] }}</text>
  195. <rich-text :nodes="option.content"></rich-text>
  196. </view>
  197. </view>
  198. <view v-if="bank.ques[ansIndex]">
  199. <view class="pad_8 answer">
  200. <view>正确答案:
  201. <text v-for="ansItem1 in bank.ans[ansIndex]">{{ast[ansItem1-1]}}</text>
  202. </view>
  203. <view>我的答案:
  204. <text v-for="quesItem in bank.ques[ansIndex]">{{ast[quesItem-1]}}</text>
  205. </view>
  206. </view>
  207. <view class="pad_8 answerInfos">
  208. <view class="answerTitle">答案解析</view>
  209. <view class="answerContent">
  210. <rich-text :nodes="ansItem.analysisContent"></rich-text>
  211. </view>
  212. </view>
  213. </view>
  214. </template>
  215. <template v-if="ansItem.type == 3">
  216. <view v-if="!bank.ques[ansIndex]">
  217. <view v-for="(option, childindex) in judge" :key="childindex" class="lisSty" @click="judgeSelectChild(ansIndex,childindex,bankIndex)">
  218. <view class="activeTI">{{ ast[childindex] }}</view>
  219. {{ option }}
  220. </view>
  221. </view>
  222. <view v-if="bank.ques[ansIndex]">
  223. <view v-for="(option, childindex) in judge" :key="childindex" class="lisSty">
  224. <text :class="{right:(childindex == bank.ques[ansIndex]) || (childindex == bank.ans[ansIndex]),wrong:(childindex == bank.ques[ansIndex]) && (bank.ques[ansIndex] != bank.ans[ansIndex])}" class="activeTI">{{ ast[childindex] }}</text>
  225. {{ option }}
  226. </view>
  227. </view>
  228. <view v-if="bank.ques[ansIndex]">
  229. <view class="pad_8 answer">
  230. <view>正确答案:{{ast[bank.ans[ansIndex]]}}</view>
  231. <view>我的答案:{{ast[bank.ques[ansIndex]]}}</view>
  232. </view>
  233. <view class="pad_8 answerInfos">
  234. <view class="answerTitle">答案解析</view>
  235. <view class="answerContent">
  236. <rich-text :nodes="ansItem.analysisContent"></rich-text>
  237. </view>
  238. </view>
  239. </view>
  240. </template>
  241. <!-- 简答题 -->
  242. <template v-if="ansItem.type == 5">
  243. <view class="ans">
  244. <view class="ans_input" v-if="!bank.ques[ansIndex]">
  245. <view class="top flex">
  246. <image class="icon" @click="chooseImgChild(bankIndex,ansIndex)" src="/static/08-10_032.jpg" mode=""></image>
  247. <view class="progress">0/4</view>
  248. <view class="submit" @click="submitAnsChild(bankIndex,ansIndex)">确认答案</view>
  249. </view>
  250. <view class="textarea">
  251. <textarea v-model="ansItem.ansText.text" placeholder="在此输入答案"></textarea>
  252. </view>
  253. <view class="imgs">
  254. <view class="img" v-for="(img,imgIndex) in ansItem.ansText.imageList" >
  255. <text @click="deleteImgChild(imgIndex,bankIndex,ansIndex)">x</text>
  256. <image :src="$method.splitImgHost(img, true)"></image>
  257. </view>
  258. </view>
  259. </view>
  260. <view class="ans_submit answerInfos" v-if="bank.ques[ansIndex]">
  261. <view class="answerTitle">答案我的</view>
  262. {{bank.ques[ansIndex].text}}
  263. <view class="imgs">
  264. <image class="img" v-for="ques in bank.ques[ansIndex].imageList" :src="ques"></image>
  265. </view>
  266. </view>
  267. </view>
  268. <view v-if="bank.ques[ansIndex]">
  269. <view class="pad_8 answerInfos">
  270. <view class="answerTitle">答案解析</view>
  271. <view class="answerContent">
  272. <rich-text :nodes="ansItem.analysisContent"></rich-text>
  273. </view>
  274. </view>
  275. </view>
  276. </template>
  277. </view>
  278. </template>
  279. </view>
  280. <view class="footer_btn">
  281. <view class="collect" :class="{show:goodsId?true:false}" @click="collect(collectList[bankIndex],bankIndex)">{{collectList[bankIndex] ?'已收藏' : '未收藏' }}</view>
  282. <view @click="openFooterTab">答题卡</view>
  283. <view @click="submit">交卷</view>
  284. </view>
  285. </view>
  286. </swiper-item>
  287. </swiper>
  288. <u-popup v-model="show" mode="bottom" border-radius="14" height="680rpx">
  289. <view class="popupView">
  290. <view class="popupTops">
  291. <view class="topIcon"></view>
  292. 点击编号即可跳转至对应题目
  293. </view>
  294. <view class="popupContent">
  295. <scroll-view scroll-y="true" style="height: 506rpx;">
  296. <view class="boxSty">
  297. <view v-for="(item, index) in questionList" :key="index" @click="changeIndex(index)" :class="{isRight:isRight(item,index),isWrong:isWrong(item,index)}" class="liListSty">{{ index + 1 }}</view>
  298. </view>
  299. </scroll-view>
  300. </view>
  301. </view>
  302. </u-popup>
  303. <view class="dialog" v-if="showDialog">
  304. <view class="text">左右滑动切换上下题</view>
  305. <view class="btn" @click="hideDialog">我知道了</view>
  306. </view>
  307. </view>
  308. </template>
  309. <script>
  310. export default {
  311. data() {
  312. return {
  313. id:'',
  314. current:0,
  315. questionList:[],
  316. ast: ['A', 'B', 'C', 'D','E','F','G'],
  317. judge:['错误','正确'],
  318. ans:[],
  319. ques:[],
  320. show: false,
  321. showDialog:true,
  322. bankList: [],
  323. collectList:[],
  324. goodsId:'',
  325. recordId:'',
  326. isSubmit:false,
  327. lastTime:0,
  328. timer :null
  329. };
  330. },
  331. onLoad(option){
  332. this.id = option.id;
  333. this.goodsId = option.goodsid;
  334. this.goodsQuestionList();
  335. },
  336. onUnload() {
  337. console.log(this.ans)
  338. this.examRecordEdit();
  339. },
  340. methods: {
  341. examRecordEdit() {
  342. if(!this.isSubmit) {
  343. let number = 0;
  344. this.questionList.forEach((item,index) => {
  345. if(item.type == 1) {
  346. if(item.ques == item.ans) {
  347. score += item.score;
  348. number++
  349. }
  350. } else if(item.type == 2) {
  351. let isRight = item.ques && item.ques.every((quesItem,quesIndex) => {
  352. return item.ques[quesIndex] == item.ans[quesIndex]
  353. })
  354. if(isRight) {
  355. score += item.score;
  356. number++
  357. }
  358. } else if(item.type == 3) {
  359. if(item.ques == item.ans) {
  360. score += item.score;
  361. number++
  362. }
  363. }
  364. })
  365. this.$api.examRecordEdit({
  366. examId:this.id,
  367. goodsId:this.goodsId,
  368. recordId: this.recordId,
  369. rightQuestionNum:number,
  370. status:0,
  371. historyExamJson:JSON.stringify({ans:this.ans,ques:this.ques})
  372. }).then(res => {
  373. })
  374. }
  375. },
  376. examRecord() {
  377. this.$api.examRecord({
  378. examId:this.id,
  379. goodsId:this.goodsId,
  380. totalQuestionNum:this.questionList.length,
  381. }).then(res => {
  382. this.recordId = res.data.data;
  383. })
  384. },
  385. countdown(second) {
  386. if(second) {
  387. let h = parseInt(second/60/60 %24); // 计算小时
  388. let m = parseInt(second/60%60); // 计算分数
  389. let s = parseInt(second%60); // 计算当前秒数
  390. if(h < 10) h = '0'+h;
  391. if(m < 10) m = '0'+m;
  392. if(s < 10) s = '0'+s;
  393. return h+':'+m+':'+s
  394. } else {
  395. return '';
  396. }
  397. },
  398. goodsQuestionList() {
  399. this.$api.goodsQuestionList({
  400. examId:this.id
  401. }).then(res => {
  402. this.lastTime = res.data.data[0].answerTime && res.data.data[0].answerTime * 60;
  403. //考试
  404. if(this.lastTime) {
  405. this.timer = setInterval(()=>{
  406. if(this.lastTime <= 0) {
  407. clearInterval(this.timer)
  408. uni.showModal({
  409. title: '提示',
  410. content: '考试时间到,自动交卷',
  411. confirmText:'确定',
  412. showCancel:false,
  413. success: (res) => {
  414. this.submit();
  415. }
  416. });
  417. return;
  418. }
  419. this.lastTime --;
  420. },1000)
  421. } else {
  422. }
  423. res.data.data.forEach((item,index) => {
  424. if(typeof item.jsonStr == 'string') {
  425. item.jsonStr = JSON.parse(item.jsonStr)
  426. if(item.type == 2) { //多选
  427. item.jsonStr.forEach(str => {
  428. str.optionsId = ''+str.optionsId;
  429. })
  430. let arr = item.answerQuestion.split(',');
  431. arr.forEach((a,i) => {
  432. arr[i] = ''+a;
  433. })
  434. item.ans = arr;
  435. return;
  436. } else if(item.type == 5) {
  437. item.ansText = {
  438. text: '',
  439. imageList: []
  440. }
  441. } else if(item.type == 4) {
  442. console.log(item.jsonStr)
  443. item.ques = []
  444. item.current = 0;
  445. let ansArr = [];
  446. item.jsonStr.forEach((json,index) => {
  447. if(json.type == 1) {
  448. ansArr[index] = json.answerQuestion;
  449. } else if(json.type == 2) {
  450. json.optionsList.forEach(str => {
  451. str.optionsId = ''+str.optionsId;
  452. })
  453. let arr = json.answerQuestion.split(',');
  454. arr.forEach((a,i) => {
  455. arr[i] = ''+a;
  456. })
  457. ansArr[index] = arr
  458. } else if(json.type == 3) {
  459. ansArr[index] = json.answerQuestion;
  460. } else if(json.type == 5) {
  461. ansArr[index] = {
  462. text: '',
  463. imageList: []
  464. }
  465. json.ansText = {
  466. text: '',
  467. imageList: []
  468. }
  469. }
  470. })
  471. item.ans = ansArr
  472. return;
  473. }
  474. item.ans = item.answerQuestion
  475. }
  476. })
  477. this.questionList = res.data.data;
  478. this.examRecord()
  479. this.getCollectInfo(this.current)
  480. })
  481. },
  482. /**
  483. * @param {Object} e单选点击
  484. */
  485. radioSelect(optionsId,bindex) {
  486. if(this.questionList[bindex].ques) return;
  487. this.$set(this.questionList[bindex],'ques',optionsId)
  488. if(this.questionList[bindex].ques != this.questionList[bindex].ans) {
  489. this.$api.examWrongRecord({
  490. "examId": this.id,
  491. "goodsId": this.goodsId,
  492. "questionId": this.questionList[bindex].questionId,
  493. "recordId": this.recordId,
  494. }).then(res => {
  495. })
  496. } else {
  497. }
  498. },
  499. /**
  500. * @param {Object} e单选点击
  501. */
  502. radioSelectChild(optionsId,ansIndex,bindex) {
  503. if(this.questionList[bindex].ques[ansIndex]) return;
  504. this.$set(this.questionList[bindex].ques,ansIndex,optionsId)
  505. },
  506. /**
  507. * @param {Object} 多选点击
  508. */
  509. checkboxSelect(optionsId,bindex,index) {
  510. this.$set(this.questionList[bindex].jsonStr[index],'checked',!this.questionList[bindex].jsonStr[index].checked)
  511. },
  512. /**
  513. * @param {Object} 多选点击
  514. */
  515. checkboxSelectChild(bindex,ansIndex,childIndex) {
  516. this.$set(this.questionList[bindex].jsonStr[ansIndex].optionsList[childIndex],'checked',!this.questionList[bindex].jsonStr[ansIndex].optionsList[childIndex].checked)
  517. },
  518. /**
  519. * @param {Object} 多选确认
  520. */
  521. checkboxSubmit(bindex) {
  522. if(this.questionList[bindex].ques) return;
  523. let arr = [];
  524. this.questionList[bindex].jsonStr.forEach(item => {
  525. if(item.checked) {
  526. arr.push(item.optionsId)
  527. }
  528. })
  529. this.$set(this.questionList[bindex],'ques',arr)
  530. let isWrong = this.questionList[bindex].ques.some((quesItem,quesIndex) => {
  531. return this.questionList[bindex].ques[quesIndex] != this.questionList[bindex].ans[quesIndex]
  532. })
  533. if(isWrong) {
  534. this.$api.examWrongRecord({
  535. "examId": this.id,
  536. "goodsId": this.goodsId,
  537. "questionId": this.questionList[bindex].questionId,
  538. "recordId": this.recordId,
  539. }).then(res => {
  540. })
  541. }
  542. },
  543. /**
  544. * @param {Object} 多选确认
  545. */
  546. checkboxSubmitChild(bindex,ansIndex) {
  547. if(this.questionList[bindex].ques[ansIndex]) return;
  548. let arr = [];
  549. this.questionList[bindex].jsonStr[ansIndex].optionsList.forEach(item => {
  550. if(item.checked) {
  551. arr.push(item.optionsId)
  552. }
  553. })
  554. this.$set(this.questionList[bindex].ques,ansIndex,arr)
  555. },
  556. judgeSelect(index,bindex) {
  557. if(this.questionList[bindex].ques) return;
  558. this.$set(this.questionList[bindex],'ques',index+'')
  559. if(this.questionList[bindex].ques != this.questionList[bindex].ans) {
  560. this.$api.examWrongRecord({
  561. "examId": this.id,
  562. "goodsId": this.goodsId,
  563. "questionId": this.questionList[bindex].questionId,
  564. "recordId": this.recordId,
  565. }).then(res => {
  566. })
  567. }
  568. },
  569. judgeSelectChild(ansindex,childindex,bindex) {
  570. if(this.questionList[bindex].ques[ansindex]) return;
  571. this.$set(this.questionList[bindex].ques,ansindex,childindex+'')
  572. },
  573. openFooterTab() {
  574. this.show = true;
  575. },
  576. hideDialog() {
  577. this.showDialog = false
  578. },
  579. changeIndex(index) {
  580. this.current = index
  581. },
  582. swiperChange(e) {
  583. this.current = e.detail.current;
  584. this.getCollectInfo(this.current)
  585. },
  586. getCollectInfo(current) {
  587. this.$api.getCollectInfo({
  588. examId:this.id,
  589. questionId:this.questionList[current].questionId,
  590. goodsId:this.goodsId,
  591. }).then(res => {
  592. if(res.data.code == 500) {
  593. this.$set(this.collectList,current,false)
  594. } else if(res.data.code == 200) {
  595. this.$set(this.collectList,current,res.data.data)
  596. }
  597. })
  598. },
  599. submit() {
  600. let score = 0; //计算总分
  601. let reportStatus = 0;
  602. let number = 0;
  603. this.questionList.forEach((item,index) => {
  604. if(item.type == 1) {
  605. if(item.ques == item.ans) {
  606. score += item.score;
  607. number++
  608. }
  609. } else if(item.type == 2) {
  610. let isRight = item.ques && item.ques.every((quesItem,quesIndex) => {
  611. return item.ques[quesIndex] == item.ans[quesIndex]
  612. })
  613. if(isRight) {
  614. score += item.score;
  615. number++
  616. }
  617. } else if(item.type == 3) {
  618. if(item.ques == item.ans) {
  619. score += item.score;
  620. number++
  621. }
  622. }
  623. })
  624. // if(score >= 60) {
  625. // reportStatus = 1
  626. // } else {
  627. // reportStatus = 0
  628. // }
  629. this.$api.examRecordEdit({
  630. examId:this.id,
  631. goodsId:this.goodsId,
  632. // reportStatus:reportStatus,
  633. recordId: this.recordId,
  634. rightQuestionNum:number,
  635. status:1,
  636. score:score,
  637. historyExamJson:JSON.stringify(this.questionList)
  638. }).then(res => {
  639. this.isSubmit = true;
  640. if(res.data.code == 200) {
  641. uni.showToast({
  642. title: '交卷成功',
  643. duration: 2000,
  644. icon:'none'
  645. });
  646. setTimeout(() => {
  647. uni.navigateBack({
  648. delta: 1
  649. });
  650. },2000)
  651. }
  652. })
  653. },
  654. collect(state,index) {
  655. if(!state) {
  656. this.$api.collectQuestion({
  657. examId:this.id,
  658. questionId:this.questionList[index].questionId,
  659. goodsId:this.goodsId || '',
  660. }).then(res => {
  661. if(res.data.code==200){
  662. this.$set(this.collectList,index,true)
  663. uni.showToast({
  664. title: '收藏成功',
  665. duration: 2000,
  666. icon:'none'
  667. });
  668. }
  669. })
  670. } else {
  671. this.$api.deleteCollectQuestion(this.collectList[index].collectQuestionId).then(res => {
  672. if(res.data.code==200){
  673. this.$set(this.collectList,index,false)
  674. uni.showToast({
  675. title: '取消收藏成功',
  676. duration: 2000,
  677. icon:'none'
  678. });
  679. }
  680. })
  681. }
  682. return;
  683. },
  684. click(e) {
  685. if(this.ques[this.current]) return;
  686. let value = e.currentTarget.dataset.value;
  687. this.ques[this.current] = value;
  688. this.ques = Object.assign({},this.ques)
  689. },
  690. deleteImg(imgIndex,bankIndex) {
  691. this.questionList[bankIndex].ansText.imageList.splice(imgIndex,1)
  692. },
  693. deleteImgChild(imgIndex,bankIndex,ansIndex) {
  694. this.questionList[bankIndex].jsonStr[ansIndex].ansText.imageList.splice(imgIndex,1)
  695. },
  696. chooseImg(bankindex) {
  697. uni.chooseImage({
  698. count: 1, //默认9
  699. sizeType: ['compressed', ], //可以指定是原图还是压缩图,默认二者都有
  700. sourceType: ['album','camera'], //从相册选择
  701. success: (res) => {
  702. let self = this;
  703. // console.log(JSON.stringify(res.tempFilePaths));
  704. let img = res.tempFilePaths[0];
  705. uni.getImageInfo({
  706. src: img,
  707. success: async res => {
  708. let canvasWidth = res.width; //图片原始长宽
  709. let canvasHeight = res.height;
  710. if (canvasWidth > 1000 || canvasHeight > 1000) {
  711. uni.compressImage({
  712. src: img,
  713. quality: 75,
  714. width: '50%',
  715. height: '50%',
  716. success: async rest => {
  717. const dir = await self.uploadFile(rest.tempFilePath, 0);
  718. this.questionList[bankindex].ansText.imageList.push(dir)
  719. }
  720. });
  721. } else {
  722. const dir = await self.uploadFile(img, 0);
  723. this.questionList[bankindex].ansText.imageList.push(dir)
  724. }
  725. }
  726. });
  727. }
  728. })
  729. },
  730. chooseImgChild(bankindex,ansindex) {
  731. uni.chooseImage({
  732. count: 1, //默认9
  733. sizeType: ['compressed', ], //可以指定是原图还是压缩图,默认二者都有
  734. sourceType: ['album','camera'], //从相册选择
  735. success: (res) => {
  736. let self = this;
  737. // console.log(JSON.stringify(res.tempFilePaths));
  738. let img = res.tempFilePaths[0];
  739. uni.getImageInfo({
  740. src: img,
  741. success: async res => {
  742. let canvasWidth = res.width; //图片原始长宽
  743. let canvasHeight = res.height;
  744. if (canvasWidth > 1000 || canvasHeight > 1000) {
  745. uni.compressImage({
  746. src: img,
  747. quality: 75,
  748. width: '50%',
  749. height: '50%',
  750. success: async rest => {
  751. const dir = await self.uploadFile(rest.tempFilePath, 0);
  752. this.questionList[bankindex].jsonStr[ansindex].ansText.imageList.push(dir)
  753. }
  754. });
  755. } else {
  756. const dir = await self.uploadFile(img, 0);
  757. this.questionList[bankindex].jsonStr[ansindex].ansText.imageList.push(dir)
  758. }
  759. }
  760. });
  761. }
  762. })
  763. },
  764. uploadFile(options, int) {
  765. var self = this;
  766. return new Promise((resolve, reject) => {
  767. var data = {
  768. imageStatus: int
  769. };
  770. self.$api.aliyunpolicy(data).then(res => {
  771. console.log(res.data,6)
  772. if(res.data.code!=200){
  773. self.$method.showToast('签名错误'+JSON.stringify(res.data))
  774. return
  775. }
  776. var ossToken = res.data.data.resultContent;
  777. if(ossToken.host==null||ossToken.host==undefined){
  778. self.$method.showToast('上传路径报错'+JSON.stringify(res.data))
  779. return
  780. }
  781. uni.uploadFile({
  782. url: ossToken.host,
  783. name: 'file',
  784. filePath: options,
  785. fileType: 'image',
  786. header: {
  787. AuthorizationToken: 'WX ' + uni.getStorageSync('token')
  788. },
  789. formData: {
  790. key: ossToken.dir,
  791. OSSAccessKeyId: ossToken.accessid,
  792. policy: ossToken.policy,
  793. Signature: ossToken.signature,
  794. callback: ossToken.callback,
  795. success_action_status: 200
  796. },
  797. success: result => {
  798. if (result.statusCode === 200) {
  799. resolve(ossToken.dir);
  800. } else {
  801. uni.showToast({
  802. title: '上传失败',
  803. icon: 'none'
  804. });
  805. return;
  806. }
  807. },
  808. fail: error => {
  809. uni.showToast({
  810. title: '上传接口报错'+error,
  811. icon: 'none'
  812. });
  813. return;
  814. }
  815. });
  816. });
  817. });
  818. },
  819. submitAns(type,bankindex) {
  820. console.log(this.questionList[bankindex])
  821. if(!this.questionList[bankindex].ansText.text && !this.questionList[bankindex].ansText.imageList.length) {
  822. uni.showToast({
  823. title: '请输入内容或上传图片',
  824. duration: 2000,
  825. icon:'none'
  826. });
  827. return
  828. }
  829. this.$set(this.ques,bankindex,{
  830. imageList:this.questionList[bankindex].ansText.imageList,
  831. text:this.questionList[bankindex].ansText.text,
  832. })
  833. },
  834. submitAnsChild(bankindex,ansindex) {
  835. if(!this.questionList[bankindex].jsonStr[ansindex].ansText.text && !this.questionList[bankindex].jsonStr[ansindex].ansText.imageList.length) {
  836. uni.showToast({
  837. title: '请输入内容或上传图片',
  838. duration: 2000,
  839. icon:'none'
  840. });
  841. return
  842. }
  843. this.$set(this.questionList[bankindex].ques,ansindex,{
  844. imageList:this.questionList[bankindex].jsonStr[ansindex].ansText.imageList,
  845. text:this.questionList[bankindex].jsonStr[ansindex].ansText.text,
  846. })
  847. },
  848. isRight(item,index) {
  849. //单选
  850. if(this.questionList[index].ques) {
  851. if(item.type == 1) {
  852. return this.questionList[index].ques == this.questionList[index].ans;
  853. //多选
  854. } else if(item.type == 2) {
  855. //每一项都相等
  856. return this.questionList[index].ques.every((item,index) => {
  857. return item == this.questionList[index].ans;
  858. })
  859. //判断
  860. } else if(item.type == 3) {
  861. return this.questionList[index].ques == this.questionList[index].ans;
  862. } else {
  863. return false;
  864. }
  865. } else {
  866. return false;
  867. }
  868. },
  869. right(bankIndex,ansIndex,option) {
  870. if(this.questionList[bankIndex].ques[ansIndex] && this.questionList[bankIndex].ans[ansIndex]) {
  871. if((this.questionList[bankIndex].ques[ansIndex].indexOf(option.optionsId) != -1 ) || (this.questionList[bankIndex].ans[ansIndex].indexOf(option.optionsId) != -1)) {
  872. return true
  873. } else {
  874. return false;
  875. }
  876. } else {
  877. return false;
  878. }
  879. },
  880. wrong(bankIndex,ansIndex,option) {
  881. if(this.questionList[bankIndex].ques[ansIndex] && this.questionList[bankIndex].ans[ansIndex]) {
  882. if((this.questionList[bankIndex].ques[ansIndex].indexOf(option.optionsId) != -1 ) && (this.questionList[bankIndex].ans[ansIndex].indexOf(option.optionsId) == -1)) {
  883. return true;
  884. } else {
  885. return false;
  886. }
  887. } else {
  888. return false;
  889. }
  890. },
  891. isWrong(item,index) {
  892. if(this.questionList[index].ques) {
  893. //单选
  894. if(item.type == 1) {
  895. return this.questionList[index].ques != this.questionList[index].ans;
  896. //多选
  897. } else if(item.type == 2) {
  898. //每一项都相等
  899. return this.questionList[index].ques.some((item,index) => {
  900. return item != this.questionList[index].ans;
  901. })
  902. //判断
  903. } else if(item.type == 3) {
  904. return this.questionList[index].ques != this.questionList[index].ans;
  905. } else {
  906. return false;
  907. }
  908. } else {
  909. return false;
  910. }
  911. },
  912. tabSelect(index,bankindex) {
  913. this.$set(this.questionList[bankindex],'current',index)
  914. },
  915. collectQuestion() {
  916. this.$api.collectQuestion({
  917. examId:this.id
  918. }).then(res => {
  919. if(res.data.code==200){
  920. uni.showToast({
  921. title: '收藏成功',
  922. duration: 2000,
  923. icon:'none'
  924. });
  925. }
  926. })
  927. }
  928. }
  929. };
  930. </script>
  931. <style lang="scss" scoped>
  932. .swiper {
  933. width:100%;
  934. height:100vh;
  935. }
  936. .lisSty {
  937. margin-bottom: 16rpx;
  938. display: flex;
  939. }
  940. .activeTI {
  941. vertical-align: middle;
  942. display: inline-block;
  943. border: 1rpx solid #eee;
  944. border-radius: 50rpx;
  945. height: 48rpx;
  946. line-height: 46rpx;
  947. text-align: center;
  948. width: 48rpx;
  949. margin-right: 15rpx;
  950. color: #666;
  951. font-size: 30rpx;
  952. &.right {
  953. color:#fff;
  954. background:green;
  955. }
  956. &.wrong {
  957. color:#fff;
  958. background:red;
  959. }
  960. &.checked {
  961. color:#fff;
  962. background:blue;
  963. }
  964. }
  965. .submit_checkbox {
  966. margin:20rpx auto;
  967. width: 526rpx;
  968. height: 80rpx;
  969. background: rgba(0, 122, 255, 1);
  970. color:#fff;
  971. text-align: center;
  972. line-height: 80rpx;
  973. font-size: 30rpx;
  974. border-radius: 40rpx;
  975. }
  976. .titles {
  977. overflow: hidden;
  978. margin-bottom: 24rpx;
  979. }
  980. .titBox {
  981. padding: 41rpx 25rpx 24rpx 25rpx;
  982. }
  983. .tabs {
  984. margin:10rpx;
  985. display: flex;
  986. .tab {
  987. margin:0 10rpx;
  988. width: 96rpx;
  989. height: 48rpx;
  990. line-height: 48rpx;
  991. text-align: center;
  992. color:#007AFF;
  993. font-size: 28rpx;
  994. border-radius: 16rpx;
  995. &.current {
  996. color:#fff;
  997. background: #007AFF;
  998. }
  999. }
  1000. }
  1001. .ans {
  1002. margin:8rpx 8rpx 8rpx;
  1003. .ans_input {
  1004. border-radius: 16rpx;
  1005. background:#fff;
  1006. .top {
  1007. border-bottom:1rpx solid #EEEEEE;
  1008. padding: 16rpx;
  1009. display: flex;
  1010. align-items: center;
  1011. .icon {
  1012. margin-right:20rpx;
  1013. width: 40rpx;
  1014. height: 38rpx;
  1015. }
  1016. .progress {
  1017. flex:1;
  1018. }
  1019. .submit {
  1020. width: 168rpx;
  1021. height: 48rpx;
  1022. line-height: 48rpx;
  1023. text-align: center;
  1024. color:#fff;
  1025. font-size: 30rpx;
  1026. background: #007AFF;
  1027. border-radius: 24rpx;
  1028. }
  1029. }
  1030. .textarea {
  1031. textarea {
  1032. width:100%;
  1033. height:287rpx;
  1034. padding:10rpx;
  1035. }
  1036. }
  1037. .imgs {
  1038. overflow: hidden;
  1039. display: flex;
  1040. width:100%;
  1041. .img {
  1042. width: 104rpx;
  1043. height: 104rpx;
  1044. border-radius: 8rpx;
  1045. position:relative;
  1046. margin:20rpx;
  1047. text {
  1048. position:absolute;
  1049. right:-15rpx;
  1050. top:-15rpx;
  1051. width:30rpx;
  1052. height:30rpx;
  1053. text-align: center;
  1054. line-height: 30rpx;
  1055. color:#fff;
  1056. background:red;
  1057. border-radius:50%;
  1058. }
  1059. image {
  1060. width:100%;
  1061. height:100%;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. .ans_submit {
  1067. padding:16rpx;
  1068. border-radius: 16rpx;
  1069. background:#fff;
  1070. .imgs {
  1071. overflow: hidden;
  1072. display: flex;
  1073. width:100%;
  1074. .img {
  1075. width: 104rpx;
  1076. height: 104rpx;
  1077. border-radius: 8rpx;
  1078. position:relative;
  1079. margin:20rpx;
  1080. image {
  1081. width:100%;
  1082. height:100%;
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. .firstLetter {
  1089. display: flex;
  1090. justify-content: space-between;
  1091. align-items: center;
  1092. margin-bottom: 30rpx;
  1093. .leftLetters {
  1094. display: flex;
  1095. align-items: center;
  1096. width: 220rpx;
  1097. .btnType {
  1098. padding: 5rpx 10rpx;
  1099. border: 1rpx solid #007aff;
  1100. border-radius: 10rpx;
  1101. background-color: rgba(0, 122, 255, 0.1);
  1102. font-size: 28rpx;
  1103. color: #007aff;
  1104. margin-right: 15rpx;
  1105. }
  1106. }
  1107. }
  1108. .popupView {
  1109. height: 100%;
  1110. padding-bottom: 100rpx;
  1111. .popupTops {
  1112. height: 77rpx;
  1113. border-bottom: 1rpx solid #eee;
  1114. text-align: center;
  1115. line-height: 77rpx;
  1116. font-size: 24rpx;
  1117. color: #999;
  1118. position: relative;
  1119. .topIcon {
  1120. position: absolute;
  1121. top: 10rpx;
  1122. left: 50%;
  1123. transform: translateX(-50%);
  1124. width: 80rpx;
  1125. height: 8rpx;
  1126. background-color: #999;
  1127. border-radius: 4rpx;
  1128. }
  1129. }
  1130. .popupContent {
  1131. }
  1132. }
  1133. .pageContent {
  1134. position:relative;
  1135. background-color: #eaeef1;
  1136. min-height: 100vh;
  1137. padding-top: 8rpx;
  1138. padding-bottom: 100rpx;
  1139. }
  1140. .pad_8 {
  1141. background-color: #fff;
  1142. margin: 0rpx 8rpx 8rpx;
  1143. border-radius: 16rpx;
  1144. }
  1145. .answer {
  1146. height: 80rpx;
  1147. line-height: 80rpx;
  1148. padding: 0rpx 24rpx;
  1149. display: flex;
  1150. align-items: center;
  1151. justify-content: space-between;
  1152. color: #666;
  1153. font-size: 30rpx;
  1154. }
  1155. .footer_btn {
  1156. background-color: #fff;
  1157. z-index: 10078;
  1158. position: absolute;
  1159. bottom: 0rpx;
  1160. display: flex;
  1161. align-items: center;
  1162. justify-content: space-between;
  1163. width: 100%;
  1164. height: 98rpx;
  1165. padding: 0rpx 38rpx;
  1166. border-top: 1rpx solid #eee;
  1167. .collect {
  1168. visibility: hidden;
  1169. &.show {
  1170. visibility: visible;
  1171. }
  1172. }
  1173. }
  1174. .boxSty {
  1175. padding: 44rpx 41rpx 0rpx;
  1176. }
  1177. .liListSty {
  1178. border:1rpx solid #EEEEEE;
  1179. width: 88rpx;
  1180. height: 88rpx;
  1181. border-radius: 32rpx;
  1182. text-align: center;
  1183. line-height: 88rpx;
  1184. color: #333;
  1185. font-size: 32rpx;
  1186. float: left;
  1187. margin: 20rpx 23rpx;
  1188. &.isRight {
  1189. border:1rpx solid #EEEEEE;
  1190. color:#fff;
  1191. background: green;
  1192. }
  1193. &.isWrong {
  1194. border:1rpx solid #EEEEEE;
  1195. color:#fff;
  1196. background: red;
  1197. }
  1198. }
  1199. .answerInfos {
  1200. padding: 25rpx 25rpx 25rpx 23rpx;
  1201. }
  1202. .answerTitle {
  1203. margin-bottom: 28rpx;
  1204. color: #666;
  1205. font-size: 30rpx;
  1206. }
  1207. .answerContent {
  1208. font-size: 30rpx;
  1209. color: #666;
  1210. }
  1211. .textChild {
  1212. display: inline-block;
  1213. vertical-align: middle;
  1214. }
  1215. .dialog {
  1216. position: fixed;
  1217. left:0;
  1218. top:0;
  1219. width:100%;
  1220. height:100%;
  1221. background-color: rgba(0,0,0,0.8);
  1222. display: flex;
  1223. flex-direction: column;
  1224. align-items: center;
  1225. justify-content: center;
  1226. z-index: 20000;
  1227. .text {
  1228. font-size: 32rpx;
  1229. color: #FFFFFF;
  1230. text-align: center;
  1231. }
  1232. .btn {
  1233. width: 242rpx;
  1234. height: 82rpx;
  1235. border: 2rpx solid #FFFFFF;
  1236. border-radius: 16rpx;
  1237. text-align: center;
  1238. line-height: 82rpx;
  1239. margin:41rpx auto;
  1240. color:#fff;
  1241. font-size: 32rpx;
  1242. }
  1243. }
  1244. </style>