index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div>
  3. <el-dialog title="选择题" :visible.sync="dialogVisibleChoice" :append-to-body="true" width="1000px"
  4. :before-close="handleClose" class="dialog_diy dialog_diy3">
  5. <div v-if="dialogVisibleChoice">
  6. <div class="a_addBox">
  7. <div style="font-size: 16px; color: #c7c7c7">题目内容</div>
  8. <div class="a_add_box" v-for="(item1, index1) in testJson.testCount" :key="index1">
  9. <div class="a_add_head">
  10. <div style="display: flex">
  11. {{ index1 + 1 + "、" }}
  12. <div v-if="testJson.testJson[index1].type == '1'" style="margin-right: 5px">
  13. (单选题)
  14. </div>
  15. <div v-if="testJson.testJson[index1].type == '2'" style="margin-right: 5px">
  16. (多选题)
  17. </div>
  18. <div>题目:{{ testJson.testJson[index1].teststitle }}</div>
  19. </div>
  20. <img v-if="testJson.testJson[index1].img" :src="testJson.testJson[index1].img"
  21. style="height: 300px; margin-top: 10px; max-width: 100%" />
  22. </div>
  23. <div class="timuImgBox" v-if="testJson.testJson[index1].timuList &&
  24. testJson.testJson[index1].timuList.length
  25. ">
  26. <div v-for="(timg, tIndex) in testJson.testJson[index1].timuList" :key="tIndex" class="timuImg"
  27. @click.stop="previewImg(timg.src)">
  28. <img :src="timg.src" alt="" />
  29. </div>
  30. </div>
  31. <div class="a_add_body">
  32. <div class="a_add_input">
  33. <el-radio-group v-model="radio[index1]" v-if="testJson.testJson[index1].type == '1'" :disabled="videoType==1" >
  34. <div class="radioBox">
  35. <el-radio v-for="(item2, checkIndex) in testJson.testJson[index1]
  36. .checkList" :key="checkIndex" :label="checkIndex"
  37. class="redioStyle">
  38. <div style="margin-right: 10px"
  39. v-if="item2 && item2.imgType && item2.imgType == 1">
  40. <div class="inImg" @click.stop="previewImg(item2.src)">
  41. <img :src="item2.src" alt="" />
  42. </div>
  43. </div>
  44. <span :class="typeof radio[index1] == 'number' && [radio[index1]==checkIndex?'showLight':'']" v-else v-html="item2"></span>
  45. </el-radio>
  46. </div>
  47. </el-radio-group>
  48. <el-checkbox-group v-model="radio[index1]" v-if="testJson.testJson[index1].type == '2'" :disabled="videoType==1">
  49. <div class="radioBox">
  50. <el-checkbox v-for="(item2, checkIndex) in testJson.testJson[index1]
  51. .checkList" :key="checkIndex" :label="checkIndex"
  52. class="redioStyle">
  53. <div style="margin-right: 10px"
  54. v-if="item2 && item2.imgType && item2.imgType == 1">
  55. <div class="inImg" @click.stop="previewImg(item2.src)">
  56. <img :src="item2.src" alt="" />
  57. </div>
  58. </div>
  59. <span :class="radio[index1].length && [radio[index1].includes(checkIndex)?'showLight':'']" v-else v-html="item2"></span>
  60. </el-checkbox>
  61. </div>
  62. </el-checkbox-group>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <span slot="footer" class="dialog-footer">
  69. <el-button @click="close">取 消</el-button>
  70. <el-button type="primary" @click="addStudentTest">确 定</el-button>
  71. </span>
  72. </el-dialog>
  73. </div>
  74. </template>
  75. <script>
  76. export default {
  77. props: {
  78. dialogVisibleChoice: {
  79. type: Boolean,
  80. default: false
  81. },
  82. json: {
  83. type: Object
  84. },
  85. userid: {
  86. type: String,
  87. },
  88. id: {
  89. type: String,
  90. },
  91. courseType: {
  92. type: [String, Number],
  93. },
  94. taskCount: {
  95. type: Number,
  96. },
  97. toolindex: {
  98. type: Number,
  99. },
  100. videoTime: {
  101. type: Number,
  102. },
  103. userChooseAnswer:{
  104. type:Array,
  105. },
  106. videoType:{
  107. type:Number,
  108. default:0
  109. }
  110. },
  111. data() {
  112. return {
  113. testJson: {},
  114. radio: []
  115. }
  116. },
  117. watch: {
  118. dialogVisibleChoice(newValue, oldValue) {
  119. this.radio = []
  120. this.testJson = JSON.parse(JSON.stringify(this.json));
  121. for (var k = 0; k < this.testJson.testJson.length; k++) {
  122. if (this.testJson.testJson[k].type == "2") {
  123. this.radio.push([]);
  124. } else {
  125. this.radio.push("");
  126. }
  127. }
  128. }
  129. },
  130. methods: {
  131. handleClose(done) {
  132. this.close();
  133. done()
  134. },
  135. close() {
  136. this.$emit("update:dialogVisibleChoice", false)
  137. this.$emit("play")
  138. },
  139. previewImg(url) {
  140. this.$hevueImgPreview(url);
  141. },
  142. setUserAnswer(userAnswer){
  143. this.radio = userAnswer;
  144. // if(userAnswer.find(i=>i.testJson[0].teststitle==this.testJson[0].teststitle)){
  145. // console.log("有答案了")
  146. // }else{
  147. // console.log("没有答案")
  148. // }
  149. },
  150. addStudentTest() {
  151. if (!this.radio.length) {
  152. this.$message.error("请选择选项");
  153. return;
  154. }
  155. for (var i = 0; i < this.testJson.testCount; i++) {
  156. if (
  157. (this.radio[i] instanceof Array && !this.radio[i].length) ||
  158. (this.radio[i] !== 0 && !this.radio[i])
  159. ) {
  160. this.$message.error("请选择选项");
  161. return;
  162. }
  163. }
  164. this.videoType==0?this.$emit("success",{answer:this.radio,json:this.testJson}):'';
  165. this.close();
  166. // let askList = []
  167. // askList.push({ testJson: this.testJson, anwer: this.radio,type:8,tool:45 });
  168. // let params = [
  169. // {
  170. // uid: this.userid,
  171. // cid: this.id,
  172. // stage: this.courseType,
  173. // task: this.taskCount,
  174. // tool: this.toolindex,
  175. // content: JSON.stringify(askList),
  176. // type: 14,
  177. // atool: 62,
  178. // vtime: this.videoTime,
  179. // },
  180. // ];
  181. // this.ajax
  182. // .post(this.$store.state.api + "addCourseWorks2Inter", params)
  183. // .then((res) => {
  184. // this.$message({
  185. // message: "提交成功",
  186. // type: "success",
  187. // });
  188. // this.close();
  189. // })
  190. // .catch((err) => {
  191. // this.$message.error("提交失败");
  192. // console.error(err);
  193. // });
  194. }
  195. },
  196. mounted() {
  197. this.radio = []
  198. this.testJson = JSON.parse(JSON.stringify(this.json));
  199. for (var k = 0; k < this.testJson.testJson.length; k++) {
  200. if (this.testJson.testJson[k].type == "2") {
  201. this.radio.push([]);
  202. } else {
  203. this.radio.push("");
  204. }
  205. }
  206. },
  207. }
  208. </script>
  209. <style scoped>
  210. @media screen and (max-width: 1280px) {
  211. .dialog_diy3>>>.el-dialog {
  212. width: 100% !important;
  213. }
  214. }
  215. .dialog_diy>>>.el-dialog {
  216. margin-top: 10vh !important;
  217. }
  218. .dialog_diy>>>.el-dialog__header {
  219. background: #454545 !important;
  220. padding: 15px 20px;
  221. }
  222. .dialog_diy>>>.el-dialog__title,
  223. .dialog_diy1>>>.el-dialog__title {
  224. color: #fff;
  225. }
  226. .dialog_diy>>>.el-dialog__headerbtn {
  227. top: 19px;
  228. }
  229. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close {
  230. color: #fff;
  231. }
  232. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close:hover {
  233. color: #fff;
  234. }
  235. .dialog_diy1>>>.el-dialog__body {
  236. padding: 0;
  237. }
  238. .dialog_diy>>>.el-dialog__body,
  239. .dialog_diy>>>.el-dialog__footer {
  240. background: #fafafa;
  241. }
  242. .a_addBox {
  243. margin: 10px 0;
  244. background: #fff;
  245. padding: 15px;
  246. max-height: 400px;
  247. overflow: auto;
  248. }
  249. .a_add_box {
  250. border-bottom: 2px solid #eee;
  251. padding-bottom: 10px;
  252. }
  253. .a_add_head {
  254. display: flex;
  255. align-items: flex-start;
  256. /* justify-content: space-between; */
  257. flex-direction: column;
  258. /* flex-direction: row; */
  259. margin: 10px 0 20px 0;
  260. font-size: 18px;
  261. width: 100%;
  262. }
  263. .a_add_head .a_add_head_input {
  264. width: 300px;
  265. }
  266. .a_add_head .a_add_head_div {
  267. display: flex;
  268. align-items: center;
  269. justify-content: space-between;
  270. }
  271. .a_add_body {
  272. display: flex;
  273. align-items: center;
  274. }
  275. .a_add_input {
  276. display: flex;
  277. align-items: center;
  278. flex-wrap: wrap;
  279. }
  280. .a_add_input>>>el-radio-group {
  281. margin: 10px 0;
  282. }
  283. .a_add_input>>>.el-radio,
  284. .a_add_input>>>.el-checkbox {
  285. margin-bottom: 10px;
  286. display: flex;
  287. flex-direction: row;
  288. flex-wrap: nowrap;
  289. align-items: center;
  290. }
  291. .redioStyle>>>.el-radio__label {
  292. font-size: 18px;
  293. }
  294. .redioStyle>>>.el-checkbox__label {
  295. font-size: 18px;
  296. }
  297. .radioBox {
  298. display: flex;
  299. flex-direction: row;
  300. flex-wrap: nowrap;
  301. align-items: center;
  302. }
  303. .radioBox>div {
  304. margin: 10px 0 0 10px;
  305. }
  306. .radioBox>>>.el-radio__label,
  307. .radioBox>>>.el-checkbox__label {
  308. display: flex;
  309. align-items: center;
  310. }
  311. .inImg {
  312. width: 100px;
  313. cursor: pointer;
  314. }
  315. .inImg>img {
  316. width: 100%;
  317. height: 100%;
  318. object-fit: cover;
  319. }
  320. .timuImgBox {
  321. margin: 10px 0;
  322. display: flex;
  323. flex-direction: column;
  324. flex-wrap: wrap;
  325. align-items: flex-start;
  326. }
  327. .timuImg {
  328. width: 100px;
  329. margin: 5px 0;
  330. cursor: pointer;
  331. }
  332. .timuImg>img {
  333. width: 100%;
  334. height: 100%;
  335. object-fit: cover;
  336. }
  337. .showLight{
  338. color: #0061FF !important;
  339. }
  340. </style>