classList-group.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div>
  3. <el-form :model="form" ref="form">
  4. <classListItem
  5. v-for="(item, index) in form.classList"
  6. :key="index"
  7. :index="index"
  8. :item="item"
  9. @deteleClass="deteleClass"
  10. :form="form"
  11. :classList="activeClassList"
  12. @filterClassList="filterClassList"
  13. />
  14. </el-form>
  15. <el-button
  16. icon="el-icon-circle-plus-outline"
  17. plain
  18. type="info"
  19. size="small"
  20. style="width: 100%; margin: 20px 0"
  21. @click="addClass"
  22. :disabled="form.classList.length >= classList.length"
  23. >添加班级</el-button
  24. >
  25. <el-dialog
  26. :visible.sync="showSecondVisable"
  27. title="缴费信息设置"
  28. append-to-body
  29. width="800px"
  30. >
  31. <classPayList
  32. :classIdList="classIdList"
  33. :courseTypesByType="courseTypesByType"
  34. :form="form"
  35. :payInfo="payInfo"
  36. @close="showSecondVisable = false"
  37. v-if="showSecondVisable"
  38. />
  39. </el-dialog>
  40. </div>
  41. </template>
  42. <script>
  43. import classListItem from "./classList-item";
  44. import classPayList from "./class-pay-list";
  45. import { getDefaultPaymentCalender } from "@/api/buildTeam";
  46. export default {
  47. props: ["classList", "courseTypesByType"],
  48. components: { classListItem, classPayList },
  49. data() {
  50. return {
  51. form: {
  52. classList: [
  53. {
  54. classId: "",
  55. studentList: [],
  56. courseList: {},
  57. index: "",
  58. type: "",
  59. classList: this.classList,
  60. },
  61. ],
  62. },
  63. showSecondVisable: false,
  64. classIdList: [],
  65. activeClassList: [],
  66. };
  67. },
  68. mounted() {
  69. this.activeClassList = [...new Set(this.classList)];
  70. },
  71. methods: {
  72. addClass() {
  73. this.form.classList.push({
  74. classId: "",
  75. studentList: [],
  76. courseList: {},
  77. index: "",
  78. type: "",
  79. classList: this.classList,
  80. });
  81. },
  82. deteleClass(index) {
  83. this.form.classList.splice(index, 1);
  84. },
  85. gotoSecond() {
  86. this.$refs.form.validate(async (res) => {
  87. if (res) {
  88. let flag = false;
  89. this.form.classList.forEach((item) => {
  90. if (item.studentList.length <= 0) {
  91. flag = true;
  92. }
  93. });
  94. if (flag) {
  95. this.$message.error("每个班级至少勾选一名学员");
  96. return;
  97. }
  98. this.classIdList = this.form.classList.map((item) => {
  99. return item.classId;
  100. });
  101. try {
  102. let result = await getDefaultPaymentCalender(this.classIdList);
  103. this.payInfo = result.data;
  104. this.showSecondVisable = true;
  105. } catch {}
  106. }
  107. });
  108. },
  109. filterClassList(id) {
  110. let arr = [];
  111. this.form.classList.forEach((item) => {
  112. if (item.classId) {
  113. arr.push(item.classId);
  114. }
  115. });
  116. console.log(arr)
  117. if (id) {
  118. let item;
  119. // 找到对应的班级
  120. this.classList.forEach((classes) => {
  121. if (classes.id == id) {
  122. item = classes;
  123. }
  124. });
  125. // 过滤类型不一样的
  126. this.activeClassList = this.classList.filter((classes) => {
  127. return item.type == classes.type;
  128. });
  129. this.activeClassList = this.activeClassList.map((classes) => {
  130. if (arr.indexOf(classes.id) != -1) {
  131. classes.disabled = true;
  132. } else {
  133. classes.disabled = false;
  134. }
  135. return classes;
  136. });
  137. } else {
  138. if (arr.length == 0) {
  139. this.activeClassList = [...new Set(this.classList)];
  140. console.log(this.activeClassList)
  141. } else {
  142. this.activeClassList =this.activeClassList.map((classes) => {
  143. if (arr.indexOf(classes.id) != -1) {
  144. classes.disabled = true;
  145. } else {
  146. classes.disabled = false;
  147. }
  148. return classes;
  149. });
  150. }
  151. }
  152. },
  153. },
  154. };
  155. </script>
  156. <style lang="scss" scoped>
  157. </style>