detail.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div class="timeline-container">
  3. <div class="timeline-content">
  4. <div class="timeline-entry-list">
  5. <div class="article">
  6. <div class="article-title">
  7. {{ data.title }}
  8. </div>
  9. <div class="author-info-block">
  10. <div class="meta-box">
  11. {{ data.createTime }}
  12. </div>
  13. </div>
  14. <div class="quesList">
  15. <div class="listItem" v-for="(item, index) in dataList" :key="index">
  16. <div v-if="item.type == 'SCQ'">
  17. <div class="itemTitle">{{ index + 1 }}. {{ item.description }}<el-tag class="elTag" size="small" type="danger">单选</el-tag></div>
  18. <el-radio-group v-model="item.comment" class="flex-column">
  19. <el-radio class="myRadio" :disabled="data.interactUserStatus == 0?false:true" v-for="(childItem, childIndex) in item.options" :key="childIndex"
  20. :label="childItem.id">{{ childItem.name }}</el-radio>
  21. </el-radio-group>
  22. </div>
  23. <div v-if="item.type == 'MCQ'">
  24. <div class="itemTitle">{{ index + 1 }}. {{ item.description }}<el-tag class="elTag" size="small" type="danger">多选</el-tag></div>
  25. <el-checkbox-group v-model="item.comment" class="flex-column">
  26. <el-checkbox class="myRadio" :disabled="data.interactUserStatus == 0?false:true" v-for="(childItem, childIndex) in item.options" :key="childIndex"
  27. :label="childItem.id">{{ childItem.name }}</el-checkbox>
  28. </el-checkbox-group>
  29. </div>
  30. <div v-if="item.type == 'SAQ'">
  31. <div class="itemTitle">{{ index + 1 }}. {{ item.description }}<el-tag class="elTag" size="small" type="danger">问答</el-tag></div>
  32. <div v-if="data.interactUserStatus != 0" class="myText">
  33. {{ item.comment }}
  34. </div>
  35. <el-input v-else type="textarea" :rows="6" maxlength="200" show-word-limit placeholder="请输入内容" v-model="item.comment"></el-input>
  36. </div>
  37. </div>
  38. <div v-if="data.interactUserStatus == 0" class="footBut">
  39. <el-button style="width: 200px;" type="primary" @click="save()">提交</el-button>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. <SiderInfo></SiderInfo>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. import { postInteractInfo, useInfo, postInteractSave } from "@/api/allApi";
  50. import SiderInfo from '@/components/SiderInfo.vue'
  51. export default {
  52. components: {
  53. SiderInfo
  54. },
  55. data() {
  56. return {
  57. data: {
  58. postId: 1,
  59. questionsList: [
  60. {
  61. optionIds: '',
  62. answer: '',
  63. questionId: ''
  64. }
  65. ]
  66. },
  67. dataList: [],
  68. dataInfo: {},
  69. avatarUrl: "",
  70. };
  71. },
  72. created() {
  73. this.getUserInfo();
  74. this.getDataInfo(this.$route.query.id);
  75. },
  76. methods: {
  77. save() {
  78. console.log(this.dataList);
  79. for(var i=0;i<this.dataList.length;i++){
  80. if(this.dataList[i].comment=='' || this.dataList[i].comment==[]){
  81. this.$message.error('还有题目未完成,无法提交!');
  82. return
  83. }
  84. }
  85. let dataList = [];
  86. this.dataList.forEach(item => {
  87. if (item.type == "MCQ") {
  88. item.comment = item.comment.join(',');
  89. dataList.push({ optionIds: item.comment, answer: '', questionId: item.id })
  90. }
  91. if (item.type == "SCQ") {
  92. dataList.push({ optionIds: item.comment, answer: '', questionId: item.id })
  93. }
  94. if (item.type == "SAQ") {
  95. dataList.push({ optionIds: '', answer: item.comment, questionId: item.id })
  96. }
  97. });
  98. let jsonData = JSON.stringify({
  99. postId: this.data.id,
  100. questionList: dataList
  101. })
  102. console.log(jsonData)
  103. postInteractSave({jsonData:jsonData}).then(response => {
  104. this.$notify({
  105. title: "成功",
  106. message: "操作成功",
  107. type: "success",
  108. duration: 2000,
  109. });
  110. this.$router.push({
  111. path: '/home/postInteract'
  112. });
  113. })
  114. },
  115. getUserInfo() {
  116. useInfo().then(response => {
  117. this.dataInfo = response.data.data;
  118. this.avatarUrl = this.dataInfo.httpFile + this.dataInfo.headImage;
  119. })
  120. },
  121. getDataInfo(id) {
  122. postInteractInfo({ postId: id }).then(response => {
  123. this.data = response.data.data;
  124. let questions = response.data.data.data;
  125. questions.forEach(item => {
  126. if (item.type == "MCQ") {
  127. if (item.comment) {
  128. item.comment = item.comment.split(',');
  129. }else{
  130. item.comment = [];
  131. }
  132. }
  133. });
  134. this.dataList = questions;
  135. console.log(this.dataList);
  136. }).catch(() => { })
  137. },
  138. },
  139. }
  140. </script>
  141. <style scoped>
  142. .myText {
  143. display: block;
  144. resize: vertical;
  145. padding: 5px 15px;
  146. line-height: 1.5;
  147. box-sizing: border-box;
  148. width: 100%;
  149. font-size: 14px;
  150. color: #606266;
  151. background-color: #FFF;
  152. background-image: none;
  153. border: 1px solid #DCDFE6;
  154. border-radius: 4px;
  155. transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  156. }
  157. .myRadio{
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. white-space:normal !important;
  162. margin: 10px !important;
  163. }
  164. .flex-column{
  165. display: flex;
  166. flex-flow: column nowrap;
  167. align-items: flex-start;
  168. }
  169. .footBut {
  170. display: flex;
  171. flex-direction: column;
  172. justify-content: center;
  173. align-items: center;
  174. }
  175. .quesList {
  176. margin-bottom: 50px;
  177. }
  178. .listItem {
  179. margin-bottom: 30px;
  180. }
  181. .itemTitle {
  182. margin-bottom: 10px;
  183. font-weight: 700;
  184. }
  185. .elTag{
  186. margin-left: 5px;
  187. }
  188. .userInfo {
  189. width: 65px;
  190. position: absolute;
  191. top: 37%;
  192. left: 46%;
  193. display: flex;
  194. flex-direction: column;
  195. justify-content: center;
  196. align-content: center;
  197. }
  198. .timeline-container {
  199. margin: 0 auto;
  200. }
  201. .timeline-entry-list {
  202. margin-right: 17.5rem;
  203. border-radius: 2px;
  204. width: 720px;
  205. position: relative;
  206. }
  207. .timeline-entry-list .article {
  208. border-radius: 4px 4px 0 0;
  209. position: relative;
  210. padding-top: 2.667rem;
  211. z-index: 1;
  212. overflow: hidden;
  213. background-color: #fff;
  214. padding-left: 2.67rem;
  215. padding-right: 2.67rem;
  216. margin-bottom: 2rem;
  217. box-sizing: border-box;
  218. }
  219. .article .article-title {
  220. margin: 0 0 1rem;
  221. font-size: 1.667rem;
  222. font-weight: 600;
  223. line-height: 1.31;
  224. color: #252933;
  225. }
  226. .article .author-info-block {
  227. display: flex;
  228. align-items: center;
  229. margin-bottom: 1.667rem
  230. }
  231. .article .markdown-body {
  232. overflow: hidden;
  233. line-height: 1.75;
  234. font-size: 15px;
  235. /* background-image: linear-gradient(90deg,rgba(72,42,10,.05) 5%,rgba(72,42,10,0) 0),linear-gradient(1turn,rgba(72,42,10,.05) 5%,rgba(72,42,10,0) 0); */
  236. background-size: 20px 20px;
  237. background-position: 50%;
  238. padding-top: 0 !important;
  239. min-height: 280px;
  240. }
  241. .markdown-body img {
  242. max-width: 100%;
  243. }
  244. .markdown-body p {
  245. color: #412c0c;
  246. letter-spacing: 1px;
  247. font-weight: 400;
  248. }
  249. .author-info-block .meta-box {
  250. font-size: 1rem;
  251. color: #8a919f;
  252. margin-top: 2px;
  253. line-height: 22px;
  254. }</style>