setQuestion.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div id="setQuestion">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="top">
  6. <el-button type="primary" size="mini" @click="add">添加题目</el-button>
  7. <el-button type="primary" size="mini" @click="back">返回</el-button>
  8. </el-col>
  9. <el-col :span="24" class="down">
  10. <el-col :span="24" class="title">
  11. {{ info.title }}
  12. </el-col>
  13. <el-col :span="24" class="form">
  14. <el-col :span="24" class="list" v-for="(item, index) in info.questions" :key="index">
  15. <el-col :span="24" class="name"> {{ index + 1 }}-{{ item.title }} </el-col>
  16. <el-col :span="24" class="radios" v-if="item.type == '0'">
  17. <el-radio v-model="info.radio" :label="item.num" v-for="(item, index) in item.selects" :key="index">{{ item.num }}-{{ item.name }}</el-radio>
  18. </el-col>
  19. <el-col :span="24" class="checkbox" v-else-if="item.type == '1'">
  20. <el-checkbox v-for="(item, index) in item.selects" :key="index">{{ item.num }}-{{ item.name }}</el-checkbox>
  21. </el-col>
  22. <el-col :span="24" class="content" v-else-if="item.type == '2'">
  23. <el-input v-model="item.content" type="textarea" :autosize="{ minRows: 4, maxRows: 6 }" placeholder="请输入简答" disabled> </el-input>
  24. </el-col>
  25. </el-col>
  26. </el-col>
  27. </el-col>
  28. </el-col>
  29. </el-row>
  30. <el-dialog title="题目管理" width="40%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
  31. <el-form ref="form" :model="form" label-width="80px">
  32. <el-form-item label="选择题目">
  33. <el-select v-model="form.questions" multiple filterable placeholder="请选择">
  34. <el-option v-for="item in questionsList" :key="item.id" :label="item.title" :value="item.id">
  35. <span style="float: left">{{ item.title }}</span>
  36. <span style="float: right; color: #8492a6; font-size: 13px">{{ item.type == '0' ? '单选' : item.type == '1' ? '多选' : '简答' }}</span>
  37. </el-option>
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button type="primary" size="mini" @click="onSubmit">保存选项</el-button>
  42. </el-form-item>
  43. </el-form>
  44. </el-dialog>
  45. </div>
  46. </template>
  47. <script>
  48. import { mapState, createNamespacedHelpers } from 'vuex';
  49. const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
  50. const { mapActions: question } = createNamespacedHelpers('question');
  51. export default {
  52. name: 'setQuestion',
  53. props: {},
  54. components: {},
  55. data: function() {
  56. return {
  57. info: {},
  58. // 选择题目
  59. dialog: false,
  60. form: {},
  61. // 题目列表
  62. questionsList: [],
  63. };
  64. },
  65. async created() {
  66. await this.search();
  67. },
  68. methods: {
  69. ...questionnaire(['query', 'fetch', 'create', 'update', 'delete']),
  70. ...question({ queQuery: 'query' }),
  71. async search() {
  72. if (this.id) {
  73. let res = await this.fetch(this.id);
  74. if (this.$checkRes(res)) {
  75. this.$set(this, `info`, res.data);
  76. }
  77. }
  78. },
  79. // 添加题目
  80. async add() {
  81. let res = await this.queQuery();
  82. if (this.$checkRes(res)) {
  83. this.$set(this, `questionsList`, res.data);
  84. }
  85. this.dialog = true;
  86. },
  87. // 保存选题
  88. async onSubmit() {
  89. let data = this.form;
  90. data.id = this.id;
  91. let res = await this.update(data);
  92. if (this.$checkRes(res)) {
  93. this.$message({
  94. message: '添加题目成功',
  95. type: 'success',
  96. });
  97. this.handleClose();
  98. this.search();
  99. }
  100. },
  101. // 取消添加
  102. handleClose() {
  103. this.form = {};
  104. this.dialog = false;
  105. },
  106. back() {
  107. this.$router.push({ path: '/question' });
  108. },
  109. },
  110. computed: {
  111. ...mapState(['user']),
  112. id() {
  113. return this.$route.query.id;
  114. },
  115. },
  116. metaInfo() {
  117. return { title: this.$route.meta.title };
  118. },
  119. watch: {
  120. test: {
  121. deep: true,
  122. immediate: true,
  123. handler(val) {},
  124. },
  125. },
  126. };
  127. </script>
  128. <style lang="less" scoped>
  129. .main {
  130. .top {
  131. text-align: right;
  132. margin: 0 0 15px 0;
  133. }
  134. .down {
  135. padding: 0 10%;
  136. .title {
  137. text-align: center;
  138. font-size: 20px;
  139. font-weight: bold;
  140. margin: 0 0 20px 0;
  141. }
  142. .form {
  143. padding: 10px 20px;
  144. border: 1px solid #ccc;
  145. .list {
  146. border-bottom: 1px dashed #f1f1f1;
  147. padding: 10px 0;
  148. .name {
  149. font-weight: bold;
  150. font-size: 18px;
  151. margin: 0 0 10px 0;
  152. }
  153. .content {
  154. padding: 0;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. /deep/.el-select {
  161. width: 100%;
  162. }
  163. </style>