addChapter.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div id="addChapter">
  3. <el-dialog
  4. :visible.sync="dialogVisible"
  5. width="700px"
  6. :show-close="false"
  7. :close-on-click-modal="false"
  8. >
  9. <div slot="title" class="hearders">
  10. <div class="leftTitle">添加章</div>
  11. <div class="rightBoxs">
  12. <img
  13. src="@/assets/images/Close@2x.png"
  14. alt=""
  15. @click="dialogVisible = false"
  16. />
  17. </div>
  18. </div>
  19. <div>
  20. <p>
  21. <el-button :size="size" type="primary" @click="addChapterList"
  22. >添加</el-button
  23. >
  24. </p>
  25. <el-form label-width="100px" class="elform_style">
  26. <div v-for="(item, index) in list" :key="index" class="dis_box">
  27. <div class="left_box">
  28. <el-form-item label="标题前缀">
  29. <el-input v-model="item.prefixName"></el-input>
  30. <p class="p_style">注:便于检索、归类,以及区分一样的标题</p>
  31. </el-form-item>
  32. <el-form-item label="章标题" required>
  33. <el-input v-model="item.name"></el-input>
  34. <p class="p_style">
  35. 注:请尽量规范易懂,方便在课程目录表呈现给学员
  36. </p>
  37. </el-form-item>
  38. </div>
  39. <div class="clear_style">
  40. <el-button :size="size" @click="list.splice(index, 1)"
  41. >删除</el-button
  42. >
  43. </div>
  44. </div></el-form
  45. >
  46. </div>
  47. <span slot="footer" class="dialog-footer">
  48. <el-button @click="dialogVisible = false">取 消</el-button>
  49. <el-button type="primary" @click="submitForm" :disabled="!list.length"
  50. >确 定</el-button
  51. >
  52. </span>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. size: "small",
  61. dialogVisible: false,
  62. list: [],
  63. };
  64. },
  65. methods: {
  66. addChapterList() {
  67. this.list.push({});
  68. },
  69. openBoxs(arr) {
  70. this.businList = JSON.parse(JSON.stringify(arr));
  71. this.list = [{}]
  72. this.dialogVisible = true;
  73. },
  74. submitForm() {
  75. const arr = [];
  76. this.list.forEach((item, index) => {
  77. if (!item.name && item.name !== 0) {
  78. arr.push(index + 1);
  79. }
  80. });
  81. if (arr.length) {
  82. this.$message.error(
  83. `第${arr.join(",")}条数据没有填写章标题,请填写完整后提交`
  84. );
  85. return;
  86. }
  87. let data = this.list.map((item) => {
  88. item.businessList = this.businList;
  89. item.status = 1;
  90. item.publishStatus = 1;
  91. item.coverUrl = "oss/images/avatar/20211013/1634097664410_1397766697";
  92. return item;
  93. });
  94. this.$api.addMoreCoursechapter(data.reverse()).then((res) => {
  95. this.dialogVisible = false;
  96. this.$emit("backData", res.data);
  97. });
  98. },
  99. },
  100. };
  101. </script>
  102. <style lang="less" scoped>
  103. .dis_box {
  104. background-color: #eee;
  105. padding: 10px 10px 0px;
  106. display: flex;
  107. margin-bottom: 16px;
  108. .left_box {
  109. flex: 1;
  110. }
  111. .clear_style {
  112. flex-shrink: 0;
  113. width: 80px;
  114. vertical-align: top;
  115. text-align: center;
  116. }
  117. }
  118. .elform_style{
  119. max-height: 620px;
  120. overflow: auto;
  121. }
  122. .p_style {
  123. font-size: 12px;
  124. color: #a4a4a4;
  125. margin: 0;
  126. }
  127. </style>