TopicSelectDialog.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <el-dialog
  3. class="topic-select-dialog"
  4. :visible.sync="modalIsShow"
  5. title="试题选择"
  6. top="10vh"
  7. width="400px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <div class="topic-select-list">
  14. <el-button
  15. v-for="(item, index) in topics"
  16. :key="index"
  17. :type="curTopic.type === item.type ? 'primary' : ''"
  18. @click="selectTopic(item)"
  19. ><i class="el-icon-plus"></i>{{ item.name }}</el-button
  20. >
  21. </div>
  22. <div slot="footer">
  23. <el-button type="primary" @click="submit">确认</el-button>
  24. <el-button @click="cancel">取消</el-button>
  25. </div>
  26. </el-dialog>
  27. </template>
  28. <script>
  29. export default {
  30. name: "TopicSelectDialog",
  31. props: {
  32. topics: {
  33. type: Array,
  34. default() {
  35. return [];
  36. },
  37. },
  38. insertTopic: {
  39. type: Object,
  40. default() {
  41. return {};
  42. },
  43. },
  44. },
  45. data() {
  46. return {
  47. modalIsShow: false,
  48. curTopic: {},
  49. };
  50. },
  51. methods: {
  52. visibleChange() {
  53. this.curTopic = {};
  54. },
  55. cancel() {
  56. this.modalIsShow = false;
  57. },
  58. open() {
  59. this.modalIsShow = true;
  60. },
  61. selectTopic(topic) {
  62. this.curTopic = topic;
  63. },
  64. submit() {
  65. if (!this.curTopic.type) {
  66. this.$message.error("请选择试题类型");
  67. return;
  68. }
  69. this.$emit("confirm", {
  70. ...this.curTopic,
  71. insertTopic: this.insertTopic,
  72. });
  73. this.cancel();
  74. },
  75. },
  76. };
  77. </script>