classList-group.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. :addCourseType="addCourseType"
  34. :courseTypesByType="courseTypesByType"
  35. :classMaxCourseNumMap="classMaxCourseNumMap"
  36. :form="form"
  37. :teacherList="teacherList"
  38. :payInfo.sync="payInfo"
  39. @resetPayInfo="resetPayInfo"
  40. @close="showSecondVisable = false"
  41. v-if="showSecondVisable"
  42. />
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. import classListItem from "./classList-item";
  48. import classPayList from "./class-pay-list";
  49. import { getDefaultPaymentCalender } from "@/api/buildTeam";
  50. export default {
  51. props: ["classList", "courseTypesByType", "teacherList"],
  52. components: { classListItem, classPayList },
  53. data() {
  54. return {
  55. form: {
  56. classList: [
  57. {
  58. classId: "",
  59. studentList: [],
  60. courseList: {},
  61. index: "",
  62. type: "",
  63. classList: this.classList,
  64. },
  65. ],
  66. },
  67. showSecondVisable: false,
  68. classIdList: [],
  69. activeClassList: [],
  70. addCourseType: [],
  71. };
  72. },
  73. mounted() {
  74. this.activeClassList = this.classList;
  75. },
  76. methods: {
  77. addClass() {
  78. this.form.classList.push({
  79. classId: "",
  80. studentList: [],
  81. courseList: {},
  82. index: "",
  83. type: "",
  84. classList: this.classList,
  85. });
  86. },
  87. deteleClass(index) {
  88. this.form.classList.splice(index, 1);
  89. },
  90. gotoSecond() {
  91. this.$refs.form.validate(async (res) => {
  92. if (res) {
  93. let flag = false;
  94. this.form.classList.forEach((item) => {
  95. if (item.studentList.length <= 0) {
  96. flag = true;
  97. }
  98. });
  99. if (flag) {
  100. this.$message.error("每个班级至少勾选一名学员");
  101. return;
  102. }
  103. this.classIdList = this.form.classList.map((item) => {
  104. return item.classId;
  105. });
  106. try {
  107. let result = await getDefaultPaymentCalender(this.classIdList);
  108. this.payInfo = result.data.defaultPaymentCalender;
  109. this.addCourseType = result.data.groupTypeSet;
  110. this.classMaxCourseNumMap = result.data.classMaxCourseNumMap;
  111. this.showSecondVisable = true;
  112. } catch {}
  113. }
  114. });
  115. },
  116. filterClassList(id) {
  117. let arr = [];
  118. this.form.classList.forEach((item) => {
  119. if (item.classId) {
  120. arr.push(item.classId);
  121. }
  122. });
  123. if (id) {
  124. let item;
  125. // 找到对应的班级
  126. this.classList.forEach((classes) => {
  127. if (classes.id == id) {
  128. item = classes;
  129. }
  130. });
  131. this.form.classList.forEach((classes) => {
  132. if (classes.classId == id) {
  133. classes.type = item.type;
  134. }
  135. });
  136. // 过滤类型不一样的
  137. this.activeClassList = this.classList.filter((classes) => {
  138. return item.type == classes.type;
  139. });
  140. this.addDisabled(arr);
  141. } else {
  142. if (arr.length == 0) {
  143. this.activeClassList = this.classList;
  144. } else {
  145. this.addDisabled(arr);
  146. }
  147. }
  148. },
  149. addDisabled(arr) {
  150. this.activeClassList = this.activeClassList.map((classes) => {
  151. return {
  152. ...classes,
  153. disabled: arr.indexOf(classes.id) != -1,
  154. };
  155. });
  156. },
  157. resetPayInfo(key, value, time) {
  158. console.log(value, time);
  159. console.log(this.payInfo);
  160. let obj = { ...this.payInfo };
  161. for (let k in obj) {
  162. if (obj[k][key]) {
  163. obj[k][key].courseCurrentPrice = value;
  164. obj[k][key].courseOriginalPrice = value;
  165. obj[k][key].courseTotalMinuties = parseInt(time);
  166. }
  167. }
  168. this.payInfo = obj;
  169. },
  170. },
  171. };
  172. </script>
  173. <style lang="scss" scoped>
  174. </style>