AddChapter.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible="visible"
  5. width="460px"
  6. :show-close="false"
  7. class="add-chapter"
  8. @close="dialogClose"
  9. >
  10. <el-form ref="form" :model="data" :rules="rules" label-width="80px">
  11. <el-form-item label="章节名称" prop="name">
  12. <el-input ref="name" v-model="data.name" placeholder="请输入章节名称" />
  13. </el-form-item>
  14. </el-form>
  15. <div slot="footer">
  16. <el-button @click="dialogClose">取消</el-button>
  17. <el-button type="primary" @click="addChapterNode">确定</el-button>
  18. </div>
  19. </el-dialog>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'AddChapter',
  24. props: {
  25. visible: {
  26. type: Boolean,
  27. required: true,
  28. },
  29. id: {
  30. type: String,
  31. default: '',
  32. },
  33. parentId: {
  34. type: String,
  35. default: '',
  36. },
  37. curSelectId: {
  38. type: String,
  39. default: '',
  40. },
  41. addType: {
  42. type: String,
  43. default: 'chapter',
  44. },
  45. },
  46. data() {
  47. return {
  48. data: {
  49. name: '',
  50. book_id: this.id,
  51. },
  52. rules: {
  53. name: [{ required: true, message: '请输入章节名称', trigger: 'blur' }],
  54. },
  55. };
  56. },
  57. computed: {
  58. title() {
  59. return this.addType === 'chapter' ? '添加章节' : '添加课件';
  60. },
  61. },
  62. watch: {
  63. visible(newVal) {
  64. if (newVal) {
  65. this.$nextTick(() => {
  66. this.$refs.form.clearValidate();
  67. this.$refs.name.focus();
  68. });
  69. }
  70. },
  71. },
  72. methods: {
  73. dialogClose() {
  74. this.$emit('close');
  75. this.data.name = '';
  76. },
  77. addChapterNode() {
  78. if (this.addType === 'chapter') {
  79. this.$emit('addChapterNode', {
  80. ...this.data,
  81. parent_id: this.parentId,
  82. is_leaf: 'false',
  83. });
  84. } else {
  85. this.$emit('addCourseware', {
  86. ...this.data,
  87. chapter_id: this.curSelectId,
  88. });
  89. }
  90. this.data.name = '';
  91. },
  92. },
  93. };
  94. </script>