detail.vue 8.6 KB

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