Questionnaire.vue 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="question-wrapper">
  3. <QuestionnHome
  4. :show="showFirstScreen"
  5. :content="questionnaireContent"
  6. @confirm="showFirstScreen = false"
  7. />
  8. <van-dialog v-model="showPopup" title="确定提交答案吗" show-cancel-button @confirm="submitForm()">
  9. <p style="margin: 2em">确定要提交答案吗?</p>
  10. </van-dialog>
  11. <!-- 页面标题 -->
  12. <div class="VSTD_box" v-if="questionList.length > 0">
  13. <!-- 题的表单 -->
  14. <!-- 绑定表单的数据 ruleForm -->
  15. <!-- 绑定题的数组 ruleForm.resource[index] -->
  16. <van-form class="demo-ruleForm">
  17. <!-- 循环后端 的所有题 -->
  18. <div class="VSTD_box_item">
  19. <question
  20. :step="step + 1"
  21. :steps="total"
  22. v-model="currentQuestion"
  23. @next="step++"
  24. @prev="step--"
  25. @submit="showPopup = true"
  26. ></question>
  27. </div>
  28. </van-form>
  29. </div>
  30. <!-- 如果没题就提示没题 -->
  31. <div v-else>
  32. <div class="none" style="margin-left: 0px">
  33. <div class="none_img"></div>
  34. <h3>暂无试题</h3>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import { Toast } from 'vant'
  41. import { getQuestionnaire, getQuestion, answerQuestionnaire } from '@/util/api'
  42. export default {
  43. name: 'QuestionDetail',
  44. components: {
  45. Question: () => import('./components/Question'),
  46. Popup: () => import('./components/Questionnaire/Popup.vue'),
  47. QuestionnHome: () => import('./components/QuestionnHome.vue')
  48. },
  49. props: {},
  50. data() {
  51. return {
  52. showFirstScreen: true,
  53. questionnaireContent: {},
  54. showPopup: false,
  55. step: 0,
  56. total: 0,
  57. questionList: []
  58. }
  59. },
  60. computed: {
  61. currentQuestion: {
  62. get: function () {
  63. return this.questionList[this.step]
  64. },
  65. set: function (val) {
  66. this.$set(this.questionList, this.step, val)
  67. }
  68. }
  69. },
  70. watch: {
  71. '$route.query.id': {
  72. handler(v) {
  73. this.loadData('f5a47d178019bda33a370d7a6ed1e4c3')
  74. },
  75. immediate: true
  76. }
  77. },
  78. methods: {
  79. loadData(id) {
  80. // 问卷信息
  81. getQuestionnaire(id).then((e) => {
  82. this.questionnaireContent = e || {}
  83. })
  84. // 问题列表
  85. getQuestion(id).then((res) => {
  86. console.log('题目列表', res)
  87. const { records, total } = res
  88. this.questionList = records || []
  89. this.total = total
  90. })
  91. // let sum = 0
  92. },
  93. submitForm(e) {
  94. const toast = Toast.loading({
  95. duration: 0, // 持续展示 toast
  96. forbidClick: true,
  97. message: '请稍后...'
  98. })
  99. answerQuestionnaire(this.$route.query.id, this.questionList)
  100. .then((e) => {
  101. toast.clear()
  102. Toast.success('感谢您的参与')
  103. this.questionnaireContent.isAnswered = true
  104. this.showFirstScreen = true
  105. })
  106. .catch((e) => {
  107. toast.clear()
  108. Toast.fail(e.message)
  109. })
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="less" scoped>
  115. .question-wrapper {
  116. background-image: url('~@/assets/userImag/backImag.png');
  117. background-size: 100%;
  118. background-repeat: no-repeat;
  119. }
  120. .ImagStyle {
  121. width: 100%;
  122. }
  123. .VSTD_box {
  124. .demo-ruleForm {
  125. width: 80%;
  126. display: flex;
  127. margin: 0 auto;
  128. .VSTD_box_item {
  129. display: flex;
  130. flex-direction: column;
  131. align-items: center;
  132. .but-box {
  133. width: 62vw;
  134. .but-box-form-item {
  135. text-align: center;
  136. width: 100%;
  137. margin: 0 auto;
  138. top: -5vh;
  139. position: relative;
  140. }
  141. .butsize {
  142. height: 43px;
  143. margin: 0 10px;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. </style>