TeacherSimpleAssignCourseDialog.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <el-dialog
  3. class="page-dialog"
  4. :visible.sync="modalIsShow"
  5. title="分配班级"
  6. top="10vh"
  7. width="800px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="visibleChange"
  12. >
  13. <div class="part-box part-box-pad">
  14. <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
  15. <el-form-item>
  16. <el-input
  17. v-model.trim="filterLabel"
  18. placeholder="请输入班级名称"
  19. clearable
  20. ></el-input>
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="primary" @click="getList">查询</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <el-table ref="TableList" :data="dataList">
  27. <el-table-column width="55" align="center">
  28. <template slot="header">
  29. <el-checkbox
  30. v-model="checkAll"
  31. @change="checkAllChagne"
  32. ></el-checkbox>
  33. </template>
  34. <template slot-scope="scope">
  35. <el-checkbox v-model="scope.row.checked"></el-checkbox>
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="clazzName" label="教学班"></el-table-column>
  39. <el-table-column prop="teachers" label="当前分配人"></el-table-column>
  40. </el-table>
  41. </div>
  42. <div slot="footer">
  43. <el-button type="primary" :loading="loading" @click="submit"
  44. >确认</el-button
  45. >
  46. <el-button @click="cancel">取消</el-button>
  47. </div>
  48. </el-dialog>
  49. </template>
  50. <script>
  51. import { teacherSimpleCourseQuery, teacherSimpleAssignCourse } from "../../api";
  52. export default {
  53. name: "teacher-simple-assign-course-dialog",
  54. props: {
  55. teacher: {
  56. type: Object,
  57. default() {
  58. return {};
  59. },
  60. },
  61. },
  62. data() {
  63. return {
  64. modalIsShow: false,
  65. dataList: [],
  66. filterLabel: "",
  67. checkAll: false,
  68. loading: false,
  69. };
  70. },
  71. methods: {
  72. async getList() {
  73. const data = await teacherSimpleCourseQuery({
  74. teachCourseId: this.teacher.teachCourseId,
  75. clazzName: this.filterLabel,
  76. });
  77. this.dataList = (data || []).map((item) => {
  78. if (item.teacherList && item.teacherList.length) {
  79. item.teachers = item.teacherList.map((t) => t.name).join(",");
  80. item.checked = item.teacherList.some(
  81. (t) => t.id === this.teacher.userId
  82. );
  83. } else {
  84. item.teachers = "公共班级";
  85. item.checked = false;
  86. }
  87. return item;
  88. });
  89. },
  90. checkAllChagne(checked) {
  91. this.dataList.forEach((item) => {
  92. item.checked = checked;
  93. });
  94. },
  95. visibleChange() {
  96. this.filterLabel = "";
  97. this.getList();
  98. },
  99. cancel() {
  100. this.modalIsShow = false;
  101. },
  102. open() {
  103. ``;
  104. this.modalIsShow = true;
  105. },
  106. async submit() {
  107. const clazzIdList = this.dataList
  108. .filter((item) => item.checked)
  109. .map((item) => item.clazzId);
  110. if (!clazzIdList.length) {
  111. this.$message.error("请选择班级");
  112. return;
  113. }
  114. if (this.loading) return;
  115. this.loading = true;
  116. const res = await teacherSimpleAssignCourse({
  117. teachCourseId: this.teacher.teachCourseId,
  118. teacherId: this.teacher.userId,
  119. clazzIdList,
  120. }).catch(() => {});
  121. this.loading = false;
  122. if (!res) return;
  123. this.$message.success("保存成功!");
  124. this.cancel();
  125. },
  126. },
  127. };
  128. </script>