askPanel.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class="cp-container" v-if="panelVisible">
  3. <div class="cp-title">
  4. <span class="back" @click="back"></span>
  5. <span class="title" v-if="isTeacher">问卷调查作业</span>
  6. <span class="title" v-else>问卷调查作业-{{ sStudent.student }}</span>
  7. <span class="btn" v-if="type == 1" @click="addPz(type)">提交</span>
  8. </div>
  9. <div class="cp-box">
  10. <div class="cp-quest">标题:{{ askJson.askTitle }}</div>
  11. <div class="cp-conent" v-if="type == 1">
  12. <div v-for="(item, index) in askJson.askCount" :key="index" class="askBox">
  13. <div class="askTitle">
  14. {{ index + 1 + '、' }}
  15. <div>题目:{{ askJson.askJson[index].askstitle }}</div>
  16. </div>
  17. <img v-if="askJson.askJson[index].img" :src="askJson.askJson[index].img" />
  18. <div class="askBody">
  19. <el-radio-group
  20. v-model="radio[index]"
  21. v-if="askJson.askJson[index].type == '1' || !askJson.askJson[index].type"
  22. >
  23. <el-radio
  24. v-for="(item1, checkIndex) in askJson.askJson[index].checkList"
  25. :key="checkIndex"
  26. :label="checkIndex"
  27. class="redioStyle"
  28. ><span v-html="item1"></span
  29. ></el-radio>
  30. </el-radio-group>
  31. <el-checkbox-group v-model="radio[index]" v-if="askJson.askJson[index].type == '2'">
  32. <el-checkbox
  33. v-for="(item1, checkIndex) in askJson.askJson[index].checkList"
  34. :key="checkIndex"
  35. :label="checkIndex"
  36. class="redioStyle"
  37. ><span v-html="item1"></span>
  38. </el-checkbox>
  39. </el-checkbox-group>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import { addCourseWorks, addCourseWorksTeacher } from '@/api/course'
  48. import { mapGetters } from 'vuex'
  49. export default {
  50. props: {
  51. panelVisible: {
  52. type: Boolean
  53. },
  54. courseid: {
  55. type: String,
  56. default: ''
  57. },
  58. courseType: {
  59. type: Number,
  60. default: 0
  61. },
  62. taskCount: {
  63. type: Number,
  64. default: 0
  65. },
  66. toolindex: {
  67. type: Number
  68. },
  69. isTeacher: {
  70. type: Boolean
  71. },
  72. askJson: {
  73. type: Object
  74. },
  75. sStudent: {
  76. type: Object
  77. }
  78. },
  79. components: {},
  80. data() {
  81. return {
  82. type: 1,
  83. message: '',
  84. imgList: [],
  85. radio: [],
  86. askList: []
  87. }
  88. },
  89. computed: {
  90. ...mapGetters(['userinfo'])
  91. },
  92. mounted() {
  93. for (var k = 0; k < this.askJson.askJson.length; k++) {
  94. if (this.askJson.askJson[k].type == '2') {
  95. this.radio.push([])
  96. } else {
  97. this.radio.push('')
  98. }
  99. }
  100. },
  101. methods: {
  102. back() {
  103. this.$emit('setAskPanelVisible', false)
  104. },
  105. setType(type) {
  106. this.type = type
  107. },
  108. getImage(imgList) {
  109. this.imgList = imgList
  110. this.$forceUpdate()
  111. },
  112. addPz() {
  113. if (!this.radio.length) {
  114. this.$message.error('请选择选项')
  115. return
  116. }
  117. for (var i = 0; i < this.askJson.askCount; i++) {
  118. if ((this.radio[i] instanceof Array && !this.radio[i].length) || (this.radio[i] !== 0 && !this.radio[i])) {
  119. this.$message.error('请选择选项')
  120. return
  121. }
  122. }
  123. const fun = [addCourseWorks, addCourseWorksTeacher]
  124. const askList = [
  125. {
  126. askJson: this.askJson,
  127. anwer: this.radio
  128. }
  129. ]
  130. let params = []
  131. if (this.isTeacher) {
  132. params = [
  133. {
  134. uid: this.userinfo.userid,
  135. cid: this.courseid,
  136. stage: this.courseType,
  137. task: this.taskCount,
  138. tool: this.toolindex,
  139. content: JSON.stringify(askList).replaceAll(/%/g, '%25'),
  140. type: 2
  141. }
  142. ]
  143. } else {
  144. params = [
  145. {
  146. uid: this.sStudent.userid,
  147. cid: this.courseid,
  148. stage: this.courseType,
  149. task: this.taskCount,
  150. tool: this.toolindex,
  151. content: JSON.stringify(askList),
  152. type: 2,
  153. ateacher: this.userinfo.userid
  154. }
  155. ]
  156. }
  157. fun[this.isTeacher ? 0 : 1](params)
  158. .then(res => {
  159. this.$toast({
  160. message: '上传成功',
  161. type: 'success'
  162. })
  163. this.$emit('setAskPanelVisible', false)
  164. })
  165. .catch(err => {
  166. console.error(err)
  167. })
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .cp-container {
  174. width: 100vw;
  175. height: 100vh;
  176. position: fixed;
  177. top: 0;
  178. left: 0;
  179. background: #fff;
  180. z-index: 2;
  181. .cp-title {
  182. height: 1.5rem;
  183. width: 100%;
  184. border-bottom: 1px solid #cecece;
  185. display: flex;
  186. align-items: center;
  187. justify-content: center;
  188. box-sizing: border-box;
  189. position: relative;
  190. .back {
  191. width: 0.3rem;
  192. height: 0.3rem;
  193. border-top: 2px solid #000000;
  194. border-left: 2px solid #000000;
  195. position: absolute;
  196. transform: rotate(-45deg) translateY(-50%);
  197. top: 47%;
  198. left: 0.8rem;
  199. cursor: pointer;
  200. }
  201. .title {
  202. font-size: 16px;
  203. }
  204. .btn {
  205. font-size: 14px;
  206. transform: translateY(-50%);
  207. top: 50%;
  208. right: 0.8rem;
  209. position: absolute;
  210. color: #2274ff;
  211. cursor: pointer;
  212. }
  213. }
  214. .cp-box {
  215. width: 100%;
  216. height: calc(100% - 1.5rem);
  217. overflow: auto;
  218. .type-nav {
  219. height: 60px;
  220. width: 100%;
  221. display: flex;
  222. align-items: center;
  223. padding: 10px 0.3rem;
  224. box-sizing: border-box;
  225. .type-nav-box {
  226. height: 100%;
  227. opacity: 0.5;
  228. transition: all 0.5s;
  229. + .type-nav-box {
  230. margin-left: 0.3rem;
  231. }
  232. &.active {
  233. opacity: 1;
  234. }
  235. > img {
  236. height: 100%;
  237. }
  238. }
  239. }
  240. .cp-quest {
  241. width: 100%;
  242. padding: 10px 15px;
  243. font-size: 18px;
  244. word-break: break-all;
  245. box-sizing: border-box;
  246. }
  247. .cp-conent {
  248. // margin-top: 10px;
  249. height: auto;
  250. overflow: auto;
  251. font-size: 14px;
  252. width: 100%;
  253. /deep/ .van-field__control {
  254. // height: auto !important;
  255. }
  256. .askBox {
  257. padding: 0.26667rem 0.4rem;
  258. .askTitle {
  259. display: flex;
  260. }
  261. .askBody {
  262. margin-top: 10px;
  263. /deep/.redioStyle {
  264. margin-bottom: 10px;
  265. }
  266. }
  267. }
  268. }
  269. .cp-audio {
  270. height: calc(100% - 60px);
  271. position: relative;
  272. width: 100%;
  273. }
  274. }
  275. }
  276. </style>